View difference between Paste ID: HeaXveQZ and PyXUViq8
SHOW: | | - or go back to the newest paste.
1
-- Wireless BigReactor Control
2
-- by SparkyBearBomb
3
-- Original by jaranvil aka jared314
4
--
5
-- feel free to use and/or modify this code
6
--
7
-----------------------------------------------
8
-- Wireless Reactor Control - Version History
9
--
10
-- Version 2.0 - 11 Jul 21
11
-- Upodated to work with the new transmitted message
12
--
13
-- Version 1.1 - 26.12.2020
14
-- - original program forked from ELJptBRk
15-
--peripherals
15+
16-
local modem
16+
17-
local mon
17+
18
--Port Number
19-
local version = 3.0
19+
port = 0
20
21
--monitor size
22
local monX
23
local monY
24
25
term.clear()
26
-------------------FORMATTING-------------------------------
27
function clear()
28-
  mon.setBackgroundColor(colors.black)
28+
  term.setBackgroundColor(colors.black)
29-
  mon.clear()
29+
30-
  mon.setCursorPos(1,1)
30+
  term.setCursorPos(1,1)
31
end
32
 
33-
--display text on computer's terminal screen
33+
34-
function draw_text_term(x, y, text, text_color, bg_color)
34+
35
  term.setBackgroundColor(bg_color)
36
  term.setTextColor(text_color)
37
  term.setCursorPos(x,y)
38-
  write(text)
38+
  term.write(text)
39
end
40
 
41
--draw line on computer terminal
42
function draw_line(x, y, length, color)
43-
  mon.setBackgroundColor(bg_color)
43+
44-
  mon.setTextColor(text_color)
44+
45-
  mon.setCursorPos(x,y)
45+
	term.write(string.rep(" ", length))
46-
  mon.write(text)
46+
47
 
48
--draw line on computer terminal
49
function draw_line_term(x, y, length, color)
50
    term.setBackgroundColor(color)
51-
    mon.setBackgroundColor(color)
51+
52-
    mon.setCursorPos(x,y)
52+
53-
    mon.write(string.rep(" ", length))
53+
54
55
-- Round Decimal Numbers
56
function roundNumber(num, n)
57
  local mult = 10^(n or 0)
58
  return math.floor(num * mult + 0.5) / mult
59
end
60
 
61
--create progress bar
62
--draws two overlapping lines
63
--background line of bg_color
64
--main line of bar_color as a percentage of minVal/maxVal
65
function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
66
  draw_line(x, y, length, bg_color) --backgoround bar
67
  local barSize = math.floor((minVal/maxVal) * length)
68
  draw_line(x, y, barSize, bar_color) --progress so far
69
end
70
71
--create status bar
72
--draws three overlapping lines
73
--background line of bg_color
74
function status_bar(x, y, length, minVal, medVal, maxVal, bar_color1, bar_color2, bg_color)
75
  draw_line(x, y, length, bg_color) --backgoround bar
76
  local barSize1 = math.floor((medVal/maxVal) * length)
77
  local barSize2 = math.floor((minVal/maxVal) * length)
78
  draw_line(x, y, barSize1, bar_color1) --progress so far
79
  draw_line(x, y, barSize2, bar_color2) --progress so far
80
end
81
 
82
--same as above but on the computer terminal
83
function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
84
  draw_line_term(x, y, length, bg_color) --backgoround bar
85
  local barSize = math.floor((minVal/maxVal) * length)
86
  draw_line_term(x, y, barSize, bar_color)  --progress so far
87
end
88
89
--header and footer bars on monitor
90
function menu_bar()
91
  draw_line(0, 1, monX, colors.purple)
92
  draw_text(1, 1, " Wireless Reactor Receiver", colors.white, colors.purple)
93
  draw_line(0, 20, monX, colors.purple)
94
  draw_text(1, 20, " Wireless Reactor Receiver", colors.white, colors.purple)
95
end
96
97
98
------------------------END FORMATTING--------------------------
99-
  draw_line(1, 1, monX, colors.purple)
99+
100-
  draw_text(2, 1, " Wireless Reactor Receiver", colors.white, colors.purple)
100+
101-
  draw_line(1, 26, monX, colors.purple)
101+
102-
  draw_text(2, 26, " Wireless Reactor Receiver", colors.white, colors.purple)
102+
103
		table.insert(results,pharseData)
104
	end
105
	active = results[1]
106-
--basic popup screen with title bar and exit button
106+
	energyQty = results[2]
107-
function popup_screen(y, title, height)
107+
  energyMax = results[3]
108-
  clear()
108+
  energyTick = results[4]
109-
  menu_bar()
109+
	fuelTemp = results[5]
110
	caseTemp = results[6]
111-
  draw_line(4, y, 22, colors.purple)
111+
	fuelQty = results[7]
112-
  draw_line(25, y, 1, colors.red)
112+
	wasteQty = results[8]
113
	fuelMax = results[9]
114-
  for counter = y+1, height+y do
114+
  fuelTick = results[10]
115-
    draw_line(4, counter, 22, colors.white)
115+
	rodLevel = results[11]
116-
  end
116+
	isCooled = results[12]
117
end
118-
  draw_text(25, y, "X", colors.white, colors.red)
118+
119-
  draw_text(5, y, title, colors.white, colors.purple)
119+
function rfScale(number)
120
    if number == nil or number == 0 then
121
		value = "0 RF/T"
122-
--write settings to config file
122+
	elseif number < 1000 then
123-
function save_config()
123+
		number = (math.floor(number)/1)
124-
  sw = fs.open("config.txt", "w")  
124+
		value = number.." RF/T"
125-
    sw.writeLine(version)
125+
    elseif number < 1000000 then
126-
    sw.writeLine(auto_string)
126+
		number = (math.floor(number)/1000)
127-
    sw.writeLine(on)
127+
		value = number.." KRF/T"
128-
    sw.writeLine(off)
128+
    elseif number < 1000000000 then
129-
    sw.writeLine(auto_rods)
129+
		number = (math.floor(number)/1000000)
130-
    sw.writeLine(auto_rf)
130+
		value = number.." MF/T"
131-
  sw.close()
131+
	else
132
		number = (math.floor(number)/1000000000)
133
		value = number.." GF/T"
134-
--read settings from file
134+
135-
function load_config()
135+
	return value
136-
  sr = fs.open("config.txt", "r")
136+
137-
    version = tonumber(sr.readLine())
137+
138-
    auto_string = sr.readLine()
138+
modem = peripheral.wrap("back")
139-
    on = tonumber(sr.readLine())
139+
modem.closeAll()
140-
    off = tonumber(sr.readLine())
140+
modem.open(port)
141-
    auto_rods = sr.readLine()
141+
monX,monY = term.getSize()
142-
    auto_rf = tonumber(sr.readLine())
142+
143-
  sr.close()
143+
144
  	event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
145
	pharseMessage(message)
146
    clear()
147
    menu_bar()
148-
-- peripheral searching thanks to /u/kla_sch
148+
149-
function modemSearch()
149+
150-
   local names = peripheral.getNames()
150+
151-
   local i, name
151+
152-
   for i, name in pairs(names) do
152+
153-
      if peripheral.getType(name) == "modem" then
153+
154-
         return peripheral.wrap(name)
154+
155-
      else
155+
156-
         --return null
156+
157-
      end
157+
158-
   end
158+
159
160
    -----------FUEL---------------------
161-
function monitorSearch()
161+
162-
   local names = peripheral.getNames()
162+
163-
   local i, name
163+
164-
   for i, name in pairs(names) do
164+
165-
      if peripheral.getType(name) == "monitor" then
165+
166-
        test = name
166+
167-
         return peripheral.wrap(name)
167+
168-
      else
168+
169-
         --return null
169+
170-
      end
170+
    status_bar(2, 6, 24, minVal, medVal, maxVal, colors.blue, colors.red, colors.gray)
171-
   end
171+
    elseif percent < 40 then
172
    status_bar(2, 6, 24, minVal, medVal, maxVal, colors.blue, colors.orange, colors.gray)
173
    elseif percent < 60 then
174
    status_bar(2, 6, 24, minVal, medVal, maxVal, colors.blue, colors.yellow, colors.gray)
175
    elseif percent <= 80 then
176
    status_bar(2, 6, 24, minVal, medVal, maxVal, colors.blue, colors.lime, colors.gray)
177
    elseif percent <= 100 then
178
    status_bar(2, 6, 24, minVal, medVal, maxVal, colors.blue, colors.green, colors.gray)
179
	end
180-
	numRod = results[2]
180+
181-
	energyStored = results[3]
181+
182-
	fuelTemp = results[4]
182+
183-
	caseTemp = results[5]
183+
184-
	fuelQty = results[6]
184+
185-
	wasteQty = results[7]
185+
186-
	fuelMax = results[8]
186+
187-
	rodLevel = results[9]
187+
    progress_bar(2, 9, 24, minVal, maxVal, colors.cyan, colors.gray)
188-
	energyTick = results[10]
188+
    elseif minVal < 1000 then
189-
	fluidTick = results[11]
189+
    progress_bar(2, 9, 24, minVal, maxVal, colors.lime, colors.gray)
190-
	coolType = results[12]
190+
    elseif minVal < 1500 then  
191-
	coolQty = results[13]
191+
    progress_bar(2, 9, 24, minVal, maxVal, colors.yellow, colors.gray)
192-
	fluidType = results[14]
192+
    elseif minVal < 2000 then
193-
	react = results[15]
193+
    progress_bar(2, 9, 24, minVal, maxVal, colors.orange, colors.gray)
194-
	fuelTick = results[16]
194+
    elseif minVal >= 2000 then
195-
	isCooled = results[17]
195+
    progress_bar(2, 9, 24, 2000, maxVal, colors.red, colors.gray)
196-
    sleep(pharseSleep)
196+
197-
	call_homepage()
197+
198
    draw_text(15, 8, math.floor(minVal).." C", colors.white, colors.black)
199
  
200-
-----------------------Settings--------------------------------
200+
201
202-
function rf_mode()
202+
    draw_text(2, 11, "Fuel/Tick:", colors.lightGray, colors.black)
203-
  wait = read()
203+
204
    fuelConsumed = roundNumber(fuel_usage, 5)
205
    draw_text(13, 11, fuelConsumed.." mB/T", colors.white, colors.black)
206-
function steam_mode()
206+
207-
  wait = read()
207+
208
    if isCooled == "true" then
209
      draw_text(2, 12, "mB/tick:", colors.lightGray, colors.black)
210
      mbt = math.floor(energyTick)
211-
function terminal_screen()
211+
      draw_text(13, 12, mbt.." mB/t", colors.white, colors.black)
212
    else
213-
  draw_line_term(1, 1, 55, colors.purple)
213+
      draw_text(2, 12, "RF/Tick:", colors.lightGray, colors.black)
214-
  draw_text_term(13, 1, "BigReactor Controls", colors.white, colors.purple)
214+
215-
  draw_line_term(1, 19, 55, colors.purple)
215+
	    rft = rfScale(rft)
216-
  draw_text_term(13, 19, "by SparkyBearBomb", colors.white, colors.purple)
216+
      draw_text(13, 12, rft, colors.white, colors.black)
217
    end
218-
  draw_text_term(1, 3, "Current program:", colors.white, colors.black)
218+
219-
  draw_text_term(1, 4, "Reactor Control v"..version, colors.blue, colors.black)
219+
220
    energy_stored_percent = math.floor((energyQty/energyMax)*100)
221-
  draw_text_term(1, 6, "Installer:", colors.white, colors.black)
221+
	  if isCooled == "true" then
222-
  draw_text_term(1, 7, "pastebin.com/ELJptBRk", colors.blue, colors.black)
222+
      draw_text(2, 14, "mB Stored:", colors.lightGray, colors.black)
223
    else
224-
  draw_text_term(1, 9, "Please give me your feedback, suggestions,", colors.white, colors.black)
224+
      draw_text(2, 14, "RF Stored:", colors.lightGray, colors.black)
225-
  draw_text_term(1, 10, "and errors!", colors.white, colors.black)
225+
226
    draw_text(13, 14, energy_stored_percent.."%", colors.white, colors.black)
227-
  draw_text_term(1, 11, "http://pastebin.com/u/Sparkybearbomb", colors.blue, colors.black)
227+
    progress_bar(2, 15, 24, energy_stored_percent, 100, colors.green, colors.gray)
228
    ------------CONTROL RODS------------
229
      
230-
--run both homepage() and stop() until one returns
230+
    draw_text(2, 17, "Control Rods:", colors.lightGray, colors.black)
231-
function call_homepage() 
231+
    draw_text(16, 17, rodLevel.."%", colors.white, colors.black)
232-
  if stop_function == "terminal_screen" then
232+
    progress_bar(2, 18, 24, rodLevel, 100, colors.cyan, colors.gray)
233-
    stop_function = "nothing"
233+
end