Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Parte logica del programma di gestione fabbrica
- -- Variabili Globali
- local gpuutils = require("screen_utils")
- local component = require("component")
- local term = require("term")
- local event = require("event")
- local serialization = require("serialization")
- local modem = component.modem
- local running = true
- local charges = {}
- local currentChargeX = 30
- local currentChargeY = 10
- --------------------------------------
- -- Move this to graphic
- function DrawBattery(x,y,charge,name)
- fullH = 4
- DrawRectangle(x,y,3,fullH,0x990000)
- height = fullH * charge
- y = y+(fullH-height)
- DrawRectangle(x,y,3,height,0x009900)
- end
- function GetDataTable()
- end
- local eventHandler = setmetatable({}, { __index = function() return unknownEvent end })
- function unknownEvent()
- end
- function eventHandler.touch(id, x, y)
- print("Touch "..x..","..y)
- running = false;
- end
- -- Modem Messages
- function AddBatteryToList( address )
- newCharge = {}
- newCharge["x"] = currentChargeX;
- newCharge["y"] = currentChargeY;
- currentChargeX = currentChargeX + 15
- charges[address] = newCharge
- end
- function eventHandler.modem_message(_,_,from,port,_,message)
- if (_) then
- value = serialization.unserialize(_)
- if (value["id"] == "charge_report") then
- if (not charges[value["address"]]) then
- AddBatteryToList( value["address"] )
- end
- bat = charges[value["address"]]
- DrawBattery(bat["x"], bat["y"], value["charge"], "Charge")
- end
- end
- end
- -------------------------------------
- function HandleEvent(eventId, ...)
- -- print("event id:"..eventId)
- if (eventId) then
- eventHandler[eventId](...)
- end
- end
- modem.open(20)
- print(modem.isOpen(20))
- while(running) do
- HandleEvent(event.pull())
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement