added energy_control

This commit is contained in:
navid.sassan 2021-04-02 16:25:56 +02:00
parent 02924eb7bf
commit 3d99d2b302

78
energy_control Normal file
View File

@ -0,0 +1,78 @@
redstone_toggle_id = 48
de_store_mon_id = nil
redstone_toggle_state = nil
function dump(o)
if o == nil then
return ""
end
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
end
return tostring(o)
end
function poll()
if redstone_toggle_id ~= nil then
rednet.send(redstone_toggle_id, "get_state")
end
if de_store_mon_id ~= nil then
-- todo
end
end
function recv()
while true do
local id, data = rednet.receive()
if id == redstone_toggle_id then
if type(data) == 'table' then
if data[1] == 'output_state' then
redstone_toggle_state = data[2]
end
end
elseif id == de_store_mon_id then
-- todo
end
end
end
function draw_screen()
while true do
term.clear()
term.setCursorPos(0, 0)
term.setTextColor(colors.white)
term.getBackgroundColor(colors.black)
term.write('Press "R" to toggle the rainbows\n')
term.write('Rainbows state: ')
if redstone_toggle_state == true then
term.getBackgroundColor(colors.green)
term.write('On')
else
term.getBackgroundColor(colors.red)
term.write('Off')
end
term.getBackgroundColor(colors.black)
sleep(0.5)
end
end
local sides = peripheral.getNames()
for i = 1, #sides do
if peripheral.getType(sides[i]) == "modem" then
modemSide = sides[i]
break
end
end
rednet.open(modemSide)
rednet.host("rmm", "master")
parallel.waitForAny(recv, control)
rednet.close(modemSide)