--[[ --------------------------------------------------------- Localisation-file has to be as /Apps/Lang/VpC.jsn --]] collectgarbage() ---------------------------------------------------------------------- -- Locals for the application local senso, senid, sid, sparam, senpa, switch local minSpannung = 0 local aktSpannung = 0 local zustand = 0 local sensoLalist = {"..."} local sensoIdlist = {"..."} local sensoPalist = {"..."} local repeatlist = {} local trans12 local wartezeit, startzeit = 0, 0 local zellenzahl = 1 ---------------------------------------------------------------------- -- Read translations local function setLanguage() local lng=system.getLocale() local file = io.readall("Apps/Lang/VpC.jsn") local obj = json.decode(file) if(obj) then trans12 = obj[lng] or obj[obj.default] end end -------------------------------------------------------------------------------- -- Draw telemetry-window local function printMinSpannung() local txth txth = 6 lcd.drawText(0,txth,"min:",FONT_MINI) lcd.drawText(27,0,string.format("%.2fV", minSpannung/zellenzahl),FONT_BIG) lcd.drawText(85,txth,"akt:",FONT_MINI) lcd.drawText(146 - lcd.getTextWidth(FONT_NORMAL,string.format("%.2fV", aktSpannung/zellenzahl)),2,string.format("%.2fV", aktSpannung/zellenzahl),FONT_NORMAL) end -------------------------------------------------------------------------------- -- Read available sensors for user to select local sensors = system.getSensors() for i,sensor in ipairs(sensors) do if (sensor.label ~= "") then table.insert(sensoLalist, string.format("%s", sensor.label)) table.insert(sensoIdlist, string.format("%s", sensor.id)) table.insert(sensoPalist, string.format("%s", sensor.param)) end end ---------------------------------------------------------------------- -- Store settings when changed by user local function sensorChanged(value) senso=value senid=value senpa=value system.pSave("senso",value) system.pSave("senid",value) system.pSave("senpa",value) sid = string.format("%s", sensoIdlist[senid]) sparam = string.format("%s", sensoPalist[senpa]) if (sid == "...") then sid = 0 sparam = 0 end system.pSave("sid", sid) system.pSave("sparam", sparam) end local function switchChanged(value) switch = value system.pSave("switch",value) end local function wartezeitChanged(value) wartezeit = value system.pSave("wartezeit",value) end local function zellenzahlChanged(value) zellenzahl = value system.pSave("zellenzahl",value) end ---------------------------------------------------------------------- -- Draw the main form (Application inteface) local function initForm() -- form.addRow(1) -- form.addLabel({label="--- RC-Thoughts Jeti Tools ---",font=FONT_BIG}) -- Battery 1 form.addRow(1) form.addLabel({label=trans12.appName,font=FONT_BOLD}) form.addRow(2) form.addLabel({label=trans12.selSensor}) form.addSelectbox(sensoLalist,senso,true,sensorChanged) form.addRow(2) form.addLabel({label=trans12.selSwitch}) form.addInputbox(switch, true, switchChanged) form.addRow(2) form.addLabel({label="Wartezeit:"}) form.addIntbox(wartezeit, 0, 10, 0, 0, 1, wartezeitChanged) form.addRow(2) form.addLabel({label="Zellenanzahl:"}) form.addIntbox(zellenzahl, 1, 14, 0, 0, 1, zellenzahlChanged) form.addRow(1) form.addLabel({label="dit71 v."..minSpannungVersion.." ",font=FONT_MINI, alignRight=true}) collectgarbage() end ---------------------------------------------------------------------- -- Runtime functions local function loop() local sense = system.getSensorByID(sid, sparam) local switch = system.getInputsVal(switch) if(sense and sense.valid) then if (sense.value > 1) then aktSpannung = sense.value if (startzeit == 0) then startzeit = system.getTime() end if (minSpannung == 0 and system.getTime() > startzeit + wartezeit) then minSpannung = sense.value end if (switch == 1) then if (zustand < 2) then zustand = 2 minSpannung = sense.value end if (sense.value < minSpannung) then minSpannung = sense.value end else if (zustand == 2) then zustand = 1 end if (zustand == 0 and sense.value < minSpannung) then minSpannung = sense.value end end end end collectgarbage() end ---------------------------------------------------------------------- -- Application initialization local function init() system.registerForm(1,MENU_APPS,trans12.appName,initForm) senso = system.pLoad("senso",0) senid = system.pLoad("senid",0) senpa = system.pLoad("senpa",0) sid = system.pLoad("sid",0) sparam = system.pLoad("sparam",0) switch = system.pLoad("switch") zellenzahl = system.pLoad("zellenzahl",1) system.registerTelemetry(1,trans12.winLabel,1,printMinSpannung) wartezeit = system.pLoad("wartezeit",0) collectgarbage() end ---------------------------------------------------------------------- minSpannungVersion = "1.0" setLanguage() collectgarbage() return {init=init, loop=loop, author="dit71", version=minSpannungVersion, name=trans12.appName}