Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- WarpDrive Lift Control v1 by DrPepper
- -------------------------------------------------------------------
- -------------------------------------------------------------------
- if not fs.exists("widgets_0_3.lua") then
- if not shell.run("pastebin get iA6LZxX7 widgets_0_3.lua") then
- error("Unable to get the dependency from Pastebin")
- end
- end
- if not fs.exists("utils_0_2.lua") then
- if not shell.run("pastebin get dGWjEaL5 utils_0_2.lua") then
- error("Unable to get the dependency from Pastebin")
- end
- end
- local Widgets = require("widgets_0_3")
- local Utils = require("utils_0_2")
- Widgets.Logger.enable("ERROR")
- --Widgets.Logger.enable("DEBUG")
- Utils.PeripheralManager.SetLogger(Widgets.Logger)
- Utils.PeripheralManager.Init()
- --find peripherals
- local pMon = Utils.PeripheralManager.GetPeripheralByParamAndType(
- "monitor", true, "monitor")
- if not pMon then Widgets.Logger.log("ERROR", "no monitor", "") end
- local pLiftL = Utils.PeripheralManager.GetPeripheralByParamAndType(
- "left", true, "warpdriveLift")
- if not pLiftL then Widgets.Logger.log("ERROR", "no left lift", "") end
- local pLiftR = Utils.PeripheralManager.GetPeripheralByParamAndType(
- "right", true, "warpdriveLift")
- if not pLiftR then Widgets.Logger.log("ERROR", "no right lift", "") end
- local mainMonitorWidget = Widgets.MonitorWidget:new()
- mainMonitorWidget.name = "mainMonitorWidget"
- local monBtnL = Widgets.ButtonT:new()
- local monBtnR = Widgets.ButtonT:new()
- local monBtnLR = Widgets.ButtonT:new()
- if pMon and pMon.wrapped then
- pMon.wrapped.setTextScale(2)
- mainMonitorWidget:init(pMon.wrapped)
- mainMonitorWidget.bgColor = colors.yellow
- monBtnL:init(mainMonitorWidget, 1, 1, 2, 2, true)
- monBtnL.bgColor = colors.orange
- monBtnL.caption = "\27\n"
- monBtnL.symbolPos = 2
- monBtnLR:init(mainMonitorWidget, 4, 1, 3, 2, true)
- monBtnLR.bgColor = colors.orange
- monBtnLR.caption = "\27\26\n"
- monBtnLR.symbolPos = 2
- monBtnR:init(mainMonitorWidget, 8, 1, 2, 2, true)
- monBtnR.bgColor = colors.orange
- monBtnR.caption = "\26\n"
- monBtnR.symbolPos = 1
- monBtnLR.fn = function(param)
- local res = nil
- if pLiftL and pLiftL.wrapped then
- res = pLiftL.wrapped.enable(param)
- end
- if pLiftR and pLiftR.wrapped then
- res = pLiftR.wrapped.enable(param) or res
- end
- return res
- end
- if pLiftL and pLiftL.wrapped then
- monBtnL.caption = monBtnL.caption..pLiftL.wrapped.mode()
- monBtnL.fn = function(param) return pLiftL.wrapped.enable(param) end
- end
- if pLiftR and pLiftR.wrapped then
- monBtnR.caption = monBtnR.caption..pLiftR.wrapped.mode()
- monBtnR.fn = function(param) return pLiftR.wrapped.enable(param) end
- end
- monBtnL.refsDraw = {monBtnLR, monBtnR}
- monBtnLR.refsDraw = {monBtnL, monBtnR}
- monBtnR.refsDraw = {monBtnL, monBtnLR}
- end
- local mainWidget = Widgets.Widget:new()
- mainWidget:init(nil, 1, 1, 51, 19, true)
- mainWidget.name = "mainWidget"
- --Tabs
- local tabWidget = Widgets.Tabs:new()
- tabWidget:init(mainWidget, 1, 1, 51, 18, true)
- tabWidget.name = "tabWidget"
- --Text input
- local textInput = Widgets.InputLine:new()
- textInput:init(mainWidget, 1, 19, 43, 1, true)
- -- Tab 1 -- User manual
- local tab1 = tabWidget:addTab(" USAGE ")
- local manLabelWidget = Widgets.Label:new()
- manLabelWidget:init(tab1, 1, 1, 51, 17)
- 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"
- manLabelWidget.blit = "\n 0000000000000000000000000000\n \n fffffffffffffffffffffffffffffffffff\n \n ffffffffffffffffffffeeeeeeeeefff7777\n fffffffffffffffeeeeeefff7777\n fffffffffffffffeeeeeeefff7777\n \n ffffffffffffffffffffffffffffffffffffffffffffffffffff"
- -- Tab 2 -- Peripheral manager from Utils
- local tabPerMan2 = tabWidget:addTab(" PERIPHERALS ")
- Utils.CreatePeripheralManagerTab(tabPerMan2, textInput)
- tabWidget:selectTab(" USAGE ")
- mainWidget:draw()
- mainMonitorWidget:draw()
- local function CoroutineUserInput()
- while true do
- local p1, p2, p3, p4, p5 = os.pullEvent()
- if p1 == "mouse_click"
- or p1 == "mouse_scroll"
- or p1 == "mouse_up" then
- mainWidget:processEvent(p1, p2, p3, p4, p5)
- end
- if p1 == "monitor_touch" then
- mainMonitorWidget:processEvent(p1, p2, p3, p4, p5)
- end
- end
- end
- parallel.waitForAny(CoroutineUserInput,
- Utils.PeripheralManager.ManagerCoroutine
- )
Advertisement
Add Comment
Please, Sign In to add comment