updated matrix to lib changes
This commit is contained in:
parent
08b8fa6136
commit
8c1401f553
|
@ -1,18 +1,13 @@
|
|||
-- user options
|
||||
local options = {
|
||||
port = 'inductionPort',
|
||||
name = 'Induction Matrix',
|
||||
compact = true,
|
||||
channels = 10,
|
||||
timeout = 15,
|
||||
unit = 'FE'
|
||||
}
|
||||
|
||||
|
||||
-- set system seed
|
||||
math.randomseed(os.time())
|
||||
|
||||
-- system options/components
|
||||
local system = {}
|
||||
|
||||
-- initialize client library
|
||||
dofile('inputClient.lua')
|
||||
|
||||
|
@ -20,19 +15,15 @@ dofile('inputClient.lua')
|
|||
-- this gets a pre-made function to convert joules (input values) to provided options.unit
|
||||
local convert_joules = set_converter(options)
|
||||
|
||||
-- initialize components
|
||||
wait_for_components(options, system, 'inductionPort', 'Induction Matrix')
|
||||
|
||||
|
||||
-- generate induction matrix values
|
||||
function generate_message(buffer)
|
||||
function generate_message(width, component, buffer)
|
||||
-- read induction matrix values
|
||||
local p_raw = system.main.getEnergyFilledPercentage()
|
||||
local c_raw = system.main.getEnergy()
|
||||
local m_raw = system.main.getMaxEnergy()
|
||||
local i_raw = system.main.getLastInput()
|
||||
local o_raw = system.main.getLastOutput()
|
||||
local t_raw = system.main.getTransferCap()
|
||||
local p_raw = component.getEnergyFilledPercentage()
|
||||
local c_raw = component.getEnergy()
|
||||
local m_raw = component.getMaxEnergy()
|
||||
local i_raw = component.getLastInput()
|
||||
local o_raw = component.getLastOutput()
|
||||
local t_raw = component.getTransferCap()
|
||||
|
||||
-- convert raw values from joules to specified options.unit
|
||||
local c_conv = convert_joules(c_raw)
|
||||
|
@ -42,56 +33,24 @@ function generate_message(buffer)
|
|||
local t_conv = convert_joules(t_raw)
|
||||
|
||||
-- format and align fill values
|
||||
message_aligned(buffer, 'Fill....:', format_percent(options, p_raw), system.width)
|
||||
message_aligned(buffer, 'Fill....:', format_energy(options, c_conv), system.width)
|
||||
message_aligned(buffer, 'Fill....:', format_percent(options, p_raw), width)
|
||||
message_aligned(buffer, 'Fill....:', format_energy(options, c_conv), width)
|
||||
|
||||
-- format and align capacity
|
||||
message(buffer, '\n')
|
||||
message_aligned(buffer, 'Capacity:', format_energy(options, m_conv), system.width)
|
||||
message_aligned(buffer, 'Capacity:', format_energy(options, m_conv), width)
|
||||
|
||||
-- format and align i/o values
|
||||
message(buffer, '\n') message(buffer, '\n')
|
||||
message_aligned(buffer, 'Input...:', format_energy(options, i_conv, true), system.width)
|
||||
message_aligned(buffer, 'Output..:', format_energy(options, o_conv, true), system.width)
|
||||
message_aligned(buffer, 'Input...:', format_energy(options, i_conv, true), width)
|
||||
message_aligned(buffer, 'Output..:', format_energy(options, o_conv, true), width)
|
||||
|
||||
-- format and align transfer
|
||||
message(buffer, '\n')
|
||||
message_aligned(buffer, 'Transfer:', format_energy(options, t_conv, true), system.width)
|
||||
message_aligned(buffer, 'Transfer:', format_energy(options, t_conv, true), width)
|
||||
end
|
||||
|
||||
function send_info()
|
||||
-- buffer for messages
|
||||
local buffer = {}
|
||||
-- generate messages in buffer
|
||||
generate_message(buffer)
|
||||
-- transmit messages in form of buffer
|
||||
transmit_messages(options, system, buffer)
|
||||
end
|
||||
|
||||
function event_listener()
|
||||
while true do
|
||||
local _, _, senderChannel, _, message, _ = os.pullEvent('modem_message')
|
||||
|
||||
-- respond to corresponding message only
|
||||
if senderChannel == system.channel and message == 'print' then
|
||||
-- send message main display message
|
||||
send_info()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- main program
|
||||
function main()
|
||||
-- permanent runtime
|
||||
while true do
|
||||
-- reset terminal
|
||||
term.clear()
|
||||
-- run while all components are detected
|
||||
while scan_components('inductionPort').success and (not system.timeout) do
|
||||
event_listener()
|
||||
end
|
||||
-- rescan components
|
||||
wait_for_components(options, system, 'inductionPort', 'Induction Matrix')
|
||||
end
|
||||
end
|
||||
main()
|
||||
-- run main program
|
||||
run_client(options, {
|
||||
print = generate_message
|
||||
})
|
Loading…
Reference in New Issue
Block a user