View difference between Paste ID: spgBhL3f and tDuTcdSw
SHOW: | | - or go back to the newest paste.
1
require('BC_Mgr/Util/loadTable')
2
3
function setDevices(class)
4
    local devices = peripheral.getNames()
5
    
6
    deviceList = {}
7
    for device, value in pairs(devices) do
8
    
9
        if string.find(value, class) then 
10
            deviceList[#deviceList+1] = value
11
        end
12
    end 
13
    
14
    file = 'BC_Mgr/classes/'..class
15
    tables.write(file, deviceList)
16
    return true
17
end
18
19
function getDevices(class)
20
    local file = 'BC_Mgr/classes/'..class
21
    return tables.load(file)
22
end
23
24
function rs_signal(capacity, total)
25
    if total/capacity < 0.9f then
26
        redstone.setAnalogOutput('bottom', 15 )
27
        return 'on'
28
    else
29
        redstone.setAnalogOutput('bottom', 0)
30
        return 'off'
31
    end
32
end
33
34
function fuel_engines()
35
    local chests = getDevices('chest')
36
    local engines = getDevices('engine')
37
    for k, engine in pairs(engines) do
38
--        print('working on engine:', engine)
39
        local p = peripheral.wrap(engine)
40
        local eng_type = peripheral.getType(engine)
41
        local fuels = tables.load('BC_Mgr/dat/fuels')
42
        local eng_fuels = fuels[eng_type]
43
                  
44
        if eng_type=='items' then
45
            local item = p.getItem(1)
46
            local count = item.count
47
            if count < 1 then
48
                print(count)
49
            end
50
        end    
51
    end
52
end    
53
            
54
classList = tables.load('BC_Mgr/dat/classList')
55
--print(classList)
56
loop=true
57
main = peripheral.wrap('top')
58
term.redirect(main)
59
term.clear()
60
term.setCursorPos(1,1)
61
while loop do
62
    
63
--    q = os.pullEvent('char')
64
--    print(q)
65
--    if q == 'q' or q=='Q' then
66
--        loop=false
67
--    end
68
69
    main = peripheral.wrap('top')
70
    --term.redirect(main)
71
    --term.clear()
72
    --term.setCursorPos(1,1)
73
    --print('set classes:')
74
    
75
    
76
    for class in ipairs(classList) do
77
        setDevices(class)    
78
    end
79
    
80
--    print('get classes: in forestry')
81
    energy = {
82
        ['Stored'] = 0,
83
        ['Capacity'] = 0,
84
        ['Devices'] = {}
85
    }
86
    for k, device in ipairs(getDevices('forestry')) do
87
        p = peripheral.wrap(device)
88
        e = p.getEnergyStored()
89
        c = p.getEnergyCapacity()
90
--        print(device, c, e, c-e )
91
        energy['Stored'] = energy['Stored'] + e
92
        energy['Capacity'] = energy['Capacity'] + c
93
        energy['Devices'][device] = {
94
            ['Stored'] = e,
95
            ['Capacity'] = c
96
        }
97
    end
98
    signal = rs_signal(energy['Capacity'], energy['Stored'])
99
    term.clear()
100
    term.setCursorPos(1,1)
101
    print('Totals:')
102
    print('Capacity:', energy['Capacity'])
103
    print('Stored:', energy['Stored'])
104
    print('Deficit:', 
105
        energy['Capacity']-energy['Stored'], 
106
        '(',math.floor(energy['Stored']/energy['Capacity']*100),'%)')
107
    print('Engines:', signal)
108
    for k,v in pairs(energy.Devices) do
109
        print(k)
110
        for key, value in pairs(v) do
111
            print('\t',key, value)
112
        end
113
    end
114
    --fuel_engines()
115
    sleep(1)
116
end