SHOW:
|
|
- or go back to the newest paste.
1 | os.loadAPI("ocs/apis/sensor") | |
2 | local power = sensor.wrap("left") | |
3 | local net = peripheral.wrap("back") | |
4 | local mon = "monitor_0" | |
5 | if ( power == nil ) then | |
6 | print("No sensor!") | |
7 | os.exit() | |
8 | - | -- coordinates of block to monitor |
8 | + | |
9 | - | local location = "-1,1,0" |
9 | + | if ( net == nil ) then |
10 | print("No network!") | |
11 | - | -- amount of energy space needed to turn on |
11 | + | |
12 | - | local trigger = 2000 |
12 | + | |
13 | ||
14 | -- coordinates of blocks to monitor | |
15 | local locations = {"-1,-1,0","0,-1,0","1,-1,0","-2,-2,-1"} | |
16 | - | local blockInfo = power.getTargetDetails(location) |
16 | + | |
17 | - | if ( blockInfo == nil ) then |
17 | + | function displayPercent(percent) |
18 | - | print("Can't get block info") |
18 | + | net.callRemote(mon,"clear") |
19 | - | os.exit() |
19 | + | net.callRemote(mon,"setCursorPos",2,3) |
20 | --local display = string.format("%.2f",percent) | |
21 | - | return blockInfo["EnergySunken"] |
21 | + | local display = string.sub(tostring(percent),1,4) .. "%" |
22 | net.callRemote(mon,"write",display) | |
23 | end | |
24 | ||
25 | ||
26 | - | if ( getEnergySpace() < trigger ) then |
26 | + | |
27 | - | rs.setOutput("top",true) |
27 | + | local location |
28 | local total = 0 | |
29 | local totalStorage = 0 | |
30 | - | rs.setOutput("top",false) |
30 | + | for i,location in ipairs(locations) do |
31 | local blockInfo = power.getTargetDetails(location) | |
32 | if ( blockInfo == nil ) then | |
33 | print("Can't get block info " .. location) | |
34 | exit() | |
35 | end | |
36 | total = total + blockInfo["Stored"] | |
37 | totalStorage = totalStorage + blockInfo["Capacity"] | |
38 | end | |
39 | ||
40 | percentTotal = 100 * total / totalStorage | |
41 | ||
42 | displayPercent(percentTotal) | |
43 | ||
44 | return percentTotal | |
45 | end | |
46 | ||
47 | ||
48 | while true do | |
49 | if ( getEnergySpace() < 95 ) then | |
50 | rs.setBundledOutput("right",colors.white) | |
51 | os.sleep(2) | |
52 | else | |
53 | rs.setBundledOutput("right",0) | |
54 | os.sleep(10) | |
55 | end | |
56 | end |