drpepper240

warpdriveLiftCtrl

Dec 20th, 2024 (edited)
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.43 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. if not pMon then Widgets.Logger.log("ERROR", "no monitor", "") end
  27. local pLiftL = Utils.PeripheralManager.GetPeripheralByParamAndType(
  28.     "left", true, "warpdriveLift")
  29. if not pLiftL then Widgets.Logger.log("ERROR", "no left lift", "") end
  30. local pLiftR = Utils.PeripheralManager.GetPeripheralByParamAndType(
  31.     "right", true, "warpdriveLift")
  32. if not pLiftR then Widgets.Logger.log("ERROR", "no right lift", "") end
  33.  
  34. local mainMonitorWidget = Widgets.MonitorWidget:new()
  35. mainMonitorWidget.name = "mainMonitorWidget"
  36. local monBtnL = Widgets.ButtonT:new()
  37. local monBtnR = Widgets.ButtonT:new()
  38. local monBtnLR = Widgets.ButtonT:new()
  39. if pMon and pMon.wrapped then
  40.     pMon.wrapped.setTextScale(2)
  41.     mainMonitorWidget:init(pMon.wrapped)
  42.     mainMonitorWidget.bgColor = colors.yellow
  43.     monBtnL:init(mainMonitorWidget, 1, 1, 2, 2, true)
  44.     monBtnL.bgColor = colors.orange
  45.     monBtnL.caption = "\27\n"
  46.     monBtnL.symbolPos = 2
  47.     monBtnLR:init(mainMonitorWidget, 4, 1, 3, 2, true)
  48.     monBtnLR.bgColor = colors.orange
  49.     monBtnLR.caption = "\27\26\n"
  50.     monBtnLR.symbolPos = 2
  51.     monBtnR:init(mainMonitorWidget, 8, 1, 2, 2, true)
  52.     monBtnR.bgColor = colors.orange
  53.     monBtnR.caption = "\26\n"
  54.     monBtnR.symbolPos = 1
  55.     monBtnLR.fn = function(param)
  56.         local res = nil
  57.         if pLiftL and pLiftL.wrapped then
  58.             res = pLiftL.wrapped.enable(param)
  59.         end
  60.         if pLiftR and pLiftR.wrapped then
  61.             res = pLiftR.wrapped.enable(param) or res
  62.         end
  63.         return res
  64.     end
  65.     if pLiftL and pLiftL.wrapped then
  66.         monBtnL.caption = monBtnL.caption..pLiftL.wrapped.mode()
  67.         monBtnL.fn = function(param) return pLiftL.wrapped.enable(param) end
  68.     end
  69.     if pLiftR and pLiftR.wrapped then
  70.         monBtnR.caption = monBtnR.caption..pLiftR.wrapped.mode()
  71.         monBtnR.fn = function(param) return pLiftR.wrapped.enable(param) end
  72.     end
  73.     monBtnL.refsDraw = {monBtnLR, monBtnR}
  74.     monBtnLR.refsDraw = {monBtnL, monBtnR}
  75.     monBtnR.refsDraw = {monBtnL, monBtnLR}
  76. end
  77.  
  78. local mainWidget = Widgets.Widget:new()
  79. mainWidget:init(nil, 1, 1, 51, 19, true)
  80. mainWidget.name = "mainWidget"
  81.  
  82. --Tabs
  83. local tabWidget = Widgets.Tabs:new()
  84. tabWidget:init(mainWidget, 1, 1, 51, 18, true)
  85. tabWidget.name = "tabWidget"
  86.  
  87. --Text input
  88. local textInput = Widgets.InputLine:new()
  89. textInput:init(mainWidget, 1, 19, 43, 1, true)
  90.  
  91. -- Tab 1 -- User manual
  92. local tab1 = tabWidget:addTab(" USAGE ")
  93. local manLabelWidget = Widgets.Label:new()
  94. manLabelWidget:init(tab1, 1, 1, 51, 17)
  95. 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"
  96. manLabelWidget.blit = "\n            0000000000000000000000000000\n \n fffffffffffffffffffffffffffffffffff\n \n   ffffffffffffffffffffeeeeeeeeefff7777\n   fffffffffffffffeeeeeefff7777\n   fffffffffffffffeeeeeeefff7777\n \n ffffffffffffffffffffffffffffffffffffffffffffffffffff"
  97. -- Tab 2 -- Peripheral manager from Utils
  98. local tabPerMan2 = tabWidget:addTab(" PERIPHERALS ")
  99. Utils.CreatePeripheralManagerTab(tabPerMan2, textInput)
  100.  
  101. tabWidget:selectTab(" USAGE ")
  102. mainWidget:draw()
  103. mainMonitorWidget:draw()
  104.  
  105. local function CoroutineUserInput()
  106.     while true do
  107.         local p1, p2, p3, p4, p5 = os.pullEvent()
  108.         if p1 == "mouse_click"
  109.                 or p1 == "mouse_scroll"
  110.                 or p1 == "mouse_up" then
  111.           mainWidget:processEvent(p1, p2, p3, p4, p5)
  112.         end
  113.         if p1 == "monitor_touch" then
  114.             mainMonitorWidget:processEvent(p1, p2, p3, p4, p5)
  115.         end
  116.     end
  117. end
  118.  
  119. parallel.waitForAny(CoroutineUserInput,
  120.     Utils.PeripheralManager.ManagerCoroutine
  121. )
Advertisement
Add Comment
Please, Sign In to add comment