Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor");
- lastCount = 0;
- for a, b in pairs(rs.getSides()) do
- if peripheral.getType(b) == "sensor" then
- prox = sensor.wrap(b);
- break
- end
- end
- for a, b in pairs(rs.getSides()) do
- if peripheral.getType(b) == "monitor" then
- mon = peripheral.wrap(b);
- break
- end
- end
- term.redirect(mon);
- -- stati batterie
- function ChangeState(x,y,color)
- term.setCursorPos(x, y);
- term.setTextColor(color);
- print("||");
- term.setTextColor(colors.white);
- end
- function ClearState(x,y)
- term.setCursorPos(x,y);
- term.setTextColor(colors.black);
- print("||");
- term.setTextColor(colors.white);
- end
- -- azioni a seconda della carica della batteria
- function battery(l, b)
- local red = colors.red;
- local yellow = colors.yellow;
- local green = colors.lime;
- if percent < 33 then
- ChangeState(l, b,red);
- ClearState(l,b-1);
- ClearState(l,b-2);
- elseif percent >= 33 and (percent <= 66) then
- ChangeState(l, b,red);
- ChangeState(l, b-1,yellow);
- ClearState(l,b-2);
- elseif percent >= 66 then
- ChangeState(l, b,red);
- ChangeState(l, b-1,yellow);
- ChangeState(l, b-2,green);
- end
- end
- function show(device, Nslot, Xstart, Ystart)
- local details = prox.getTargetDetails(device);
- term.setCursorPos(Xstart, Ystart);
- if (details.Name == "Adjustable Energy Storage Unit") then
- print("AESU - ",Nslot);
- elseif (details.Name == "LiFePO4 battery") then
- print("LiFePO4 - ",Nslot);
- end
- term.setCursorPos(Xstart+1, Ystart+1);
- term.setTextColor(colors.black);
- print("--------");
- term.setCursorPos(Xstart+1, Ystart+1);
- term.setTextColor(colors.white);
- print(math.floor(details.Stored));
- term.setCursorPos(Xstart+2, Ystart+2);
- term.setTextColor(colors.black);
- print("-------");
- term.setCursorPos(Xstart+2, Ystart+2);
- term.setTextColor(colors.white);
- percent = math.floor(details.StoredPercentage);
- print(percent, "%");
- battery(Xstart+11, Ystart+2);
- end
- function NoInput(x,y)
- term.setCursorPos(x, y);
- print("No Input");
- end
- -- controllo batterie
- while true do
- shell.run("ui");
- t = {};
- tar = prox.getTargets();
- i = 1;
- count = 0;
- for name, basicDetails in pairs(tar) do
- local moreDetails = prox.getTargetDetails(name);
- if moreDetails.Name == "Adjustable Energy Storage Unit" or moreDetails.Name == "LiFePO4 battery" then
- t[i] = name;
- i = i + 1;
- count = count + 1;
- end
- end
- if(count ~= lastCount) then
- term.clear()
- end
- if count > 0 then
- show(t[1],1,3,3);
- else
- NoInput(4,4);
- end
- if count > 1 then
- show(t[2],2,20,3);
- else
- NoInput(21,4);
- end
- if count > 2 then
- show(t[3],3,36,3);
- else
- NoInput(37,4);
- end
- if count > 3 then
- show(t[4],4,3,9);
- else
- NoInput(4,10);
- end
- if count > 4 then
- show(t[5],5,20,9);
- else
- NoInput(21,10);
- end
- if count > 5 then
- show(t[6],6,36,9);
- else
- NoInput(37, 10);
- end
- if count > 6 then
- show(t[7],7,3,15);
- else
- NoInput(4, 16);
- end
- if count > 7 then
- show(t[8],8,20,15);
- else
- NoInput(21, 16);
- end
- if count > 8 then
- show(t[9],9,36,15);
- else
- NoInput(37, 16);
- end
- lastCount = count;
- sleep(1);
- end
Advertisement
Add Comment
Please, Sign In to add comment