Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- load libraries
- os.loadAPI("drawLib")
- os.loadAPI("buttonLib")
- os.loadAPI("dataLib")
- -- peripheral setup
- local controllername = "left"
- local controller = peripheral.wrap(controllername)
- -- local modem = peripheral.wrap('top')
- -- modem.closeAll()
- -- modem.open(2)
- -- Application Variables Setup
- local controllerX, controllerY
- local currentApp = "home"
- local previousApp = "home"
- function resizeMon()
- controllerX, controllerY = controller.getSize()
- end
- function transmitToSlaves(message)
- -- print('Transmitting: ' .. message)
- modem.transmit(1,2,message)
- end
- for i = 2, 5 do
- -- wmod.open(i)
- end
- function clearAll()
- drawLib.empty(controller)
- end
- -- Startup Functions
- function bootSequence()
- -- drawTitle(displayX/2-5, displayY/2, "Booting...", colors.white, colors.black,display)
- -- Application Triggers
- loadingScreen(controllerX,controllerY,controller)
- end
- function loadingScreen(monX,monY,monitor)
- drawLib.drawTitle(monX/2-11, monY/2, "Create Above and Beyond OS", colors.white, colors.black,monitor)
- drawLib.drawTitle(monX/2-9, monY-3, "Loading... Please wait", colors.white, colors.black,monitor)
- for i=1, 30 do
- --drawContent(2, monY-1, monY-2, 2, i, 100, colors.red, colors.gray,monitor)
- drawLib.drawProg(2,monY-1, monX-2, 1, i, 30, colors.white, colors.gray,monitor)
- sleep(0.05)
- end
- drawLib.empty(monitor)
- end
- -- Utility Functions
- function formatNumbers(number,length)
- return tostring(math.floor(number))..string.rep(" ",length-#tostring(math.floor(number)))
- end
- function table_count(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- -- Application Functions
- -- Add all buttons
- function addButtons()
- -- Homebar Page Change
- buttonLib.addButton(1,1,3,1,"pageLeft",colors.cyan,colors.red,true,"<- ","",1,1,"")
- buttonLib.addButton(controllerX-2,1,3,1,"pageRight",colors.cyan,colors.red,true," ->","",controllerX-2,1,"")
- -- Homebar Home
- buttonLib.addButton(1,1,5,1,"homeButton1",colors.lime,colors.lightGray,true,"/^\\","",2,1,"")
- buttonLib.addButton(1,2,5,1,"homeButton2",colors.lime,colors.lightGray,true,"|#|","",2,2,"")
- -- Homebar Back
- buttonLib.addButton(controllerX-4,1,5,1,"backButton1",colors.red,colors.lightGray,true,"/__","",controllerX-3,1,"")
- buttonLib.addButton(controllerX-4,2,5,1,"backButton2",colors.red,colors.lightGray,true,"\\ ","",controllerX-3,2,"")
- -- Applications
- buttonLib.addButton(3,4,11,3,"farms",colors.cyan,colors.gray,true,"Farms","",6,5,"")
- buttonLib.addButton(17,4,11,3,"setting",colors.cyan,colors.gray,true,"Setting","",19,5,"")
- buttonLib.addButton(3,8,11,3,"storage",colors.cyan,colors.gray,true,"Storage","",5,9,"")
- buttonLib.addButton(17,8,11,3,"graphs",colors.cyan,colors.gray,true,"Diagram","",19,9,"")
- --addButton(3,12,11,3,"timelog",colors.cyan,colors.gray,true,"TimeLog","",5,13,"")
- --addButton(17,12,11,3,"nothing",colors.cyan,colors.gray,false,"","Nothing",19,13,"")
- -- Settings Application Buttons
- buttonLib.addButton(3,4,11,3,"restart",colors.red,colors.gray,true,"Restart","",5,5,"")
- end
- -- Generate The Gui Based On Current State
- function generateGUI(monitor)
- -- Draw Home Bar
- drawLib.drawLine(1,1,controllerX,2,colors.gray,monitor)
- buttonLib.drawButton("homeButton1",monitor)
- buttonLib.drawButton("homeButton2",monitor)
- buttonLib.drawButton("backButton1",monitor)
- buttonLib.drawButton("backButton2",monitor)
- drawLib.clearBox(controllerX/2-1,1,1,5,monitor,colors.gray)
- drawLib.putTime(controllerX/2-1,1,monitor,true,colors.gray)
- -- Draw Application Specific Items
- if currentApp == "home" then
- buttonLib.drawButton("farms",monitor)
- buttonLib.drawButton("storage",monitor)
- buttonLib.drawButton("graphs",monitor)
- buttonLib.drawButton("setting",monitor)
- elseif currentApp == "farms" then
- drawLib.drawTitle(controllerX/2-1, 2, "Farms", colors.white, colors.gray, monitor)
- elseif currentApp == "storage" then
- drawLib.drawTitle(controllerX/2-2, 2, "Storage", colors.white, colors.gray, monitor)
- elseif currentApp == "graphs" then
- drawLib.drawTitle(controllerX/2-2, 2, "Diagram", colors.white, colors.gray, monitor)
- elseif currentApp == "setting" then
- drawLib.drawTitle(controllerX/2-2, 2, "Setting", colors.white, colors.gray, monitor)
- buttonLib.drawButton("restart",monitor)
- else error("App not found") end
- -- drawButton("pageLeft",monitor)
- -- drawButton("pageRight",monitor)
- end
- -- React To Touch Events
- function touchAreas(x,y,side)
- -- Is On the main controller screen
- if side == controllername then
- if buttonLib.isWithinBoundingBox(x,y,"homeButton1") then
- currentApp = "home"
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"homeButton2") then
- currentApp = "home"
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"backButton1") then
- elseif buttonLib.isWithinBoundingBox(x,y,"backButton2") then
- elseif currentApp == "home" then
- if buttonLib.isWithinBoundingBox(x,y,"farms") then
- currentApp = "farms"
- previousApp = "home"
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"storage") then
- currentApp = "storage"
- previousApp = "home"
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"graphs") then
- currentApp = "graphs"
- previousApp = "home"
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"setting") then
- currentApp = "setting"
- previousApp = "home"
- drawLib.empty(controller)
- end
- elseif currentApp == "farms" then
- elseif currentApp == "setting" then
- if buttonLib.isWithinBoundingBox(x,y,"restart") then
- os.reboot()
- else
- end
- else
- end
- else
- end
- end
- function waitForTouch()
- parallel.waitForAny(wait,getTouch)
- end
- function getTouch()
- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- touchAreas(xPos, yPos, side)
- end
- function wait()
- sleep(0.5)
- end
- function init()
- clearAll()
- resizeMon()
- bootSequence()
- addButtons()
- clearAll()
- while true do
- generateGUI(controller)
- waitForTouch()
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement