View difference between Paste ID: Q4fF9A5s and zScAy5h3
SHOW: | | - or go back to the newest paste.
1
local uk = "unknown"
2
local p = peripheral
3
local cname = "cofh_thermalexpansion_energycell_"
4
local mname = "monitor_"
5
local sm = "                                                                     "
6
local k = 0 --X
7
local l = 0 --X
8
local m = 0 --X
9
local n = 0 --X
10
local o = 0 --X
11-
local q = 0
11+
local q = 0 --X
12
local r = 0
13
local s = 0
14
local UHSLC = 0
15
local num = 0
16
local energy = 0
17
local maxenergy = 0
18
local monitors = {}
19
local cells = {}
20
local numbers = {}
21
local timeINNum = 0
22
local midnum = 0
23-
local cme
23+
local cme = 0
24-
local ce
24+
local ce = 0
25
local mx = 0
26
local inStartNum
27
local inSumNum
28
local inIDNum
29
--local writeISNfile = fs.open("inSumNum","w")
30
--local readISNfile = fs.open("inSumNum","r")
31
--local writeIIDNfile = fs.open("inIDNum","w")
32
--local readIIDNfile = fs.open("inIDNum","r")
33
--local writeTINNfile = fs.open("timeINNum","w")
34
--local readTINNfile = fs.open("timeINNum","r")
35
--local writeCELLSfile = fs.open("CELLS","w")
36
--local readCELLSfile = fs.open("CELLS","r")
37
--local fileDataISN={}
38
--local fileDataIIDN={}
39
--local fileDataTINN={}
40
--local fileDataCELLS={}
41
--local ISNLine = readISNfile.readLine()
42
--local IIDNLine = readIIDNfile.readLine()
43
--local TINNLine = readIIDNfile.readLine()
44
--local CELLSLine = readCELLSfile.readLine()
45
46
function initNumArray()
47
 for i=0,500 do
48
  numbers[i+1]=i
49
 end
50
end
51
52
function configMonitor()
53
 term.clear()
54
 term.setCursorPos(1,1)
55
 local mid = 0
56
 print("Bitte gebe die aktive(!) Rednet-ID des 3x2 (bxl) Monitors ein!")
57
 print("Bitte beachte, dass das Programm abstürzt, wenn es keine Zahl erhält!")
58
 mid = read()
59
 mx = mid+midnum
60
 mon = p.wrap(mname..tonumber(mx))
61
end
62
63
function configCells()
64
 while l==0 do
65
  term.clear()
66
  term.setCursorPos(1,1)
67
  local cin = ""
68
  local inStart = ""
69
  --local inSum = ""
70
  --local inID = ""
71
  print("Willst du den automatischen oder den manuellen Modus für die Konfiguration deiner")
72
  print("Energiezellen benutzen?")
73
  print("Fuer den automatischen Modus, gebe 'auto' ein")
74
  print("Fuer den manuellen Modus, gebe 'manu' ein")
75
  print("Bitte beachte beim automatischen Modus, dass die IDs nacheinander folgen! (Wie z.B.: 1,2,3,4,5,...)")
76
  print("(Der autom. Modus ist einfacher, der manuelle Modus ist auch nicht schlecht!)")
77
  print("HINWEIS: Dieses Programm ist für die Energiezellen von Thermal Expansion 4 geschrieben worden!")
78
  print("(Für PROs: Das bedeutet, dass für dieses Programm die Standardbezeichnung")
79
  print("'cofh_thermalexpansion_energycell_' benutzt wird!)")
80
  cin = read()
81
  if cin=="auto" then
82
   l=1
83
   term.clear()
84
   term.setCursorPos(1,1)
85
   print("Du hast den automatischen Modus gewaehlt")
86
   os.sleep(1)
87
   print("Gebe nun die niedrigste ID deiner Energiezellen ein!")
88
   inStart = read()
89
   local writeIStNfile = fs.open("inStartNum","w")
90
   writeIStNfile.writeLine(inStart)
91
   writeIStNfile.close()
92
   inStartNum = tonumber(inStart)
93
   os.sleep(1)
94
   print("Gebe nun die Gesamtanzahl deiner Energiezellen ein!")
95
   local inSum = read()
96
   local writeISNfile = fs.open("inSumNum","w")
97
   writeISNfile.writeLine(inSum)
98
   writeISNfile.close()
99
   for i=0,500 do
100
    if tonumber(inSum)==numbers[i+1] then
101
     inSumNum=numbers[i+1]
102
    end
103
   end
104
   --inSumNum = tonumber(inSum)
105
   os.sleep(1)
106
   print("Energiezellen werden nun konfiguriert...")
107
   --local CELLSLine = writeCELLSfile.writeLine()
108
   local writeCELLSfile = fs.open("CELLS","w")
109
   for i=1,inSumNum do
110
    x=inStartNum+inSumNum
111
    cells[i] = peripheral.wrap(cname..x)
112
    print("Energiezelle 'c"..(i).."' wurde erfolgreich konfiguriert!")
113
   end
114
   --ct = textutils.serialize(cells)
115
   writeCELLSfile.write(cells)
116
   --repeat
117
   --table.insert(cells,CELLSLine)
118
   --CELLSLine = writeCELLSfile.writeLine()
119
   --until CELLSLine == nil
120
   writeCELLSfile.close()
121
   os.sleep(1)
122
   print("Energiezellen sind nun konfiguriert!")
123
  else
124
   if cin=="manu" then
125
    l=1
126
    term.clear()
127
    term.setCursorPos(1,1)
128
    print("Du hast den manuellen Modus gewaehlt")
129
    os.sleep(1)
130
    print("Gebe nun die Gesamtanzahl deiner Energiezellen ein!")
131
    local inSum = read()
132
    local writeISNfile = fs.open("inSumNum","w")
133
    writeISNfile.writeLine(inSum)
134
    writeISNfile.close()
135
    for i=0,500 do
136
     if tonumber(inSum)==numbers[i+1] then
137
      inSumNum=numbers[i+1]
138
     end
139
    end
140
    --inSumNum = tonumber(inSum)
141
    print("Gebe nun die(/alle) ID(s) deiner Energiezelle(n) nacheinander ein!")
142
    for i=1,inSumNum do
143
     local inID = read()
144
     local writeIIDNfile = fs.open("inIDNum","w")
145
     writeIIDNfile.writeLine(inID)
146
     writeIIDNfile.close() 
147
     for i=0,500 do
148
      if tonumber(inID)==numbers[i+1] then
149
       inIDNum = numbers[i+1]    
150
      end
151
     end
152
     --inIDNum = tonumber(inID)
153
     cells[i] = p.wrap(cname..inIDNum)
154
     print("Energiezelle 'c"..i.."' wurde erfolgreich konfiguriert!")
155
    end
156
   else
157
    l=0
158
    print(cin.." gibt es nicht!")
159
   end
160
  end
161
 end
162
end
163
164
function configComputer()
165
 while m==0 do
166
  term.clear()
167
  term.setCursorPos(1,1)
168
  local sideRN = ""
169
  print("Dein Computer wird jetzt fuer Rednet konfiguriert!")
170
  print("Gebe nun ein, an welcher Seite des PCs das (wireless) Modem für Rednet angeschlossen ist!")
171
  print("Verfuegbare Seiten: oben('top'), unten('bottom'), rechts('right'), links('left'), hinten('back')")
172
  print("Bitte beachte, dass das Programm abstuerzt, wenn an der angegebenen Seite kein Modem angeschlossen ist!")
173
  sideRN = read()
174
  if sideRN == "top" or sideRN == "bottom" or sideRN == "right" or sideRN == "left" or sideRN == "back" then
175
   rednet.open(sideRN)
176
   m=1
177
  else
178
   print(sideRN.." -Eingabe nicht akzeptabel!")
179
   m=0
180
  end  
181
 end
182
 while n==0 do
183
  term.clear()
184
  term.setCursorPos(1,1)
185
  --local timeIN = ""
186
  print("Gebe nun die Zeit in Sekunden ein, wie oft der Computer die Daten der Energiezelle(n) abfragen soll!")
187
  print("0 ist nicht akzeptabel! Wenn du bspw. jede halbe Sekunde haben willst, dann gebe '0.5' ein!")
188
  local timeIN = read()
189
  local writeTINNfile = fs.open("timeINNum","w")
190
  writeTINNfile.writeLine(timeIN)
191
  writeTINNfile.close() 
192
  for i=0,500 do
193
   if tonumber(timeIN)==numbers[i+1] then
194
    timeINNum = numbers[i+1]    
195
   end  
196
  end
197
  --timeINNum = tonumber(timeIN)
198
  if tonumber(timeIN)==0 then
199
   print("Bist du eigentlich behindert? Ich hab doch gesagt, dass '"..timeINNum.."' nicht akzeptiert wird -.-")
200
   n=0
201
  else
202
   print("Updateintervall wurde erfolgreich auf '"..timeINNum.."'s gesetzt")
203
   n=1
204
  end
205
 end
206
end
207
208
function setupMonitor()
209
 mon.setBackgroundColor(colors.lime)
210
 mon.setTextColor(colors.blue)
211
 for i=0,20 do
212
   mon.setCursorPos(1,i+1)
213
   mon.write(sm)
214
 end
215
  mon.setCursorPos(1,1)
216
  mon.write("       ENERGIE-MONITOR"..sm)  
217
end
218-
 local readCELLSfile = fs.open("CELLS","r")
218+
219
function readEnergy()
220-
 local fileDataCELLS={}
220+
 ce = 0
221
 cme = 0
222-
 local CELLSLine = readCELLSfile.readLine()
222+
223
 local readIStNfile = fs.open("inStartNum","r")
224
 --local readCELLSfile = fs.open("CELLS","r")
225
 local fileDataISN={}
226
 local fileDataIStN={}
227
 --local fileDataCELLS={}
228
 local ISNLine = readISNfile.readLine()
229
 local IStNLine = readIStNfile.readLine()
230
 --local CELLSLine = readCELLSfile.readLine()
231
 repeat
232-
 --for i=1,(tonumber(fileDataISN[1])+0) do
232+
233-
 for i=1,14 do
233+
234
 until ISNLine == nil
235
 repeat
236
 table.insert(fileDataIStN,IStNLine)
237
 IStNLine = readIStNfile.readLine()
238
 until IStNLine == nil
239
 --repeat
240
 --table.insert(fileDataCELLS,CELLSLine)
241
 --CELLSLine = readCELLSfile.readLine()
242-
 readCELLSfile.close()
242+
243
 --cells = textutils.unserialize(fileDataCELLS.readAll())
244
 for i=1,(tonumber(fileDataISN[1])+0) do
245
  --local e = 0
246
  --local me = 0
247
  cells = {}
248
  cells[i] = peripheral.wrap(tostring(cname..(fileDataIStN[1]+0)))
249
  energy = cells[i].getEnergyStored("unknown")
250
  maxenergy = cells[i].getMaxEnergyStored("unknown")
251
  ce = ce+energy
252
  cme = cme+maxenergy
253
 end
254
 readISNfile.close()
255
 readIStNfile.close()
256
 --readCELLSfile.close()
257
end
258
259
function writeEnergy()
260
  local readTINNfile = fs.open("timeINNum","r")
261
  local fileDataTINN={}
262
  local TINNLine = readTINNfile.readLine()
263
  repeat
264-
    mon.write("Check"..fileDataTINN[1].."s): +"..cen-ceo.."RF"..sm)
264+
265
  TINNLine = readTINNfile.readLine()
266
  until TINNLine == nil
267
  readTINNfile.close()
268
  mon.setCursorPos(1,2)
269
  mon.clearLine()
270
  mon.write("Energie: "..ce.."RF"..sm)
271-
      mon.write(mm)
271+
272
  local cen = ce
273
  if cen>ceo then
274
    mon.clearLine()
275
    mon.write("Energiegewinn seit letztem"..sm)
276
    mon.setCursorPos(1,4)
277
    mon.clearLine()
278-
        mon.write("Check"..fileDataTINN[1].."s): -"..ceo-cen.."RF"..sm)
278+
    mon.write("Check ("..fileDataTINN[1].."s): +"..cen-ceo.."RF"..sm)
279
  else
280
    if cen==ceo then
281
      mon.clearLine()
282
      mon.write("Gleicher Energiestand"..sm)
283
      mon.setCursorPos(1,4)
284
      mon.clearLine()
285
      mon.write(sm)
286
    else
287
      if c13n<c13o then
288
        mon.clearLine()
289
        mon.write("Energieverlust seit letztem"..sm)
290
        mon.setCursorPos(1,4)
291
        mon.clearLine()
292
        mon.write("Check ("..fileDataTINN[1].."s): -"..ceo-cen.."RF"..sm)
293
      end
294
    end
295
  end   
296
  local ep = cen/cme*100
297
  mon.setCursorPos(1,6)
298
  mon.clearLine()
299
  mon.write(" (in '%'):"..sm)
300
  mon.setCursorPos(1,7)
301-
  local readCELLSfile = fs.open("CELLS","r")
301+
302
  mon.write(ep.."%"..sm)
303-
  local fileDataCELLS={}
303+
304
305-
  local CELLSLine = readCELLSfile.readLine()
305+
306
  if o==0 then								
307
    ceo=0  								
308
    o=1									
309
  end
310
end
311
312
function calcEnergyB()
313
  ceo = 0      		
314
  local readISNfile = fs.open("inSumNum","r")
315
  local readIStNfile = fs.open("inStartNum","r")
316
  --local readCELLSfile = fs.open("CELLS","r")
317
  local fileDataISN={}
318
  local fileDataIStN={}
319
  --local fileDataCELLS={}
320
  local ISNLine = readISNfile.readLine()
321-
  readCELLSfile.close()							
321+
  local IStNLine = readIStNfile.readLine()
322
  --local CELLSLine = readCELLSfile.readLine()
323
  repeat
324
  table.insert(fileDataISN,ISNLine)
325
  ISNLine = readISNfile.readLine()
326
  until ISNLine == nil
327
  repeat
328
  table.insert(fileDataIStN,IStNLine)
329
  IStNLine = readIStNfile.readLine()
330
  until IStNLine == nil
331
  --repeat
332
  --table.insert(fileDataCELLS,CELLSLine)
333
  --CELLSLine = readCELLSfile.readLine()
334
  --until CELLSLine == nil
335
  --cells = textutils.unserialize(fileDataCELLS.readAll())
336-
 if m==0 then
336+
337
   local eo = 0
338-
  m=1
338+
   cells = {}
339
   cells[i] = peripheral.wrap(tostring(cname..(fileDataIStN[1]+0)))
340
   eo = cells[i].getEnergyStored("unknown")
341
   ceo = ceo+eo
342
  end	
343
  readISNfile.close()
344-
 rednetListenet()
344+
  readIStNfile.close()
345
  --readCELLSfile.close()							
346
end
347
348
function rednetListener()
349
350
end
351
352
while true do
353-
 os.sleep((fileDataTINN[1]+0))
353+
354
  initNumArray()
355
  configComputer()
356
  configMonitor()
357
  configCells()
358
  k=1
359
 end
360
 if q==0 then
361
  setupMonitor()
362
  q=1
363
 end
364
 calcEnergyA()
365
 readEnergy()
366
 writeEnergy()
367
 calcEnergyB()
368
 rednetListener()
369
 local readTINNfile = fs.open("timeINNum","r")
370
 local fileDataTINN={}
371
 local TINNLine = readTINNfile.readLine()
372
 repeat
373
 table.insert(fileDataTINN,TINNLine)
374
 TINNLine = readTINNfile.readLine()
375
 until TINNLine == nil
376
 os.sleep(tonumber((fileDataTINN[1]+0)))
377
 readTINNfile.close()
378
end