SHOW:
|
|
- or go back to the newest paste.
| 1 | modem = peripheral.wrap("right")
| |
| 2 | monitor = peripheral.wrap("top")
| |
| 3 | monitor.setTextScale(1) | |
| 4 | ||
| 5 | lastStoredEnergy = 0 | |
| 6 | energyRate = 0 | |
| 7 | timeEmpty = 0 | |
| 8 | ||
| 9 | function comma_value(n) -- credit http://richard.warburton.it | |
| 10 | local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$') | |
| 11 | return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
| |
| 12 | end | |
| 13 | ||
| 14 | function SecondsToClock(nSeconds) | |
| 15 | if nSeconds == 0 then | |
| 16 | return "00:00:00" | |
| 17 | elseif nSeconds > -math.huge and nSeconds < math.huge then | |
| 18 | numHours = math.floor(nSeconds/3600) | |
| 19 | numMins = string.format("%.2d", math.floor(nSeconds/60 - (numHours*60)))
| |
| 20 | numSecs = string.format("%.2d", math.floor(nSeconds - numHours*3600 - numMins *60))
| |
| 21 | return numHours..":"..numMins..":"..numSecs | |
| 22 | else | |
| 23 | return "n/a" | |
| 24 | end | |
| 25 | end | |
| 26 | ||
| 27 | while(true) do | |
| 28 | numCells = 0 | |
| 29 | - | timeEmpty = math.floor((storedEnergy/energyRate)/60) |
| 29 | + | |
| 30 | ||
| 31 | for index,value in pairs(modem.getNamesRemote()) do | |
| 32 | - | monitor.write("Connected Cells: "..numCells)
|
| 32 | + | |
| 33 | - | monitor.setCursorPos(2,2) |
| 33 | + | |
| 34 | - | monitor.write("Stored Energy: "..storedEnergy.." ("..percentStored.."%)")
|
| 34 | + | |
| 35 | end | |
| 36 | - | monitor.write("Energy Use: "..energyRate.."/s")
|
| 36 | + | |
| 37 | ||
| 38 | - | monitor.write("Time to Empty: "..timeEmpty.." min")
|
| 38 | + | |
| 39 | storedEnergy = 0 | |
| 40 | maxStoredEnergy = 0 | |
| 41 | for index,value in pairs(attachedCells) do | |
| 42 | storedEnergy = storedEnergy + modem.callRemote(value, "getEnergyStored","") | |
| 43 | maxStoredEnergy = maxStoredEnergy + modem.callRemote(value, "getMaxEnergyStored","") | |
| 44 | end | |
| 45 | percentStored = math.floor(100*storedEnergy/maxStoredEnergy) | |
| 46 | energyRate = lastStoredEnergy - storedEnergy | |
| 47 | timeEmpty = math.floor(storedEnergy/energyRate) | |
| 48 | monitor.clear() | |
| 49 | monitor.setCursorPos(2,1) | |
| 50 | monitor.write("Connected Cells: "..comma_value(numCells))
| |
| 51 | monitor.setCursorPos(2,3) | |
| 52 | monitor.write("Stored Energy: "..comma_value(storedEnergy).." ("..percentStored.."%)")
| |
| 53 | monitor.setCursorPos(2,4) | |
| 54 | monitor.write("Energy Use: "..comma_value(energyRate).."/s")
| |
| 55 | monitor.setCursorPos(2,6) | |
| 56 | monitor.write("Time to Empty: "..SecondsToClock(timeEmpty))
| |
| 57 | print(i) | |
| 58 | os.sleep(1) | |
| 59 | lastStoredEnergy = storedEnergy | |
| 60 | end | |
| 61 | end |