SHOW:
|
|
- or go back to the newest paste.
1 | - | local gpuutils = require("screen_utils") |
1 | + | -- Parte logica del programma di gestione fabbrica |
2 | - | local component = require("component") |
2 | + | |
3 | - | local term = require("term") |
3 | + | -- Variabili Globali |
4 | - | local event = require("event") |
4 | + | local gpuutils = require("screen_utils") |
5 | - | local serialization = require("serialization") |
5 | + | local component = require("component") |
6 | - | |
6 | + | local term = require("term") |
7 | - | local modem = component.modem |
7 | + | local event = require("event") |
8 | - | local running = true |
8 | + | local serialization = require("serialization") |
9 | - | |
9 | + | |
10 | - | local charges = {} |
10 | + | local modem = component.modem |
11 | - | local currentChargeX = 30 |
11 | + | local running = true |
12 | - | local currentChargeY = 10 |
12 | + | |
13 | - | |
13 | + | local charges = {} |
14 | - | function DrawBattery(x,y,charge,name) |
14 | + | local currentChargeX = 30 |
15 | - | |
15 | + | local currentChargeY = 10 |
16 | - | fullH = 4 |
16 | + | -------------------------------------- |
17 | - | |
17 | + | |
18 | - | DrawRectangle(x,y,3,fullH,0x990000) |
18 | + | -- Move this to graphic |
19 | - | height = fullH * charge |
19 | + | function DrawBattery(x,y,charge,name) |
20 | - | y = y+(fullH-height) |
20 | + | |
21 | - | DrawRectangle(x,y,3,height,0x009900) |
21 | + | fullH = 4 |
22 | - | |
22 | + | |
23 | DrawRectangle(x,y,3,fullH,0x990000) | |
24 | - | |
24 | + | height = fullH * charge |
25 | - | function GetDataTable() |
25 | + | y = y+(fullH-height) |
26 | - | |
26 | + | DrawRectangle(x,y,3,height,0x009900) |
27 | ||
28 | - | |
28 | + | end |
29 | - | local eventHandler = setmetatable({}, { __index = function() return unknownEvent end }) |
29 | + | |
30 | - | |
30 | + | function GetDataTable() |
31 | - | function unknownEvent() |
31 | + | |
32 | - | |
32 | + | end |
33 | ||
34 | - | |
34 | + | local eventHandler = setmetatable({}, { __index = function() return unknownEvent end }) |
35 | - | function eventHandler.touch(id, x, y) |
35 | + | |
36 | - | print("Touch "..x..","..y) |
36 | + | function unknownEvent() |
37 | - | running = false; |
37 | + | |
38 | end | |
39 | - | |
39 | + | |
40 | - | function eventHandler.modem_message(_,_,from,port,_,message) |
40 | + | function eventHandler.touch(id, x, y) |
41 | - | if (_) then |
41 | + | print("Touch "..x..","..y) |
42 | - | value = serialization.unserialize(_) |
42 | + | running = false; |
43 | - | if (value["id"] == "charge_report") then |
43 | + | end |
44 | - | if (not charges[value["address"]]) then |
44 | + | |
45 | - | newCharge = {} |
45 | + | -- Modem Messages |
46 | - | newCharge["x"] = currentChargeX; |
46 | + | |
47 | - | newCharge["y"] = currentChargeY; |
47 | + | function AddBatteryToList( address ) |
48 | - | currentChargeX = currentChargeX + 15 |
48 | + | newCharge = {} |
49 | - | charges[value["address"]] = newCharge |
49 | + | newCharge["x"] = currentChargeX; |
50 | - | end |
50 | + | newCharge["y"] = currentChargeY; |
51 | - | bat = charges[value["address"]] |
51 | + | currentChargeX = currentChargeX + 15 |
52 | - | DrawBattery(bat["x"], bat["y"], value["charge"], "Charge") |
52 | + | charges[address] = newCharge |
53 | - | end |
53 | + | end |
54 | - | end |
54 | + | |
55 | function eventHandler.modem_message(_,_,from,port,_,message) | |
56 | - | |
56 | + | if (_) then |
57 | - | function HandleEvent(eventId, ...) |
57 | + | value = serialization.unserialize(_) |
58 | - | |
58 | + | if (value["id"] == "charge_report") then |
59 | - | -- print("event id:"..eventId) |
59 | + | |
60 | - | if (eventId) then |
60 | + | if (not charges[value["address"]]) then |
61 | - | eventHandler[eventId](...) |
61 | + | AddBatteryToList( value["address"] ) |
62 | - | end |
62 | + | end |
63 | ||
64 | - | |
64 | + | bat = charges[value["address"]] |
65 | - | modem.open(20) |
65 | + | DrawBattery(bat["x"], bat["y"], value["charge"], "Charge") |
66 | - | print(modem.isOpen(20)) |
66 | + | |
67 | - | |
67 | + | end |
68 | - | while(running) do |
68 | + | end |
69 | - | HandleEvent(event.pull()) |
69 | + | end |
70 | ||
71 | ------------------------------------- | |
72 | ||
73 | function HandleEvent(eventId, ...) | |
74 | ||
75 | -- print("event id:"..eventId) | |
76 | if (eventId) then | |
77 | eventHandler[eventId](...) | |
78 | end | |
79 | end | |
80 | ||
81 | modem.open(20) | |
82 | print(modem.isOpen(20)) | |
83 | ||
84 | while(running) do | |
85 | HandleEvent(event.pull()) | |
86 | end |