Advertisement
drpepper240

warpdriveLiftCtrl

Dec 20th, 2024 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. --  WarpDrive Lift Control v1 by DrPepper
  2. -------------------------------------------------------------------
  3. -------------------------------------------------------------------
  4. if not fs.exists("widgets_0_3.lua") then
  5.     if not shell.run("pastebin get iA6LZxX7 widgets_0_3.lua") then
  6.         error("Unable to get the dependency from Pastebin")
  7.     end
  8. end
  9.  
  10. if not fs.exists("utils_0_2.lua") then
  11.     if not shell.run("pastebin get dGWjEaL5 utils_0_2.lua") then
  12.         error("Unable to get the dependency from Pastebin")
  13.     end
  14. end
  15.  
  16. local Widgets = require("widgets_0_3")
  17. local Utils = require("utils_0_2")
  18. Widgets.Logger.enable("ERROR")
  19. Widgets.Logger.enable("DEBUG")
  20. Utils.PeripheralManager.SetLogger(Widgets.Logger)
  21. Utils.PeripheralManager.Init()
  22.  
  23. --find peripherals
  24. local pMon = Utils.PeripheralManager.GetPeripheralByParamAndType(
  25.     "monitor", true, "monitor")
  26. local pLiftL = Utils.PeripheralManager.GetPeripheralByParamAndType(
  27.     "warpdriveLift", true, "left")
  28. local pLiftR = Utils.PeripheralManager.GetPeripheralByParamAndType(
  29.     "warpdriveLift", true, "right")
  30.  
  31. local mainMonitorWidget = Widgets.MonitorWidget:new()
  32. mainMonitorWidget.name = "mainMonitorWidget"
  33. local monBtnL = Widgets.Button:new()
  34. if pMon and pMon.wrapped then
  35.     mainMonitorWidget:init(pMon.wrapped)
  36.     monBtnL:init(mainMonitorWidget, 1, 1, 5, 1, true)
  37.     monBtnL.caption = "< "
  38.     if pLiftL.wrapped then
  39.         monBtnL.caption = monBtnL.caption..pLiftL.wrapped.mode()
  40.     end
  41. end
  42.  
  43. local mainWidget = Widgets.Widget:new()
  44. mainWidget:init(nil, 1, 1, 51, 19, true)
  45. mainWidget.name = "mainWidget"
  46.  
  47. --Tabs
  48. local tabWidget = Widgets.Tabs:new()
  49. tabWidget:init(mainWidget, 1, 1, 51, 18, true)
  50. tabWidget.name = "tabWidget"
  51.  
  52. --Text input
  53. local textInput = Widgets.InputLine:new()
  54. textInput:init(mainWidget, 1, 19, 43, 1, true)
  55.  
  56. -- Tab 1 -- User manual
  57. local tab1 = tabWidget:addTab(" USAGE ")
  58. local manLabelWidget = Widgets.Label:new()
  59. manLabelWidget:init(tab1, 1, 1, 51, 17)
  60. manLabelWidget.text = "\n            WarpDrive lift controller v1\n \n Requires the following peripherals:\n \n   monitor (advanced): \"monitor\" = true\n   warpdriveLift: \"left\" = true\n   warpdriveLift: \"right\" = true\n \n Make sure to save these properties to peripheral.cfg"
  61.  
  62. -- Tab 2 -- Peripheral manager from Utils
  63. local tabPerMan2 = tabWidget:addTab(" PERIPHERALS ")
  64. Utils.CreatePeripheralManagerTab(tabPerMan2, textInput)
  65.  
  66. tabWidget:selectTab(" USAGE ")
  67. mainWidget:draw()
  68. mainMonitorWidget:draw()
  69.  
  70. local function CoroutineUserInput()
  71.     while true do
  72.         local p1, p2, p3, p4, p5 = os.pullEvent()
  73.         if p1 == "mouse_click"
  74.                 or p1 == "mouse_scroll"
  75.                 or p1 == "mouse_up" then
  76.           mainWidget:processEvent(p1, p2, p3, p4, p5)
  77.         end
  78.         if p1 == "monitor_touch" then
  79.             mainMonitorWidget:processEvent(p1, p2, p3, p4, p5)
  80.         end
  81.     end
  82. end
  83.  
  84. parallel.waitForAny(CoroutineUserInput,
  85.     Utils.PeripheralManager.ManagerCoroutine
  86. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement