collectgarbage() local triggerSwitch local triggerSwitchState=0 local inputs local inputLabels local columns={{},{},{},{},{}} local function printCell(x,y,w,text,format) lcd.drawText(x+(w+1-lcd.getTextWidth(format,text))/2,y,text,format) --lcd.drawRectangle(x,y,w+1) return x+w end local function printRow(row,text,format) local x,y=-1,-1+row*18 for i=1,5 do x=printCell(x,y,64,text[i],format) end lcd.drawLine(0,y,320,y) end local function printTable() local text={"-","-","-","-","-"} for i=1,5 do if inputs[i]>0 then text[i]=inputLabels[inputs[i]] end end printRow(0,text,FONT_BOLD) for i=1,#columns[1] do for j=1,5 do if columns[j][i]>1 then text[j]="-" else text[j]=string.format("%d%%",columns[j][i]*100) end end printRow(i,text,FONT_NORMAL) end end local function initInputs() inputLabels={"..."} for p=1,10 do table.insert(inputLabels,"P"..p) end for o=1,24 do table.insert(inputLabels,"O"..o) end end local function createForm(formID) form.addRow(2) form.addLabel({label="Trigger Switch"}) form.addInputbox(triggerSwitch,true,function(input) triggerSwitch=input system.pSave("triggerSwitch",triggerSwitch) end) form.addLabel() form.addLabel({label="Input/Output Columns"}) form.addRow(5) for i=1,5 do form.addSelectbox(inputLabels,inputs[i],true,function(index) inputs[i]=index system.pSave("inputs",inputs) end) end end local function init(code) triggerSwitch=system.pLoad("triggerSwitch") if triggerSwitch then triggerSwitchState=system.getInputsVal(triggerSwitch) end inputs=system.pLoad("inputs",{0,0,0,0,0}) initInputs() system.registerTelemetry(1,"Input/Output Logger",4,printTable) system.registerForm(1,MENU_APPS,"Input/Output Logger",createForm) collectgarbage() end local function loop() if not triggerSwitch then return end local triggerSwitchStateOld=triggerSwitchState triggerSwitchState=system.getInputsVal(triggerSwitch) if triggerSwitchState==triggerSwitchStateOld then return end for i=1,5 do local inputValue=2 if inputs[i]>0 then inputValue=system.getInputs(inputLabels[inputs[i]]) end table.insert(columns[i],1,inputValue) end if #columns[1]==9 then for i=1,5 do table.remove(columns[i],9) end end collectgarbage() end collectgarbage() return {init=init,loop=loop,author="LD",version="1.0",name="Input/Output Logger"}