--[[ ---------------------------------------------------------------------------- App for F5B Distance task climb advice and 'set' recording ---------------------------------------------------------------------------- MIT License Copyright (c) 2021 R.Whitehead - incorportaing ideas from C.parish and J.Mouris. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. v2.1 model name added to window 2 v2.2 Time of climb out (11th climb) added to window 2 v2.3 Cumulatives set times added in place of 11th climb v2.4 Tidy up code ---------------------------------------------------------------------]] local switch local reset local launch = 0 local launchTime = 0 --system.getTimeCounter() local launchTime2 = 0 --system.getTime() local val = 0 -- motor switch ON/OFF local refTime, diffTime, runTime = 0, 0, 0 local task = 0 local climb = 1 local mstatus = -1 local playn1, playn2 = 0, 0 local mOn, mOff, mRun, mTot = 0, 0, 0, 0 local vert = 0 local sets = {} local setTime, setS, setI, sTot = 0, 0, 0, 0 local dt = system.getDateTime() ---------------------------------------------------------------- -- Initial set up form -- set up motor and reset switches local function initForm() form.addRow(2) form.addLabel({label="Motor-Schalter"}) form.addInputbox(switch, true, function(value) switch=value;system.pSave("switch",value); end ) form.addRow(2) form.addLabel({label="Reset-Schalter"}) form.addInputbox(reset, true, function(valuea) reset=valuea;system.pSave("reset",valuea); end) -- print notes form.addRow(1) form.addLabel({label="Es können zwei Telemetriefenster angezeigt werden :-", font=FONT_MINI}) form.addRow(1) form.addLabel({label=" 1) Kleines Fenster zeigt einfach 'Aufstiege und Zeiten'.", font=FONT_MINI}) form.addRow(1) form.addLabel({label=" 2) Großes Fenster erzeugt Datensatz von 'Sets'.", font=FONT_MINI}) form.addRow(1) form.addLabel({label="Screenshot zum Speichern verwenden (2)", font=FONT_MINI}) form.addSpacer(100,10) form.addRow(1) form.addLabel({label="Entwickelt von RJFW - v"..F5B200Version.." ", font=FONT_MINI, alignRight=true}) end -------------------------------------------- local function loop() local val = system.getInputsVal(switch) local restart = system.getInputsVal(reset) -- resets values for restarting if (restart) then --1 if (restart >= 1 ) then -- 2 task = 0 climb = 1 launch = 0 launchTime, launchTime2 = 0, 0 diffTime, refTime, runTime = 0, 0, 0 playn1,play2 = 0, 0 mOn, mOff, mRun, mTot = 0, 0, 0, 0 setTime = 0 setS, setI, sTot = 0, 0, 0 dt = system.getDateTime() else ------------------------------------------------------------------------- if(val) then --3 main working 'IF' loop -- If first Motor On get start time and set launch indicator for repeat process if launch < 1 and val > 0 then launchTime = system.getTimeCounter() --microsecs for motor & set times launchTime2 = system.getTime() --secs '200' and 'ahead' times dt = system.getDateTime() launch = 1 mOn = launchTime setS = launchTime --set start values for motor and set times setI = -1 end -- Update run time each loop if (launch >= 1 ) then runTime = (system.getTime() - launchTime2) end -- calculate motor runs and set times if val > mstatus then mOn = system.getTimeCounter() -- motor just turned ON setTime = mOn - setS setS = mOn -- calc set time and reset start of set sTot = setTime + sTot -- calc cumulative set time if setI >9 then setI = 10 else setI = setI + 1 end elseif mstatus > val then mOff = system.getTimeCounter() -- motor just turned OFF mRun = mOff - mOn mTot = mTot + mRun -- calc motor run and cumulative run end if (task <= 10 ) then --4 -- stops process after climb 10 if (runTime <= 210) then --5 -- stops process : 210 secs (allows last set end after 200) if(val > 0 ) --6 i.e motor just turned ON then --6 -- sets and resets basic values as process runs refTime = (20 * climb) diffTime = refTime - runTime mstatus = val -- mstatus = 1 when motor ON else --6 diffTime = refTime - runTime if mstatus > val then -- i.e motor just turned OFF task = task + 1 climb = climb + 1 mstatus = -1 -- mstatus = -1 when motor OFF end -- Voice output of times ahead - but not for last 10 secs of distance task if diffTime >10 then playn2 = 8 end if diffTime < 10 and diffTime > 0 and mstatus < 0 and runTime < 190 then if playn2 == diffTime then system.playNumber (diffTime , 0 ) playn2 = diffTime - 1 end end end -- 6 --Voice output of climb no. (control = playn1) if required when not using Jeti lap timer --[[ if task > 0 and mstatus > 0 and playn1 <= task then playn1 = task + 1 system.playNumber (playn1 , 0 ) end ]] end -- 5 end -- 4 end -- 3 main working IF loop --------------------------------------------------------------- end -- 2 of restart end -- 1 of restart ---------------- end loop -------------------------------------- -- sets up data for the climb data display sets[task].mRun = mRun/1000 sets[task].mTot = mTot/1000 sets[task].setTime = setTime/1000 sets[task].sTot = sTot/1000 end -- add values to telemetry 1 window local function printDistance() lcd.drawNumber(10, 5, runTime, FONT_BOLD) lcd.drawText(60, 5, "- ", FONT_BOLD) lcd.drawNumber(70, 5, diffTime, FONT_BOLD) lcd.drawText (110, 5, task, FONT_BOLD) end -- add values to telemetry 2 window local function printData() lcd.drawText(10, 0, "1 - ", FONT_MINI) lcd.drawText(10, 14, "2 - ", FONT_MINI) lcd.drawText(10, 28, "3 - ", FONT_MINI) lcd.drawText(10, 42, "4 - ", FONT_MINI) lcd.drawText(10, 56, "5 - ", FONT_MINI) lcd.drawText(10, 70, "6 - ", FONT_MINI) lcd.drawText(10, 84, "7 - ", FONT_MINI) lcd.drawText(10, 98, "8 - ", FONT_MINI) lcd.drawText(10, 112, "9 - ", FONT_MINI) lcd.drawText(4, 126, "10 - ", FONT_MINI) lcd.drawText (180, 145, system.getProperty("Model"), FONT_MINI) lcd.drawText (80,145,(string.format("%d-%02d-%02d",dt.year, dt.mon, dt.day)), FONT_MINI) lcd.drawText (30,145,(string.format(" %d:%02d",dt.hour, dt.min)), FONT_MINI) lcd.drawLine(5,70,215,70, 0) lcd.drawLine(95,140,120,140, 0) lcd.drawLine(180,140,215,140, 0) --creates the printed motor run times and set times data log for i = 1, setI do if setI < 12 then vert = -14 + (14*i) lcd.drawText(55, vert, (string.format("%.1f", sets[i].mRun)), FONT_MINI) lcd.drawText(100, vert, (string.format("%.1f", sets[i].mTot)), FONT_MINI) lcd.drawText(145, vert, (string.format("%.1f", sets[i].setTime)), FONT_MINI) lcd.drawText(190, vert, (string.format("%.1f", sets[i].sTot)), FONT_MINI) end end end local function init() switch = system.pLoad("switch") reset = system.pLoad("reset") system.registerTelemetry(1,"F5B 200 - Voraus - Steig",1,printDistance) system.registerTelemetry(2,"Steig - Mot - Kum Mot - Satz - Kum Satz",4,printData) system.registerForm(1,MENU_APPS,"F5B 200",initForm) for i=0, 13 do sets[i] = { mRun = 0, mTot = 0, setTime = 0, sTot = 0} end end --- F5B200Version = "2.4_D" return {init=init, loop=loop, author="RJFW", version=F5B200Version, name="F5B 200",}