View difference between Paste ID: NYJ2NGqN and j7zCy3k6
SHOW: | | - or go back to the newest paste.
1-
--[[This is a fix of the original version (https://pastebin.com/knPtJCjb). Thanks to https://pastebin.com/dyre9saS and https://pastebin.com/gyMNUyRb for providing a fix to the clock while I was distracted from this project. I've remade the getTime function to make it work with Timezones again]] 
1+
function putValue(line, text, color)
2-
local mon = peripheral.find("monitor")
2+
    local align = 30 - string.len(text)
3-
local core = peripheral.find("draconic_rf_storage")
3+
    term.setCursorPos(align, line)
4-
local tier = 0
4+
    term.setTextColor(color)
5-
local colorShield = colors.white
5+
    print(text)
6-
local colorCore = colors.white
6+
7-
local input, output = peripheral.find("flux_gate")
7+
8-
local limitTransfer = true
8+
function DrawBox(xMin, xMax, yMin, yMax, title)
9-
local currentControls = "main"
9+
    term.setBackgroundColor(colors.gray)
10-
local page = 1
10+
    for xPos = xMin, xMax, 1 do
11-
local putLimit = ""
11+
        term.setCursorPos(xPos, yMin)
12-
local version = "1.0"
12+
        term.write(" ")
13-
local timediff = 0
13+
14-
local monthDays = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 ,31}
14+
15
        term.setCursorPos(xMin, yPos)
16-
if fs.exists("logs.cfg") then
16+
        term.write(" ")
17
        term.setCursorPos(xMax, yPos)
18-
	file = io.open("logs.cfg", "w")
18+
        term.write(" ")
19-
	file:write("")
19+
20-
	file:close()
20+
    for xPos = xMin, xMax, 1 do
21
        term.setCursorPos(xPos, yMax)
22
        term.write(" ")
23-
if fs.exists("config.cfg") then
23+
24
    term.setCursorPos(xMin + 4, yMin)
25-
	file = io.open("config.cfg", "w")
25+
    term.setBackgroundColor(colors.black)
26-
	file:write("Timezone: 0")
26+
    term.write(" ")
27-
	file:close()
27+
    term.write(title)
28
    term.write(" ")
29
end
30-
mon.setTextScale(1)
30+
31
function DrawProgress(xMin, xMax, yMin, yMax, percentage)
32-
local function fileWrite(path, text)
32+
    yTotal = yMax - yMin
33-
	local file = io.open(path, "w")
33+
    for xPos = xMin, xMax, 1 do
34-
	file:write(text)
34+
        term.setCursorPos(xPos, yMin)
35-
	file:close()
35+
        for yPos = yMin, yMax, 1 do
36
            yProgress = 1 - ((yPos - yMin) / yTotal)
37
            if yProgress <= percentage then
38-
local function fileWriteFromTable(path, t)
38+
                term.setPaletteColour(colors.green, 0x5cd65c)
39-
	local text = ""
39+
                term.setBackgroundColor(colors.green)
40-
	for _, line in pairs(t) do
40+
            else
41-
		text = text..line.."\n"
41+
                term.setPaletteColour(colors.red, 0xFF6666)
42-
	end
42+
                term.setBackgroundColor(colors.red)
43-
	fileWrite(path, text)
43+
44
            term.setCursorPos(xPos, yPos)
45
            term.write(" ")
46-
local function fileGetTable(path)
46+
47-
	if fs.exists(path) then
47+
48-
		local file = io.open(path, "r")
48+
    term.setBackgroundColor(colors.black)
49-
		local lines = {}
49+
50-
		local i = 1
50+
51-
		local line = file:read("*l")
51+
function putNumber(number)
52-
		while line ~= nil do
52+
    local round = 0
53-
			lines[i] = line
53+
    local texts = ""
54-
			line = file:read("*l")
54+
55-
			i = i +1
55+
    if number >= 1000000000000000000 then
56-
		end
56+
        round = (number / 1000000000000000000)
57-
		file:close()
57+
        texts = string.sub(round, 0, 3) .. "ERF"
58-
		return lines
58+
59-
	end
59+
        if number >= 1000000000000000 then
60-
	return {}
60+
            round = (number / 1000000000000000)
61
            texts = string.sub(round, 0, 3) .. "PRF"
62
        else
63-
local function fileReplaceLine(path, n, text)
63+
            if number >= 1000000000000 then
64-
	local lines = fileGetTable(path)
64+
                round = (number / 1000000000000)
65-
	lines[n] = text
65+
                texts = string.sub(round, 0, 3) .. "TRF"
66-
	fileWriteFromTable(path, lines)
66+
            else
67
                if number >= 1000000000 then
68
                    round = (number / 1000000000)
69-
local function fileAppend(path, text)
69+
                    texts = string.sub(round, 0, 3) .. "GRF"
70-
	local file = io.open(path, "a")
70+
                else
71-
	file:write(text.."\n")
71+
                    if number >= 1000000 then
72-
	file:close()
72+
                        round = (number / 1000000)
73
                        texts = string.sub(round, 0, 4) .. "MRF"
74
                    else
75-
local function fileGetLength(path)
75+
                        if number >= 1000 then
76-
	local file = io.open(path, "r")
76+
                            round = (number / 1000)
77-
	local i = 0
77+
                            texts = string.sub(round, 0, 4) .. "kRF"
78-
	while file:read("*l") ~= nil do
78+
                        else
79-
		i = i +1
79+
                            texts = string.sub(number, 0, 3) .. " RF"
80-
	end
80+
                        end
81-
	file:close()
81+
                    end
82-
	return i
82+
                end
83
            end
84
        end
85-
local function fileGetLines(path, startN, endN)
85+
86-
	local lines = fileGetTable(path)
86+
87-
	local linesOut = {}
87+
    return texts
88-
	local x = 1
88+
89-
	for i = startN, endN, 1 do
89+
90-
		linesOut[x] = lines[i]
90+
-- Initialize our interface!
91-
		x = x + 1
91+
-- Find all of our peripherals
92-
	end
92+
monitor = peripheral.find("monitor")
93-
	return linesOut	
93+
battery = peripheral.find("inductionMatrix")
94
95
-- Check and bind monitor
96-
local function editConfigFile(path,line,text)
96+
if monitor == nil then
97-
	fileReplaceLine(path,line,text)
97+
    error("ER: No screen found to display!")
98
else
99
    monitor.clear()
100-
local function detectInOutput()
100+
    term.redirect(monitor)
101-
	input, output = peripheral.find("flux_gate")
101+
    term.setCursorPos(1, 1)
102-
	--print(input)
102+
    term.setBackgroundColor(colors.black)
103-
	--print(output)
103+
104-
	if core.getTransferPerTick() ~= 0 then
104+
    DrawBox(2, 17, 2, 25, "ENERGY")
105-
		if core.getTransferPerTick() < 0 then
105+
106-
			output.setSignalLowFlow(0)
106+
107-
			sleep(2)
107+
-- Check if we have a battery
108-
			if core.getTransferPerTick() >= 0 then
108+
if battery == nil then
109-
				--keep it
109+
    error("ER: No battery connected to computer")
110-
			else
110+
111-
				output, input = peripheral.find("flux_gate")
111+
112-
			end
112+
--   -- Draw our static interface text
113-
			output.setSignalLowFlow(2147483647)
113+
--   term.setCursorPos(1, 2);
114-
			input.setSignalLowFlow(2147483647)
114+
--   print("Max RF:")
115-
		elseif core.getTransferPerTick() > 0 then
115+
--   term.setCursorPos(1, 3);
116-
			input.setSignalLowFlow(0)
116+
--   print("Max Thru:")
117-
			sleep(2)
117+
term.setCursorPos(1, 1)
118-
			if core.getTransferPerTick() <= 0 then
118+
DrawBox(2, 17, 20, 25, "CURRENT")
119-
				--keep it
119+
term.setTextColor(colors.green)
120-
			else
120+
term.setCursorPos(5, 22);
121-
				output, input = peripheral.find("flux_gate")
121+
print("In:")
122-
			end
122+
term.setTextColor(colors.red)
123-
			output.setSignalLowFlow(2147483647)
123+
term.setCursorPos(12, 22);
124-
			input.setSignalLowFlow(2147483647)
124+
print("Out:")
125-
		end
125+
--   term.setCursorPos(1, 7);
126-
	end	
126+
--   print("Cur Bal:")
127
128
--   term.setCursorPos(1, 9);
129-
if peripheral.find("flux_gate") == nil then
129+
--   print("Stored:")
130-
	limitTransfer = false
130+
--   term.setCursorPos(1, 10);
131-
else 
131+
--   print("Filled:")
132-
	limitTransfer = true
132+
--   term.setCursorPos(1, 11);
133-
	detectInOutput()
133+
--   print("Critical:")
134
135
-- Entering our infinite loop of checking the battery
136-
local function makeNumber2Digits(number)
136+
-- This will refresh all information every 2 seconds
137-
    strNumber = tostring(number)
137+
alarmIsRinging = false
138-
    if string.len(strNumber) == 1 then
138+
alarmIsActive = false
139-
        return "0" .. strNumber
139+
alarmCounter = 0
140
141-
        return string.sub(strNumber, string.len(strNumber) - 2)
141+
142
143
    -- batteryMaxCharge = battery.getMaxEnergy()
144
    -- batteryMaxInOuts = battery.getTransferCap()
145-
local function getTime(long)
145+
    -- -- putValue(2, putNumber(batteryMaxCharge), colors.lightBlue)
146-
    date_table = os.date("*t")
146+
    -- -- putValue(3, putNumber(batteryMaxInOuts), colors.lightBlue)
147
148-
    hour, minute, second = date_table.hour, date_table.min, date_table.sec
148+
    -- -- Get our input/output/balance battery values
149-
    year, month, day = date_table.year, date_table.month, date_table.day
149+
    batteryCurrentIn = battery.getLastInput()
150
    batteryCurrentOut = battery.getLastOutput()
151-
	timezoneConfig = fileGetLines("config.cfg",1,1)
151+
152-
    timedifflocal = tonumber(string.sub(timezoneConfig[1], 10))
152+
    term.setTextColor(colors.green)
153
    term.setCursorPos(4, 23);
154-
    if hour + timedifflocal > 24 then 
154+
    print(putNumber(batteryCurrentIn))
155-
        if day + 1 > monthDays[month] then
155+
156-
            if month + 1 > 12 then
156+
    term.setTextColor(colors.red)
157-
                year = year + 1
157+
    term.setCursorPos(11, 23);
158-
                month = 1
158+
    print(putNumber(batteryCurrentOut))
159-
                day = 1
159+
160-
                hour = hour + timedifflocal - 24
160+
    -- batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut
161-
            else 
161+
    -- batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red
162-
                month = month + 1
162+
    -- batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or ""
163-
                day = 1
163+
    -- putValue(7, batteryCurrentSign .. putNumber(batteryCurrentBalance), batteryCurrentColor)
164-
                hour = hour + timedifflocal - 24
164+
165
    -- -- Get our statistical values
166
    -- batteryCurrentCharge = battery.getEnergy()
167-
            day = day + 1
167+
    -- putValue(9, putNumber(batteryCurrentCharge), colors.lightBlue)
168-
            hour = hour + timedifflocal - 24
168+
169
    batteryCurrentColor = colors.red
170-
    elseif hour + timedifflocal < 0 then
170+
    batteryCurrentPercentage = battery.getEnergyFilledPercentage() * 100
171-
        if day - 1 < 1 then
171+
    batteryCurrent = battery.getEnergyFilledPercentage()
172-
            if month -1 < 1 then
172+
173-
                year = year - 1
173+
    if batteryCurrentPercentage > 30 then
174-
                month = 12
174+
        batteryCurrentColor = colors.orange
175-
                day = monthDays[12]
175+
176-
                hour = hour + timedifflocal + 24
176+
    if batteryCurrentPercentage > 60 then
177-
            else 
177+
        batteryCurrentColor = colors.green
178-
                month = month - 1
178+
179-
                day = monthDays[month]
179+
    -- putValue(10, string.sub(putNumber(batteryCurrentPercentage), 0, 4) .. "%", batteryCurrentColor)
180-
                hour = hour + timedifflocal + 24
180+
181
    term.setCursorPos(1, 1)
182
    DrawProgress(5, 14, 4, 16, batteryCurrent)
183-
            day = day - 1
183+
184-
            hour = hour + timedifflocal + 24
184+
    term.setCursorPos(1, 1)
185
    term.setTextColor(batteryCurrentColor)
186
    term.setCursorPos(7, 18);
187-
        hour = hour + timedifflocal
187+
    print(string.sub(batteryCurrentPercentage, 0, 5) .. "%")
188
    term.setBackgroundColor(colors.black)
189-
    if long then
189+
190-
        return string.format("%s.%s.%d %s:%s:%s", makeNumber2Digits(day), makeNumber2Digits(month), year, makeNumber2Digits(hour), makeNumber2Digits(minute), makeNumber2Digits(second))
190+
    -- Hey, ring the alarm!
191
    if batteryCurrentPercentage > 10 then
192-
        return string.format("%s.%s.%d %s:%s", makeNumber2Digits(day), makeNumber2Digits(month), year, makeNumber2Digits(hour), makeNumber2Digits(minute))
192+
        alarmIsRinging = false
193
        alarmIsActive = false
194
    end
195
196-
local function getLogs(path, xPos, yPos)
196+
    if batteryCurrentPercentage < 10 and alarmIsActive == false then
197-
	local Logs = fileGetLines(path, fileGetLength(path)-5, fileGetLength(path))
197+
        alarmIsRinging = true
198-
	for i = 1, 6, 1 do
198+
        alarmIsActive = true
199-
		mon.setCursorPos(xPos+2,yPos+1+i)
199+
        alarmCounter = 0
200-
		mon.write(Logs[i])
200+
        redstone.setOutput("back", true)
201-
	end
201+
202
203
    if alarmIsRinging == true then
204-
local function addLog(path, time, text)
204+
        alarmCounter = alarmCounter + 1
205-
	fileAppend(path, "["..time.."]")
205+
        if alarmCounter >= 10 then
206-
	fileAppend(path, text)
206+
            redstone.setOutput("back", false)
207
            alarmIsRinging = false
208
        end
209-
local function round(num, idp)
209+
210-
	local mult = 10^(idp or 0)
210+
211-
	return math.floor(num * mult + 0.5) / mult
211+
    -- Wait 2s until next iteration
212
    os.sleep(1)
213
214-
local function convertRF(rf)
214+
215-
	rfString = ""
215+