--[[ --------------------------------------------------------- Flight book Flight book is a simple flight counter that uses any switch. When switch have been active for set time flight counter-value is added with one. ---------------------------------------------------------------------------- MIT License Hiermit wird unentgeltlich jeder Person, die eine Kopie der Software und der zugehörigen Dokumentationen (die "Software") erhält, die Erlaubnis erteilt, sie uneingeschränkt zu nutzen, inklusive und ohne Ausnahme mit dem Recht, sie zu verwenden, zu kopieren, zu verändern, zusammenzufügen, zu veröffentlichen, zu verbreiten, zu unterlizenzieren und/oder zu verkaufen, und Personen, denen diese Software überlassen wird, diese Rechte zu verschaffen, unter den folgenden Bedingungen: Der obige Urheberrechtsvermerk und dieser Erlaubnisvermerk sind in allen Kopien oder Teilkopien der Software beizulegen. DIE SOFTWARE WIRD OHNE JEDE AUSDRÜCKLICHE ODER IMPLIZIERTE GARANTIE BEREITGESTELLT, EINSCHLIEßLICH DER GARANTIE ZUR BENUTZUNG FÜR DEN VORGESEHENEN ODER EINEM BESTIMMTEN ZWECK SOWIE JEGLICHER RECHTSVERLETZUNG, JEDOCH NICHT DARAUF BESCHRÄNKT. IN KEINEM FALL SIND DIE AUTOREN ODER COPYRIGHTINHABER FÜR JEGLICHEN SCHADEN ODER SONSTIGE ANSPRÜCHE HAFTBAR ZU MACHEN, OB INFOLGE DER ERFÜLLUNG EINES VERTRAGES, EINES DELIKTES ODER ANDERS IM ZUSAMMENHANG MIT DER SOFTWARE ODER SONSTIGER VERWENDUNG DER SOFTWARE ENTSTANDEN. ---------------------------------------------------------------------------- V1.0 initial release --]] --]] -------------------------------------------------------------------------------- -- Locals for application local flightCount, actTime, countSet, Tagescount, counterSw = 0, 1, 0, 0 local startTime, curTime, timeSet = 0, 0, 0 local Flugzeit, FlugzeitGes, FlugzeitGesmin = 0, 0 ,0 local trans21 -------------------------------------------------------------------------------- -- Read and set translations local function setLanguage() local lng=system.getLocale() local file = io.readall("Apps/Lang/Flightbook.jsn") local obj = json.decode(file) if(obj) then trans21 = obj[lng] or obj[obj.default] end end -------------------------------------------------------------------------------- -- Draw telemetry screen for main display local function printCounter1() lcd.drawText(10,5,string.format("%.0f", flightCount),FONT_BIG) lcd.drawText(135 - lcd.getTextWidth(FONT_BIG,string.format("%.0f", Tagescount)),5,string.format("%.0f", Tagescount),FONT_BIG) local Std = math.floor(FlugzeitGes / 3600) local MinGes = math.floor((FlugzeitGes - Std * 3600) / 60) local Min = math.floor(Flugzeit / 60) local Sek = Flugzeit - Min * 60 local formatFlugzeit = string.format("%3dm", Min) .. " : " .. string.format("%02ds", Sek) lcd.drawText(0,40,string.format("%3dh", Std) .. " : " .. string.format("%02dm", MinGes),FONT_NORMAL) lcd.drawText(145 - lcd.getTextWidth(FONT_NORMAL,formatFlugzeit),40,formatFlugzeit,FONT_NORMAL) end ---------------------------------------------------------------------- -- Actions when settings changed local function counterSwChanged(value) local pSave = system.pSave counterSw = value pSave("counterSw", value) end local function actTimeChanged(value) local pSave = system.pSave actTime = value pSave("actTime", value) end local function flightCountChanged(value) local pSave = system.pSave flightCount = value pSave("flightCount", value) end local function FlugzeitGesChanged(value) local pSave = system.pSave FlugzeitGes = value * 60 pSave("FlugzeitGes", FlugzeitGes) end -------------------------------------------------------------------------------- -- Draw the main form (Application inteface) local function initForm() local form, addRow, addLabel = form, form.addRow ,form.addLabel local addIntbox, addCheckbox = form.addIntbox, form.addCheckbox local addSelectbox, addInputbox = form.addSelectbox, form.addInputbox addRow(1) addLabel({label="--- RC-Thoughts Jeti Tools ---",font=FONT_BIG}) addRow(2) addLabel({label=trans21.swCount, width=220}) addInputbox(counterSw, true, counterSwChanged) addRow(2) addLabel({label=trans21.actTime, width=220}) addIntbox(actTime, 1, 600, 0, 0, 1, actTimeChanged) addRow(2) addLabel({label=trans21.curCount, width=220}) addIntbox(flightCount, -0, 10000, 0, 0, 1, flightCountChanged) addRow(2) addLabel({label=trans21.totFlightTime, width=220}) FlugzeitGesmin = math.floor(FlugzeitGes / 60) addIntbox(FlugzeitGesmin, -0, 60000, 0, 0, 1, FlugzeitGesChanged) addRow(1) addLabel({label="Powered by RC-Thoughts.com - v."..flightCounterVersion.." ", font=FONT_MINI, alignRight=true}) collectgarbage() end -------------------------------------------------------------------------------- local function loop() local switchState = system.getInputsVal(counterSw) curTime = system.getTime() if(counterSw and switchState == 1) then if(timeSet == 0) then startTime = system.getTime() timeSet = 1 end Flugzeit = curTime - startTime if (Flugzeit > actTime and countSet == 0) then Tagescount = Tagescount + 1 flightCount = flightCount + 1 system.pSave("flightCount", flightCount) system.pSave("tagescount", Tagescount) countSet = 1 end else if countSet == 1 then FlugzeitGes = FlugzeitGes + Flugzeit system.pSave("FlugzeitGes", FlugzeitGes) end countSet = 0 timeSet = 0 end collectgarbage() end -------------------------------------------------------------------------------- local function init() local pLoad, registerForm = system.pLoad, system.registerForm counterSw = pLoad("counterSw") actTime = pLoad("actTime", 1) flightCount = pLoad("flightCount", 0) Tagescount = pLoad("tagescount", 0) local Datum = pLoad("Datum", 0) local aktTag = math.floor(system.getTime() / 86400) if Datum < aktTag then Tagescount = 0 system.pSave("Datum", aktTag) system.pSave("tagescount", 0) end FlugzeitGes = pLoad("FlugzeitGes", 0) FlugzeitGesmin = math.floor(FlugzeitGes / 60) counterLabel = pLoad("cntLb1",trans21.appName) system.registerTelemetry(1,"total Flight book today",0,printCounter1) registerForm(1, MENU_APPS, trans21.appName, initForm) collectgarbage() end -------------------------------------------------------------------------------- flightCounterVersion = "1.0" setLanguage() collectgarbage() return {init=init, loop=loop, author="dit71", version=flightCounterVersion, name=trans21.appName}