Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require('component')
- local thread = require('thread')
- local event = require('event')
- local sides = require('sides')
- local gpu = component.gpu
- local CheckInterval = 1
- local updateGuiInterval = 1
- function main()
- init()
- init_gui()
- local resetBColor, resetFColor = gpu.getBackground(), gpu.getForeground()
- local background = {}
- table.insert(background, event.listen("key_up", function (key, address, char)
- if char == string.byte('q') then
- event.push('exit')
- end
- end))
- table.insert(background, event.timer(CheckInterval, failFast(check_gt), math.huge))
- table.insert(background, event.timer(updateGuiInterval, failFast(update_gui), math.huge))
- local _, err = event.pull("exit")
- for _, b in ipairs(background) do
- if type(b) == 'table' and b.kill then
- b:kill()
- else
- event.cancel(b)
- end
- end
- gpu.setBackground(resetBColor)
- gpu.setForeground(resetFColor)
- if err then
- io.stderr:write(err)
- os.exit(1)
- else
- os.exit(0)
- end
- end
- function failFast(fn)
- return function(...)
- local res = table.pack(xpcall(fn, debug.traceback, ...))
- if not res[1] then
- event.push('exit', res[2])
- end
- return table.unpack(res, 2)
- end
- end
- function errorExit(...)
- out(...)
- event.push('exit')
- end
- ----------------------- DEBUG ---------------------------
- function object_to_string(level, object) local function get_tabs(num) local msg = "" for i = 0, num do msg = msg .. " " end return msg end if level == nil then level = 0 end local message = " " if object == nil then message = message .. "nil" elseif type(object) == "boolean" or type(object) == "number" then message = message .. tostring(object) end if type(object) == "string" then message = message..object end if type(object) == "function" then message = message.."\"__function\"" end
- if type(object) == "table" then if level <= d_limit then message = message .. "\n" .. get_tabs(level) .. "{\n" for key, next_object in pairs(object) do message = message .. get_tabs(level + 1) .. "\"" .. key .. "\"" .. ":" .. object_to_string(level + 1, next_object) .. ",\n"; end message = message .. get_tabs(level) .. "}" else message = message .. "\"" .. "__table" .. "\"" end end return message end function rec_obj_to_string(object, ...) arg = {...}
- if #arg > 0 then return object_to_string(0, object) .. rec_obj_to_string(...) else return object_to_string(0, object) end end function out(...) local message = rec_obj_to_string(...) print(message) end
- ----------------------- LOOP ---------------------------
- function check_gt()
- si=component.gt_machine.getSensorInformation()[5]
- clean=tonumber(string.sub(si, string.find(si,":",10)+5, string.find(si,"%.")-1))
- if clean == 100 then
- if rio then rio.setOutput({[0] = 15, 15, 15, 15, 15, 15}) end
- else
- if rio then rio.setOutput({[0] = 0, 0, 0, 0, 0, 0}) end
- end
- end
- -------------------- SUPPORTED FUNCTION -----------------------
- function init()
- rio = link_component("redstone")
- mcr = link_component("multimachine.cleanroom")
- end
- function link_component(comp_name)
- components = component.list(comp_name)
- ret_comp = nil
- for addr, name in pairs(components) do
- if ret_comp == nil then
- ret_comp = component.proxy(addr)
- print("Link component " .. name .. " to address " .. ret_comp.address)
- else
- print("Warning: More then one component " .. name .. " found. Used: " .. ret_comp.address)
- end
- end
- return ret_comp
- end
- -------------------- GUI FUNCTION -----------------------
- function clear_screen()
- local x, y = gpu.getResolution()
- gpu.fill(1, 1, x, y, " ")
- end
- function update_gui()
- clean_i=tostring(clean).."% "
- gpu.set(1, 2, clean_i)
- end
- function init_gui()
- gpu.setResolution(8, 2)
- clear_screen()
- --gpu.set(1, 1, "Чистота:")
- update_gui()
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment