local name="Autopilot" local b,c,d,e = 0, 0, 0, 0; local f="" local g="" local h=1; local i; local j=1; local k=0; local l; local delay; local lastInput; local function delayChanged(value) delay=value system.pSave("delay",value) end local function m(n) form.addLabel({label="Lehrer Schüler System",font=2}) form.addRow(2) form.addLabel({label="Audio Lehrer"}) form.addAudioFilebox(f,function(o) f=o; system.pSave("fileT",o) end) form.addRow(2) form.addLabel({label="Audio Schüler"}) form.addAudioFilebox(g,function(o) g=o; system.pSave("fileS",o) end) form.addRow(2) form.addLabel({label="Switch"}) form.addInputbox(i,true,function(o) i=o; system.pSave("switch",o) end) form.addRow(2) form.addLabel({label="Verzögerung (0.X s)"}) form.addIntbox(delay,1,100,3,0,1,delayChanged) end; local function p(q) end; local function r() form.setButton(1,k>0 and "An" or "Aus",ENABLED) end; local function s() f=system.pLoad("fileT","") g=system.pLoad("fileS","") i=system.pLoad("switch") delay=system.pLoad("delay", 3) system.registerForm(1,MENU_ADVANCED,name,m,p,r) l=system.registerControl(1,"Trainer Switch","T/S") end; local function t() local u=system.getInputsVal(i) if u and u>0 and j==0 then j=1; if system.getProperty("WirelessMode")~="Teacher" then system.setProperty("WirelessMode","Teacher") system.playFile(f,AUDIO_IMMEDIATE) else b,c,d,e=system.getInputs("P1","P2","P3","P4") k=1; system.playFile(g,AUDIO_IMMEDIATE) end elseif u and u<=0 then j=0 end; if k>0 then local v,w,x,y=system.getInputs("P1","P2","P3","P4") if math.abs(v-b)>0.1 or math.abs(w-c)>0.1 or math.abs(x-d)>0.1 or math.abs(y-e)>0.1 then k=0; system.playFile(f,AUDIO_IMMEDIATE) end else local v,w,x,y=system.getInputs("P1","P2","P3","P4") if math.abs(v-b)>0.1 or math.abs(w-c)>0.1 or math.abs(x-d)>0.1 or math.abs(y-e)>0.1 then lastInput=system.getTimeCounter() end if lastInput and system.getTimeCounter() - lastInput >= delay*100 then k=1 lastInput = nil system.playFile(g,AUDIO_IMMEDIATE) end end if l then system.setControl(l,k,0) end end; return{init=s,loop=t,author="JETI model",version="1.00",name=name}