Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Default settings, do not change
- local options = {
- -- Unique identifier for this matrix on rednet, required for rednet functionality
- rednet_identifier = '',
- -- Energy type being displayed (J, FE)
- energy_type = 'FE',
- -- Update frequency, in seconds
- update_frequency = 1,
- -- Text scale on the monitor
- text_scale = 1,
- -- Output debug data to the computer's internal display
- debug = true,
- }
- --------------------------------------------------
- --- Helper functions
- --------------------------------------------------
- --- Holds the current buffer of data being printed
- local machine_term = term.current()
- local print_buffer = {}
- --- Writes data to the output monitor buffer
- function print_r (text)
- table.insert(print_buffer, text)
- end
- --- Writes formatted data to the output monitor buffer
- function print_f (format, ...)
- print_r(string.format(format, ...))
- end
- --- Writes the buffer into the output monitor
- function print_flush ()
- if monitor then
- -- Redirects writes to monitor (if any)
- if monitor then
- term.redirect(monitor)
- end
- -- Clears terminal
- term.clear()
- term.setCursorPos(1, 1)
- -- Writes new data
- print(table.concat(print_buffer or {}, '\n'))
- -- Redirects writes back to computer (if using monitor)
- if monitor then
- term.redirect(machine_term)
- end
- end
- -- Clears buffer
- print_buffer = {}
- end
- --- Writes debug info to the machine
- function debug (...)
- if options.debug then
- print(...)
- end
- end
- function print_drawer_info (drawer_info)
- print_r('Cake Production Control')
- print_r('------------------')
- print_r('')
- print_f('Amount : %s', drawer_info.amount)
- print_f('Production : %s', drawer_info.Cake_status)
- end
- -- Detects peripherals
- monitor = peripheral.find('monitor')
- if monitor then
- debug('Monitor detected, enabling output!')
- monitor.setTextScale(options.text_scale)
- else
- debug('No monitor detected, entering headless mode!')
- -- Makes sure we have a connected modem
- if not modem then
- error('No monitor or modem detected, cannot enter headless mode!')
- end
- end
- --------------------------------------------------
- --- Main runtime
- --------------------------------------------------
- debug('Entering main loop...')
- while true do
- local status, err = pcall(function ()
- -- Attempts to auto-detect missing Drawer
- if not drawer then
- drawer = peripheral.find('functionalstorage:oak_1')
- -- Checks if it worked
- if not drawer then
- error('Drawer not connected!')
- end
- end
- local item = drawer.getItemDetail(1)
- local Cake_status_cal
- --- This is our main information
- local drawer_info = {
- amount = item.count,
- Cake_status = Cake_status_cal
- }
- if item.count < 1000 then
- redstone.setOutput("left", false)
- Cake_status_cal = "Production ongoing"
- else
- redstone.setOutput("left", true)
- Cake_status_cal = "Drawer currently full"
- end
- -- Prints the drawer information
- print_drawer_info(drawer_info)
- end)
- -- Checks for errors (might be disconnected)
- if not status then
- -- Clears buffer first
- print_buffer = {}
- -- Shows error message
- print_r('Error reading data')
- print_r('Check connections.')
- print_r('------------------')
- print_r(err)
- end
- -- Outputs text to screen
- print_flush()
- -- Waits for next cycle
- os.sleep(options.update_frequency)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement