--[[ 8.11.2016 V0.02 22.12.2016 Auch für DC-16 geeignet Latch-Switch erzeugt einen Apps Geber (Schalter) mit Bezeichner LSw welcher mit je einem Sprachkommando oder Taster ein- bzw. ausgeschaltet werden kann. Variable Zuordnung der Sprachkommandos bzw. Taster im Setup . Zuordnung und letzter Zustand von LSw werden im jeweiligen Modellspeicher gespeichert. ]]-- -- Assigned switches as a local variable local switch1, switch2, state, state_old -------------------------------------------------------------------------------- -- Store settings when changed by user local function Switch1Changed(value) switch1 = value system.pSave("switch1", switch1) end local function Switch2Changed(value) switch2 = value system.pSave("switch2", switch2) end -------------------------------------------------------------------------------- -- Form initialization for buttom/switch select local function initForm() form.addRow(2) form.addLabel({label="Selected switch 1",width=250}) form.addInputbox(switch1, true, Switch1Changed) form.addRow(2) form.addLabel({label="Selected switch 2",width=250}) form.addInputbox(switch2, true, Switch2Changed) end -------------------------------------------------------------------------------- -- Command control local function commands() local val1 = system.getInputsVal(switch1) local val2 = system.getInputsVal(switch2) if val1 == 1 then state = 1 end if val2 == 1 then state = -1 end if state_old ~= state then system.pSave("state", state) state_old = state end if ctrlIdx then system.setControl(1, state, 0, 0) end end -------------------------------------------------------------------------------- -- Print the value if the switch is assigned local function printForm() commands() lcd.drawText(10, 50, string.format("Status LSw : %s", string.format("%3d", state)),FONT_MAXI) end -------------------------------------------------------------------------------- -- Runtime functions, read sensor, calculate values all times local function loop() commands() end ------------------------------------------------------------------------------- -- Application initialization local function init() switch1 = system.pLoad("switch1") switch2 = system.pLoad("switch2") state = system.pLoad("state", -1) system.registerForm(1,MENU_APPS,"Latch Switch Setup",initForm, nil,printForm) ctrlIdx = system.registerControl(1, "Latch-Switch","LSw") end ------------------------------------------------------------------------------- return {init=init, loop=loop, author="user", version="0.02", name= "LatchSw"}