Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor");
- if not fs.exists("ui") then
- shell.run("pastebin get MxxrdRK2 ui")
- end
- lastCount = 0;
- local mfsu = "LiFePO4 battery bank";
- aesu = "Adjustable Energy Storage Unit"
- 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 (device.Name == aesu) then
- print("AESU - ", Nslot);
- elseif (device.Name == mfsu) 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(device.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(device.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
- if type(prox.getTargetDetails(name)) == "table" then
- local moreDetails = prox.getTargetDetails(name);
- if moreDetails.Name == aesu or moreDetails.Name == mfsu then
- t[i] = moreDetails;
- i = i + 1;
- count = count + 1;
- end
- end
- end
- if (count ~= lastCount) then
- term.clear()
- end
- local Ncol = 0;
- Nriga = 1;
- x = 2;
- y = 3
- for i = 1, count do
- if Nriga > 1 then
- x = x + 17
- if Nriga == 6 then
- x = 2
- Nriga = 1
- Ncol = 1
- end
- end
- if Ncol == 1 then
- y = y + 6
- Ncol = 0
- end
- Nriga = Nriga + 1
- show(t[i], i, x, y);
- end
- if count % 5 ~= 0 then
- for i = count + 1, count + 5 - count % 5 do
- x = x + 17
- NoInput(x, y);
- end
- end
- lastCount = count;
- sleep(1);
- end
Advertisement
Add Comment
Please, Sign In to add comment