SHOW:
|
|
- or go back to the newest paste.
1 | -- Monitors TE3 Energy cells and EnderIO capacitor banks and output redstone signals once energy storage drops below set limits. | |
2 | -- Will automatically detect direction of adjacent storage device and (optional) Advanced Monitors. If chosen, monitor format should be 1 high and 2 wide. Now also with wired modem support for both storage and monitors. Directly adjacent devices will take priority over any wired devices. | |
3 | -- Redstone signal for the engines will be output out the back of the computer. | |
4 | --More details: http://forum.feed-the-beast.com/threads/rhns-1-6-monster-build-journal-and-guide-collection.42664/page-15#post-718973 | |
5 | ||
6 | ||
7 | local upper = 0.90 --Upper limit for computer to stop transmitting redstone signal. 0.90=90% full. | |
8 | local lower = 0.10 --Lower limit for computer to start transmitting redstone signal. | |
9 | ||
10 | output_side = "top" | |
11 | ||
12 | --Device detection | |
13 | isError=0 | |
14 | ||
15 | function detectDevice(DeviceName) | |
16 | DeviceSide="none" | |
17 | for k,v in pairs(redstone.getSides()) do | |
18 | if peripheral.getType(v)==DeviceName then | |
19 | DeviceSide = v | |
20 | break | |
21 | end | |
22 | end | |
23 | return(DeviceSide) | |
24 | end | |
25 | ||
26 | ||
27 | cell="none" | |
28 | monitor="none" | |
29 | local peripheralList = peripheral.getNames() | |
30 | ||
31 | CellSide=detectDevice("cofh_thermalexpansion_energycell") | |
32 | ||
33 | if CellSide~="none" then | |
34 | cell=peripheral.wrap(CellSide) | |
35 | print ("TE Energy cell on the " .. CellSide .. " connected.") | |
36 | else | |
37 | CellSide=detectDevice("tile_enderio_blockcapacitorbank_name") | |
38 | if CellSide~="none" then | |
39 | cell=peripheral.wrap(CellSide) | |
40 | print ("EnderIO capacitorbank on the " .. CellSide .. " connected.") | |
41 | else | |
42 | for Index = 1, #peripheralList do | |
43 | if string.find(peripheralList[Index], "cofh_thermalexpansion_energycell") then | |
44 | cell=peripheral.wrap(peripheralList[Index]) | |
45 | print ("TE Energy cell on wired modem: "..peripheralList[Index].." connected.") | |
46 | elseif string.find(peripheralList[Index], "tile_enderio_blockcapacitorbank_name") then | |
47 | cell=peripheral.wrap(peripheralList[Index]) | |
48 | print ("EnderIO capacitorbank on wired modem: "..peripheralList[Index].." connected.") | |
49 | end | |
50 | end --for | |
51 | if cell == "none" then | |
52 | print("No Energy storage found. Halting script!") | |
53 | return | |
54 | end | |
55 | ||
56 | end | |
57 | end | |
58 | ||
59 | ||
60 | MonitorSide=detectDevice("monitor") | |
61 | ||
62 | if MonitorSide~="none" then | |
63 | monitor=peripheral.wrap(MonitorSide) | |
64 | print ("Monitor on the " .. MonitorSide .. " connected.") | |
65 | else | |
66 | for Index = 1, #peripheralList do | |
67 | if string.find(peripheralList[Index], "monitor") then | |
68 | monitor=peripheral.wrap(peripheralList[Index]) | |
69 | print ("Monitor on wired modem: "..peripheralList[Index].." connected.") | |
70 | end | |
71 | end --for | |
72 | if monitor == "none" then | |
73 | print ("Warning - No Monitor attached, continuing without.") | |
74 | end | |
75 | end | |
76 | ||
77 | - | redstone.setOutput("back", false) --Defaulting to off |
77 | + | |
78 | redstone.setOutput(output_side, false) --Defaulting to off | |
79 | ||
80 | --If monitor is attached, write data on monitor | |
81 | if monitor ~= "none" then | |
82 | monitor.clear() | |
83 | monitor.setBackgroundColour((colours.grey)) | |
84 | monitor.setCursorPos(1,4) | |
85 | monitor.write(" ON ") | |
86 | monitor.setBackgroundColour((colours.green)) | |
87 | monitor.setCursorPos(5,4) | |
88 | monitor.write(" OFF ") | |
89 | monitor.setBackgroundColour((colours.black)) | |
90 | end | |
91 | ||
92 | --Main loop | |
93 | while true do | |
94 | --Get storage values | |
95 | eNow = cell.getEnergyStored("unknown") | |
96 | eMax = cell.getMaxEnergyStored("unknown") | |
97 | ||
98 | --Compute ratio | |
99 | fill = (eNow / eMax) | |
100 | ||
101 | --If monitor is attached, write data on monitor | |
102 | if monitor ~= "none" then | |
103 | ||
104 | if eMax >= 10000000 then | |
105 | monitor.setCursorPos(11,2) | |
106 | monitor.write("Storage:") | |
107 | monitor.setCursorPos(11,3) | |
108 | monitor.write(math.ceil(eNow/1000).."kRF") | |
109 | monitor.setCursorPos(11,4) | |
110 | monitor.write("Of:") | |
111 | monitor.setCursorPos(11,5) | |
112 | monitor.write(math.ceil(eMax/1000).."kRF") | |
113 | else | |
114 | monitor.setCursorPos(11,2) | |
115 | monitor.write("Storage:") | |
116 | monitor.setCursorPos(11,3) | |
117 | monitor.write(math.ceil(eNow)) | |
118 | monitor.setCursorPos(11,4) | |
119 | monitor.write("Of:") | |
120 | monitor.setCursorPos(11,5) | |
121 | monitor.write(math.ceil(eMax)) | |
122 | end | |
123 | ||
124 | monitor.setCursorPos(1,2) | |
125 | monitor.write("Engines:") | |
126 | end | |
127 | ||
128 | if fill > upper then | |
129 | - | redstone.setOutput("back", false) |
129 | + | |
130 | redstone.setOutput(output_side, false) | |
131 | ||
132 | if monitor ~= "none" then | |
133 | monitor.setBackgroundColour((colours.grey)) | |
134 | monitor.setCursorPos(1,4) | |
135 | monitor.write(" ON ") | |
136 | monitor.setBackgroundColour((colours.green)) | |
137 | monitor.setCursorPos(5,4) | |
138 | monitor.write(" OFF ") | |
139 | monitor.setBackgroundColour((colours.black)) | |
140 | end | |
141 | ||
142 | elseif fill < lower then | |
143 | - | redstone.setOutput("back", true) |
143 | + | |
144 | redstone.setOutput(output_side, true) | |
145 | ||
146 | if monitor ~= "none" then | |
147 | monitor.setBackgroundColour((colours.green)) | |
148 | monitor.setCursorPos(1,4) | |
149 | monitor.write(" ON ") | |
150 | monitor.setBackgroundColour((colours.grey)) | |
151 | monitor.setCursorPos(5,4) | |
152 | monitor.write(" OFF ") | |
153 | monitor.setBackgroundColour((colours.black)) | |
154 | end | |
155 | end | |
156 | ||
157 | ||
158 | sleep(1) | |
159 | end --while |