View difference between Paste ID: uTiwmvcY and Zhs6Ukmx
SHOW: | | - or go back to the newest paste.
1-
local controller = peripheral.wrap("monitor_1")
1+
-- load libraries
2-
-- local display = peripheral.wrap("monitor_27")
2+
os.loadAPI("drawLib")
3
os.loadAPI("buttonLib")
4-
local wmod = peripheral.wrap("back")
4+
os.loadAPI("dataLib")
5-
local controllerX, controllerY, displayX, displayY
5+
-- peripheral setup
6
7
local controllername = "monitor_0"
8
local controller = peripheral.wrap(controllername)
9-
local generatorOutput = 0
9+
local modem = peripheral.wrap('top')
10
modem.closeAll()
11-
buttons = {}
11+
modem.open(2)
12
-- local wmod = peripheral.wrap("bottom")
13-
wmod.closeAll()
13+
-- wmod.closeAll()
14
15
-- variables setup
16
local controllerX, controllerY
17-
    -- displayX, displayY= display.getSize()
17+
18
local previousApp = "home"
19
20
-- Application Variables Setup
21-
    wmod.open(i)
21+
local northFarmActive = false
22
local eastFarmActive = false
23
local southFarmActive = false
24-
function empty(monitor)
24+
local westFarmActive = false
25-
    monitor.setBackgroundColor(colors.black)
25+
local totalEssences = {}
26-
    monitor.clear()
26+
local essencesPage = 1
27-
    monitor.setCursorPos(1,1)
27+
local essencesPerPage = 13
28
local currentSort = "None"
29
30
function resizeMon()
31-
    empty(controller)
31+
32-
    -- empty(display)
32+
33
34
function transmitToSlaves(message)
35-
function drawTitle(x, y, text, color_txt, color_bg, monitor)
35+
	-- print('Transmitting: ' .. message)
36-
    monitor.setBackgroundColor(color_bg)
36+
	modem.transmit(1,2,message)
37-
    monitor.setTextColor(color_txt)
37+
38-
    monitor.setCursorPos(x,y)
38+
39-
    monitor.write(text)
39+
40-
    monitor.setCursorPos(1,1)
40+
    -- wmod.open(i)
41-
    monitor.setBackgroundColor(colors.black)
41+
42
 
43
function clearAll()
44-
function drawLine(x, y, length, size, color_bar, monitor)
44+
    drawLib.empty(controller)
45-
    for yPos = y, y+size-1 do
45+
46-
        monitor.setBackgroundColor(color_bar)
46+
47-
        monitor.setCursorPos(x, yPos)
47+
-- Startup Functions
48-
        monitor.write(string.rep(" ", length))
48+
49-
        monitor.setBackgroundColor(colors.black)
49+
50
    -- Application Triggers
51
    disableAllFarms()
52
    
53-
function drawProg(x, y, length, size, minVal, maxVal, color_bar, color_bg, monitor)
53+
54-
    drawLine(x, y, length, size, color_bg, monitor)
54+
55-
    local barSize = math.floor((minVal/maxVal)*length)
55+
56-
    drawLine(x, y, barSize, size, color_bar, monitor)
56+
    drawLib.drawTitle(monX/2-7, monY/2, "All The Mods 7 OS", colors.white, colors.black,monitor)
57
    drawLib.drawTitle(monX/2-9, monY-3, "Loading... Please wait", colors.white, colors.black,monitor)
58
    for i=1, 30 do
59-
function drawContent(x, y, height, width, minVal, maxVal, color_bar, color_bg, monitor)
59+
60-
    drawGraph(x, y, height, width, color_bg, monitor)
60+
        drawLib.drawProg(2,monY-1, monX-2, 1, i, 30, colors.white, colors.gray,monitor)
61-
    local a = math.floor((minVal/maxVal)*height)
61+
62-
    drawGraph(x, y, a, width, color_bar, monitor)
62+
63
    drawLib.empty(monitor)
64
end
65-
function drawGraph(x, y, height, width, color_bar, monitor)
65+
66-
    drawLine(x, y-height+1, width, height, color_bar, monitor)
66+
-- Utility Functions
67
function formatNumbers(number,length)
68
	return tostring(math.floor(number))..string.rep(" ",length-#tostring(math.floor(number)))
69-
function putTime(x,y,monitor,bool,color)
69+
70-
	monitor.setBackgroundColor(color)
70+
function table_count(T)
71-
    monitor.setCursorPos(x,y)
71+
  local count = 0
72-
    time = textutils.formatTime(os.time(), bool)
72+
  for _ in pairs(T) do count = count + 1 end
73-
	if os.time()<10.000 then monitor.write("0"..time) else monitor.write(time) end
73+
  return count
74-
	monitor.setBackgroundColor(colors.black)
74+
75
function maxpages()
76
	return math.ceil((table_count(totalEssences) / essencesPerPage))
77-
function clearBox(x,y,h,l,monitor,color)
77+
78-
	monitor.setBackgroundColor(color)
78+
function atoz(a,b)
79-
    for i = y, y + h - 1 do
79+
  return a[1] < b[1]
80-
        monitor.setCursorPos(x,i)
80+
81-
        monitor.write(string.rep(" ", l))
81+
function getSortedEssencesTable()
82
	if currentSort == "None" then
83-
	monitor.setBackgroundColor(colors.black)
83+
		return totalEssences
84
	elseif currentSort == " A to Z " then
85
		return table.sort(totalEssences, compare)
86
	elseif currentSort == " Z to Z " then
87
88
	elseif currentSort == "Hi to Lo" then
89
90
	elseif currentSort == "Lo to Hi" then
91
92-
    drawTitle(monX/2-7, monY/2, "Brent OS v2.1beta", colors.white, colors.black,monitor)
92+
	end
93-
    drawTitle(monX/2-9, monY-3, "Loading... Please wait", colors.white, colors.black,monitor)
93+
94-
    for i=1, 50 do
94+
95
-- Application Functions
96-
        drawProg(2,monY-1, monX-2, 1, i, 50, colors.white, colors.gray,monitor)
96+
function disableAllFarms()
97
    northFarmActive = false
98
	transmitToSlaves("northFarmOff")
99-
    empty(monitor)
99+
    eastFarmActive = false
100
	transmitToSlaves("eastFarmOff")
101
    southFarmActive = false
102
	transmitToSlaves("southFarmOff")
103-
	local out = tostring(math.floor(number))..string.rep(" ",length-#tostring(math.floor(number)))
103+
    westFarmActive = false
104-
	return out
104+
	transmitToSlaves("westFarmOff")
105
end
106
function updateEssenceCounts()
107-
function addButton(x,y,w,h,name,colorOn,colorOff,state,textOn,textOff,textX,textY,header)
107+
	transmitToSlaves("provideEssenceCount")
108-
	buttons[name] = {["x"] = x,["y"] = y,["width"] = w,["height"] = h,
108+
	local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
109-
						["colorOn"] = colorOn,["colorOff"] = colorOff,["state"] = state,
109+
	totalEssences = message
110-
						["textOn"] = textOn,["textOff"] = textOff,
110+
111-
						["textX"] = textX,["textY"] = textY,["header"] = header}
111+
112
-- Add all buttons
113
function addButtons()
114
	-- Homebar Page Change
115-
	addButton(1,1,3,1,"pageLeft",colors.cyan,colors.red,true,"<- ","",1,1,"")
115+
	buttonLib.addButton(1,1,3,1,"pageLeft",colors.cyan,colors.red,true,"<- ","",1,1,"")
116-
	addButton(controllerX-2,1,3,1,"pageRight",colors.cyan,colors.red,true," ->","",controllerX-2,1,"")
116+
	buttonLib.addButton(controllerX-2,1,3,1,"pageRight",colors.cyan,colors.red,true," ->","",controllerX-2,1,"")
117
	-- Homebar Home
118-
	addButton(1,1,5,1,"homeButton1",colors.lime,colors.lightGray,true,"/^\\","",2,1,"")
118+
	buttonLib.addButton(1,1,5,1,"homeButton1",colors.lime,colors.lightGray,true,"/^\\","",2,1,"")
119-
	addButton(1,2,5,1,"homeButton2",colors.lime,colors.lightGray,true,"|#|","",2,2,"")
119+
	buttonLib.addButton(1,2,5,1,"homeButton2",colors.lime,colors.lightGray,true,"|#|","",2,2,"")
120
	-- Homebar Back
121-
	addButton(controllerX-4,1,5,1,"backButton1",colors.red,colors.lightGray,true,"/__","",controllerX-3,1,"")
121+
	buttonLib.addButton(controllerX-4,1,5,1,"backButton1",colors.red,colors.lightGray,true,"/__","",controllerX-3,1,"")
122-
	addButton(controllerX-4,2,5,1,"backButton2",colors.red,colors.lightGray,true,"\\  ","",controllerX-3,2,"")
122+
	buttonLib.addButton(controllerX-4,2,5,1,"backButton2",colors.red,colors.lightGray,true,"\\  ","",controllerX-3,2,"")
123
	-- Applications
124-
	addButton(3,4,11,3,"power",colors.cyan,colors.gray,true," Power ","",5,5,"")
124+
	buttonLib.addButton(3,4,11,3,"farms",colors.cyan,colors.gray,true,"Farms","",6,5,"")
125-
	addButton(17,4,11,3,"setting",colors.cyan,colors.gray,true,"Setting","",19,5,"")
125+
	buttonLib.addButton(17,4,11,3,"setting",colors.cyan,colors.gray,true,"Setting","",19,5,"")
126-
	addButton(3,8,11,3,"storage",colors.cyan,colors.gray,true,"Storage","",5,9,"")
126+
	buttonLib.addButton(3,8,11,3,"storage",colors.cyan,colors.gray,true,"Storage","",5,9,"")
127-
	addButton(17,8,11,3,"graphs",colors.cyan,colors.gray,true,"Diagram","",19,9,"")
127+
	buttonLib.addButton(17,8,11,3,"graphs",colors.cyan,colors.gray,true,"Diagram","",19,9,"")
128-
	-- addButton(3,12,11,3,"timelog",colors.cyan,colors.gray,true,"TimeLog","",5,13,"")
128+
	--addButton(3,12,11,3,"timelog",colors.cyan,colors.gray,true,"TimeLog","",5,13,"")
129-
	-- addButton(17,12,11,3,"nothing",colors.cyan,colors.gray,false,"","Nothing",19,13,"")
129+
	--addButton(17,12,11,3,"nothing",colors.cyan,colors.gray,false,"","Nothing",19,13,"")
130
	-- Farm Application Buttons
131-
	addButton(controllerX,controllerY,1,1,"powerswitch",colors.black,colors.red,true,"X","",controllerX,controllerY,"")
131+
	--addButton(7,4,5,3,"northFarm",colors.green,colors.red,true,"N","N",9,5,"")
132
	--addButton(2,7,5,3,"westFarm",colors.green,colors.red,true,"W","W",4,8,"")
133-
	addButton(2,5,6,1,"togglePower",colors.lime,colors.red,false,"  ON  ","  OFF ",2,5,"Master")
133+
	--addButton(7,10,5,3,"southFarm",colors.green,colors.red,true,"S","S",9,11,"")
134-
	addButton(2,7,6,1,"incrPower",colors.cyan,colors.gray,true," /\\ "," /\\",3,7,"")
134+
	--addButton(12,7,5,3,"eastFarm",colors.green,colors.red,true,"E","E",14,8,"")
135-
	addButton(2,9,6,1,"levelPower",colors.black,colors.red,true,"0  EUt","",2,9,"")
135+
	buttonLib.addButton(2,4,5,3,"northFarm",colors.green,colors.red,true,"N","N",4,5,"")
136-
	addButton(2,11,6,1,"decrPower",colors.cyan,colors.gray,true," \\/ "," \\/ ",3,11,"")
136+
	buttonLib.addButton(2,8,5,3,"eastFarm",colors.green,colors.red,true,"E","E",4,9,"")
137
	buttonLib.addButton(2,12,5,3,"southFarm",colors.green,colors.red,true,"S","S",4,13,"")
138
	buttonLib.addButton(2,16,5,3,"westFarm",colors.green,colors.red,true,"W","W",4,17,"")
139
	buttonLib.addButton(31,6,3,1,"essencePageLeft",colors.blue,colors.gray,true,"<","<",32,6,"")
140-
	drawLine(1,1,controllerX,2,colors.gray,monitor)
140+
	buttonLib.addButton(47,6,3,1,"essencePageRight",colors.blue,colors.gray,true,">",">",48,6,"")
141-
	drawButton("homeButton1",monitor)
141+
	-- Settings Application Buttons
142-
	drawButton("homeButton2",monitor)
142+
	buttonLib.addButton(3,4,11,3,"restart",colors.red,colors.gray,true,"Restart","",5,5,"")
143-
	drawButton("backButton1",monitor)
143+
144-
	drawButton("backButton2",monitor)
144+
145-
	drawButton("powerswitch",monitor)
145+
-- Generate The Gui Based On Current State
146-
	clearBox(controllerX/2-1,1,1,5,monitor,colors.gray)
146+
147-
	putTime(controllerX/2-1,1,monitor,true,colors.gray)
147+
	-- Draw Home Bar
148
    drawLib.drawLine(1,1,controllerX,2,colors.gray,monitor)
149
	buttonLib.drawButton("homeButton1",monitor)
150-
		drawButton("power",monitor)
150+
	buttonLib.drawButton("homeButton2",monitor)
151-
		drawButton("storage",monitor)
151+
	buttonLib.drawButton("backButton1",monitor)
152-
		drawButton("graphs",monitor)
152+
	buttonLib.drawButton("backButton2",monitor)
153-
		drawButton("setting",monitor)
153+
	drawLib.clearBox(controllerX/2-1,1,1,5,monitor,colors.gray)
154-
	elseif currentApp == "power" then
154+
	drawLib.putTime(controllerX/2-1,1,monitor,true,colors.gray)
155-
		drawTitle(controllerX/2-2, 2, " Power", colors.white, colors.gray, monitor)
155+
    -- Draw Application Specific Items
156
	if currentApp == "home" then
157-
		if generatorOutput == 0 then buttons["decrPower"].state = false else buttons["decrPower"].state = true end
157+
		buttonLib.drawButton("farms",monitor)
158-
		if generatorOutput == 512 then buttons["incrPower"].state = false else buttons["incrPower"].state = true end
158+
		buttonLib.drawButton("storage",monitor)
159-
		buttons["levelPower"].textOn = formatNumbers(generatorOutput,3).."EUt"
159+
		buttonLib.drawButton("graphs",monitor)
160
		buttonLib.drawButton("setting",monitor)
161-
		drawButton("togglePower",monitor)	
161+
	elseif currentApp == "farms" then
162-
		drawButton("incrPower",monitor)
162+
		drawLib.drawTitle(controllerX/2-1, 2, "Farms", colors.white, colors.gray, monitor)
163-
		drawButton("decrPower",monitor)
163+
164-
		drawButton("levelPower",monitor)
164+
		buttonLib.setButtonState("northFarm",northFarmActive)
165
		buttonLib.drawButton("northFarm",monitor)
166
		buttonLib.setButtonState("westFarm",westFarmActive)
167-
		drawTitle(controllerX/2-2, 2, "Storage", colors.white, colors.gray, monitor)
167+
		buttonLib.drawButton("westFarm",monitor)
168
		buttonLib.setButtonState("southFarm",southFarmActive)
169
		buttonLib.drawButton("southFarm",monitor)
170-
		drawTitle(controllerX/2-2, 2, "Diagram", colors.white, colors.gray, monitor)
170+
		buttonLib.setButtonState("eastFarm",eastFarmActive)
171
		buttonLib.drawButton("eastFarm",monitor)
172
173-
		drawTitle(controllerX/2-2, 2, "Setting", colors.white, colors.gray, monitor)
173+
		drawLib.drawTitle(9, 4, "Essences Collected :", colors.white, colors.black, monitor)
174
175
		local index = 0
176
		for key, value in pairs(getSortedEssencesTable()) do
177
			if index < essencesPage * essencesPerPage and index >= (essencesPage - 1) * essencesPerPage then
178
				local text = key .. string.rep(" ", 15 - #key) .. string.rep(" ", 5 - #(""..value)) .. value
179
				drawLib.drawTitle(9, 6 + (index%essencesPerPage), text, colors.white, colors.black, monitor)
180
			end
181-
function drawButton(button,monitor)
181+
			index = index + 1
182-
	local color = colors.red
182+
183-
	local text = ""
183+
184-
    if buttons[button].state==true then color = buttons[button].colorOn else color = buttons[button].colorOff end
184+
		buttonLib.drawButton("essencePageLeft",monitor)
185-
    if buttons[button].state==true then text = buttons[button].textOn else text = buttons[button].textOff end
185+
		drawLib.drawTitle(31, 4, "       Page        ", colors.white, colors.gray, monitor)
186-
    drawLine(buttons[button].x, buttons[button].y, buttons[button].width, buttons[button].height, color, monitor)
186+
		drawLib.drawTitle(37, 6, essencesPage.." of "..maxpages(), colors.white, colors.black, monitor)
187-
	if buttons[button].header == "" then else 
187+
		buttonLib.drawButton("essencePageRight",monitor)
188-
    drawTitle(buttons[button].x, buttons[button].y - 1, buttons[button].header, colors.white, colors.black, monitor) end
188+
189-
    drawTitle(buttons[button].textX, buttons[button].textY, text, colors.white, color, monitor)
189+
		--buttonLib.drawButton("essencePageLeft",monitor)
190
		drawLib.drawTitle(31, 8, "       Sort        ", colors.white, colors.gray, monitor)
191
		drawLib.drawTitle(38, 10, "None", colors.white, colors.black, monitor)
192
		--buttonLib.drawButton("essencePageRight",monitor)
193-
   if x >= buttons["homeButton1"].x and x < buttons["homeButton1"].x + buttons["homeButton1"].width and 
193+
194-
		y >= buttons["homeButton1"].y and y < buttons["homeButton1"].y + buttons["homeButton1"].height and side == "monitor_1" then
194+
		--buttonLib.drawButton("essencePageLeft",monitor)
195
		drawLib.drawTitle(31, 12, "       Data        ", colors.white, colors.gray, monitor)
196-
			empty(controller)
196+
		drawLib.drawTitle(37, 14, "Totals", colors.white, colors.black, monitor)
197-
    elseif x >= buttons["homeButton2"].x and x < buttons["homeButton2"].x + buttons["homeButton2"].width and 
197+
		--buttonLib.drawButton("essencePageRight",monitor)
198-
		y >= buttons["homeButton2"].y and y < buttons["homeButton2"].y + buttons["homeButton2"].height and side == "monitor_1" then
198+
199
	elseif currentApp == "storage" then
200-
			empty(controller)
200+
		drawLib.drawTitle(controllerX/2-2, 2, "Storage", colors.white, colors.gray, monitor)
201-
    elseif x >= buttons["backButton1"].x and x < buttons["backButton1"].x + buttons["backButton1"].width and 
201+
202-
		y >= buttons["backButton1"].y and y < buttons["backButton1"].y + buttons["backButton1"].height and side == "monitor_1" then
202+
203
		drawLib.drawTitle(controllerX/2-2, 2, "Diagram", colors.white, colors.gray, monitor)
204-
    elseif x >= buttons["backButton2"].x and x < buttons["backButton2"].x + buttons["backButton2"].width and 
204+
205-
		y >= buttons["backButton2"].y and y < buttons["backButton2"].y + buttons["backButton2"].height and side == "monitor_1" then
205+
206
		drawLib.drawTitle(controllerX/2-2, 2, "Setting", colors.white, colors.gray, monitor)
207-
    elseif x >= buttons["power"].x and x < buttons["power"].x + buttons["power"].width and 
207+
		buttonLib.drawButton("restart",monitor)
208-
		y >= buttons["power"].y and y < buttons["power"].y + buttons["power"].height and side == "monitor_1" 
208+
209-
		and currentApp == "home" then
209+
210-
			currentApp = "power"
210+
211-
			previousApp = "home"
211+
212-
			empty(controller)
212+
213-
    elseif x >= buttons["storage"].x and x < buttons["storage"].x + buttons["storage"].width and 
213+
214-
		y >= buttons["storage"].y and y < buttons["storage"].y + buttons["storage"].height and side == "monitor_1" 
214+
215-
		and currentApp == "home" then
215+
-- React To Touch Events
216-
			currentApp = "storage"
216+
217-
			previousApp = "home"
217+
	-- Is On the main controller screen
218-
			empty(controller)
218+
	if side == controllername then
219-
    elseif x >= buttons["graphs"].x and x < buttons["graphs"].x + buttons["graphs"].width and 
219+
   		if buttonLib.isWithinBoundingBox(x,y,"homeButton1") then
220-
		y >= buttons["graphs"].y and y < buttons["graphs"].y + buttons["graphs"].height and side == "monitor_1" 
220+
221-
		and currentApp == "home" then
221+
			drawLib.empty(controller)
222-
			currentApp = "graphs"
222+
   		elseif buttonLib.isWithinBoundingBox(x,y,"homeButton2") then
223-
			previousApp = "home"
223+
224-
			empty(controller)
224+
			drawLib.empty(controller)
225-
    elseif x >= buttons["setting"].x and x < buttons["setting"].x + buttons["setting"].width and 
225+
   		elseif buttonLib.isWithinBoundingBox(x,y,"backButton1") then
226-
		y >= buttons["setting"].y and y < buttons["setting"].y + buttons["setting"].height and side == "monitor_1" 
226+
227-
		and currentApp == "home" then
227+
  		elseif buttonLib.isWithinBoundingBox(x,y,"backButton2") then
228-
			currentApp = "setting"
228+
      
229-
			previousApp = "home"
229+
		elseif currentApp == "home" then
230-
			empty(controller)
230+
			if buttonLib.isWithinBoundingBox(x,y,"farms") then
231-
    elseif x >= buttons["powerswitch"].x and x < buttons["powerswitch"].x + buttons["powerswitch"].width and 
231+
            	currentApp = "farms"
232-
		y >= buttons["powerswitch"].y and y < buttons["powerswitch"].y + buttons["powerswitch"].height and side == "monitor_1" then
232+
            	previousApp = "home"
233-
			os.reboot()
233+
            	drawLib.empty(controller)
234-
    elseif x >= buttons["incrPower"].x and x < buttons["incrPower"].x + buttons["incrPower"].width and 
234+
    		elseif buttonLib.isWithinBoundingBox(x,y,"storage") then
235-
		y >= buttons["incrPower"].y and y < buttons["incrPower"].y + buttons["incrPower"].height and side == "monitor_1" 
235+
            	currentApp = "storage"
236-
		and currentApp == "power" then
236+
            	previousApp = "home"
237-
			if generatorOutput <= 480 then generatorOutput = generatorOutput + 32 end
237+
            	drawLib.empty(controller)
238-
			wmod.transmit(40000,0,"gen1."..math.floor(generatorOutput/64))
238+
    		elseif buttonLib.isWithinBoundingBox(x,y,"graphs") then
239-
			wmod.transmit(40000,0,"gen2."..math.ceil(generatorOutput/64))
239+
            	currentApp = "graphs"
240-
    elseif x >= buttons["decrPower"].x and x < buttons["decrPower"].x + buttons["decrPower"].width and 
240+
            	previousApp = "home"
241-
		y >= buttons["decrPower"].y and y < buttons["decrPower"].y + buttons["decrPower"].height and side == "monitor_1" 
241+
            	drawLib.empty(controller)
242-
		and currentApp == "power" then
242+
    		elseif buttonLib.isWithinBoundingBox(x,y,"setting") then
243-
			if generatorOutput >= 32 then generatorOutput = generatorOutput - 32 end
243+
            	currentApp = "setting"
244-
			wmod.transmit(40000,0,"gen1."..math.floor(generatorOutput/64))
244+
            	previousApp = "home"
245-
			wmod.transmit(40000,0,"gen2."..math.ceil(generatorOutput/64))
245+
            	drawLib.empty(controller)
246-
    elseif x >= buttons["togglePower"].x and x < buttons["togglePower"].x + buttons["togglePower"].width and 
246+
			end
247-
		y >= buttons["togglePower"].y and y < buttons["togglePower"].y + buttons["togglePower"].height and side == "monitor_1" 
247+
        elseif currentApp == "farms" then
248-
		and currentApp == "power" then
248+
			if buttonLib.isWithinBoundingBox(x,y,"northFarm") then
249-
			if buttons["togglePower"].state == true then
249+
                if northFarmActive then transmitToSlaves("northFarmOff") else transmitToSlaves("northFarmOn") end
250-
				wmod.transmit(40000,0,".safetyOn")
250+
                if northFarmActive then northFarmActive = false else northFarmActive = true end
251-
				buttons["togglePower"].state = false
251+
				-- transmit over network that northfarm must be toggled
252-
			elseif buttons["togglePower"].state == false then 
252+
            	drawLib.empty(controller)
253-
				wmod.transmit(40000,0,".safetyOff")
253+
    		elseif buttonLib.isWithinBoundingBox(x,y,"eastFarm") then
254-
				buttons["togglePower"].state = true
254+
                if northFarmActive then transmitToSlaves("eastFarmOff") else transmitToSlaves("eastFarmOn") end
255-
				wmod.transmit(40000,0,"gen1."..math.floor(generatorOutput/64))
255+
                if eastFarmActive then eastFarmActive = false else eastFarmActive = true end
256-
				wmod.transmit(40000,0,"gen2."..math.ceil(generatorOutput/64))
256+
257
            	drawLib.empty(controller)
258-
    else
258+
    		elseif buttonLib.isWithinBoundingBox(x,y,"southFarm") then
259
                if northFarmActive then transmitToSlaves("southFarmOff") else transmitToSlaves("southFarmOn") end
260
                if southFarmActive then southFarmActive = false else southFarmActive = true end
261
262
            	drawLib.empty(controller)
263-
    parallel.waitForAny(wait,getTouch)
263+
    		elseif buttonLib.isWithinBoundingBox(x,y,"westFarm") then
264
                if northFarmActive then transmitToSlaves("westFarmOff") else transmitToSlaves("westFarmOn") end
265
                if westFarmActive then westFarmActive = false else westFarmActive = true end
266
267
            	drawLib.empty(controller)
268
			elseif buttonLib.isWithinBoundingBox(x,y,"essencePageLeft") then
269
                if essencesPage > 1 then essencesPage = essencesPage - 1 end
270
            	drawLib.empty(controller)
271
			elseif buttonLib.isWithinBoundingBox(x,y,"essencePageRight") then
272-
 sleep(1)
272+
				if essencesPage < maxpages() then essencesPage = essencesPage + 1 end
273
            	drawLib.empty(controller)
274
			end
275
        elseif currentApp == "setting" then
276
			if buttonLib.isWithinBoundingBox(x,y,"restart") then
277
				os.reboot()
278
			else
279
			end
280
   		else
281-
	wmod.transmit(40000,0,".safetyOn")
281+
   		end
282
	else
283
	end
284
end
285
286
function waitForTouch()
287
    parallel.waitForAny(applicationWaiter,getTouch)
288
end
289
290
function applicationWaiter()
291
	parallel.waitForAny(wait,applicationLoop)
292
end
293
294
function applicationLoop()
295
	updateEssenceCounts()
296
end
297
 
298
function getTouch()
299
    event, side, xPos, yPos = os.pullEvent("monitor_touch")
300
    touchAreas(xPos, yPos, side)
301
end
302
 
303
function wait()
304
 	sleep(0.5)
305
end
306
307
function init()
308
    clearAll()
309
    resizeMon()
310
    bootSequence()
311
	addButtons()
312
    clearAll()
313
    while true do
314
		generateGUI(controller)
315
        waitForTouch()
316
    end
317
end
318
 
319
init()