computercraft/energy_control
navid.sassan 1cdfd66ce9 testing
2021-04-02 16:46:12 +02:00

89 lines
2.3 KiB
Plaintext

redstone_toggle_id = 48
de_store_mon_id = 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()
while true do
if redstone_toggle_id ~= nil then
rednet.send(redstone_toggle_id, "get_state")
end
if de_store_mon_id ~= nil then
-- todo
end
sleep(1)
end
end
function recv()
local redstone_toggle_state = nil
local updated = false
while true do
local id, data = rednet.receive()
print(type(id))
if id == redstone_toggle_id then
if type(data) == 'table' then
print('table')
if data[1] == 'output_state' then
redstone_toggle_state = data[2]
updated = true
print('updated')
end
end
elseif id == de_store_mon_id then
-- todo
end
if updated == true then
print(tostring(redstone_toggle_state))
-- term.clear()
-- term.setCursorPos(0, 0)
-- term.setTextColor(colors.white)
-- term.setBackgroundColor(colors.black)
-- print('Press "R" to toggle the rainbows')
-- term.write('Rainbows state: ')
-- if redstone_toggle_state == true then
-- term.setBackgroundColor(colors.green)
-- term.write('On')
-- elseif redstone_toggle_state == false then
-- term.setBackgroundColor(colors.red)
-- term.write('Off')
-- elseif redstone_toggle_state == nil then
-- term.setBackgroundColor(colors.purple)
-- term.write('Unknown')
-- end
-- print()
-- term.setBackgroundColor(colors.black)
end
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(poll, recv)
rednet.close(modemSide)