tommy2805

Monitor batterie wireless pcreciver v1

Feb 26th, 2023 (edited)
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. for a, b in pairs(rs.getSides()) do
  2.     if peripheral.getType(b) == "monitor" then
  3.         mon = peripheral.wrap(b);
  4.         break
  5.     end
  6. end
  7. for a, b in pairs(rs.getSides()) do
  8.     if peripheral.getType(b) == "modem" then
  9.         rednet.open(b)
  10.         break
  11.     end
  12. end
  13. term.redirect(mon);
  14.  
  15. -- stati batterie
  16. function ChangeState(x, y, color)
  17.     term.setCursorPos(x, y);
  18.     term.setTextColor(color);
  19.     print("||");
  20.     term.setTextColor(colors.white);
  21. end
  22. function ClearState(x, y)
  23.     term.setCursorPos(x, y);
  24.     term.setTextColor(colors.black);
  25.     print("||");
  26.     term.setTextColor(colors.white);
  27. end
  28.  
  29. -- azioni a seconda della carica della batteria
  30. function battery(x, y)
  31.     local red = colors.red;
  32.     local yellow = colors.yellow;
  33.     local green = colors.lime;
  34.     if percent < 33 then
  35.         ChangeState(x, y, red);
  36.         ClearState(x, y - 1);
  37.         ClearState(x, y - 2);
  38.     elseif percent >= 33 and (percent <= 66) then
  39.         ChangeState(x, y, red);
  40.         ChangeState(x, y - 1, yellow);
  41.         ClearState(x, y - 2);
  42.     elseif percent >= 66 then
  43.         ChangeState(x, y, red);
  44.         ChangeState(x, y - 1, yellow);
  45.         ChangeState(x, y - 2, green);
  46.     end
  47. end
  48.  
  49. function show(details, Nslot, Xstart, Ystart)
  50.     term.setCursorPos(Xstart, Ystart);
  51.     if (details.Name == "Adjustable Energy Storage Unit") then
  52.         print("AESU - ", Nslot);
  53.     elseif (details.Name == "LiFePO4 battery") then
  54.         print("LiFePO4 - ", Nslot);
  55.     end
  56.     term.setCursorPos(Xstart + 1, Ystart + 1);
  57.     term.setTextColor(colors.black);
  58.     print("--------");
  59.     term.setCursorPos(Xstart + 1, Ystart + 1);
  60.     term.setTextColor(colors.white);
  61.     print(math.floor(details.Stored));
  62.     term.setCursorPos(Xstart + 2, Ystart + 2);
  63.     term.setTextColor(colors.black);
  64.     print("-------");
  65.     term.setCursorPos(Xstart + 2, Ystart + 2);
  66.     term.setTextColor(colors.white);
  67.     percent = math.floor(details.StoredPercentage);
  68.     print(percent, "%");
  69.     battery(Xstart + 11, Ystart + 2);
  70. end
  71.  
  72. function NoInput(x, y)
  73.     term.setCursorPos(x, y);
  74.     print("No Input");
  75. end
  76.  
  77. -- controllo batterie
  78. while true do
  79.     shell.run("ui");
  80.     id, message = rednet.receive();
  81.     Smessage = textutils.unserialize(message)
  82.     if (Smessage.Name == "clear") then
  83.         term.clear()
  84.     elseif Smessage.Name == "show" then
  85.         show(Smessage.details,Smessage.Nslot,Smessage.xPos,Smessage.yPos)
  86.     elseif Smessage.Name == "NoInput" then
  87.         NoInput(Smessage.xPos,Smessage.yPos)
  88.     end
  89.     sleep(1);
  90. end
  91.  
Advertisement
Add Comment
Please, Sign In to add comment