local timePlayed = false local Schalter1Played = false local Schalter2Played = false local sensorsX = 0 local currentCap = 0 local DeltaCap = 100 local AnzeigenCap = 0 --local Schalter1 --local Schalter2 local Schalter1 = nil local Schalter2 = nil local DeltaWertAusweisen --------------------------------------------------------------------------------- local function isSwitch(value) if (value) then local info = system.getSwitchInfo(value) return info and info.assigned end end ---------------------------------------------- local function initForm1() local addRow, addLabel = form.addRow, form.addLabel local addInputbox, addSpacer, addIntbox = form.addInputbox, form.addSpacer, form.addIntbox addSpacer(318, 16) addRow(2) addLabel({label= "Schalter 1 zuweisen", width=220}) addInputbox(Schalter1, true, function(value) if (not isSwitch(value)) then value = nil end Schalter1 = value system.pSave("Schalter1", Schalter1) end) addRow(2) addLabel({label= "Schalter 2 zuweisen", width=220}) addInputbox(Schalter2, true, function(value) if (not isSwitch(value)) then value = nil end Schalter2 = value system.pSave("Schalter2", Schalter2) end) addRow(2) addLabel({label= "Delta alle X mAh ausweisen", width=220}) addIntbox(DeltaWertAusweisen,100,900,100,0,100, function(value) DeltaWertAusweisen = value system.pSave("DeltaWertAusweisen", DeltaWertAusweisen) end) collectgarbage() end ------------------------------------------------- local function SensorAusgeben() -- aus LUA API-Dokumentation Musteranwendung local sensors = system.getSensors() for i, sensor in ipairs(sensors) do if (sensor.type == 5) then if (sensor.decimals == 0) then -- Time print (string.format("%s = %d:%02d:%02d", sensor.label, sensor.valHour, sensor.valMin, sensor.valSec)) else -- Date print (string.format("%s = %d-%02d-%02d", sensor.label, sensor.valYear, sensor.valMonth, sensor.valDay)) end elseif (sensor.type == 9) then -- GPS coordinates --local nesw = {"N", "E", "S", "W"} --local minutes = ((sensor.valGPS & 0xFFFF) * 0.001) --local degs = ((sensor.valGPS >> 16) & 0xFF) --print (string.format("%s = %d° %f' %s", sensor.label, degs, minutes, nesw[sensor.decimals+1])) print ("GPS gefunden") else if (sensor.param == 0) then -- Sensor label print (string.format("%s:", sensor.label)) else -- Other numeric value print (string.format("%s = %.1f %s (min: %.1f, max: %.1f)", sensor.label, sensor.value, sensor.unit, sensor.min, sensor.max)) end end end collectgarbage() end -------------------------------------------------------------------------------- local function loop() local time = system.getDateTime() local Schalter1gedrueckt = system.getInputsVal(Schalter1) local Schalter2gedrueckt = system.getInputsVal(Schalter2) if (Schalter1gedrueckt == 1) then if(not system.isPlayback()) then if(not Schalter1Played) then system.playNumber (time.hour, 0) system.playFile("uhr.wav") system.playNumber (time.min, 0) Schalter1Played = true else Schalter1Played = false SensorAusgeben() end end end if(sensorsX ~= 0) then local sensors = system.getSensors() local sensor1 = sensors[sensorsX] local DeltaCap = system.pLoad("DeltaWertAusweisen",100) if(math.abs(sensor1.value - currentCap) >= DeltaCap) then AnzeigenCap = ((math.floor( sensor1.value / DeltaCap) * DeltaCap) / 1000) system.playNumber (AnzeigenCap, 1, "Ah", "Capacity") currentCap = sensor1.value print ("Delta ermittelt: ", AnzeigenCap, sensor1.value, DeltaCap) end if (Schalter2gedrueckt == 1) then if(not Schalter2Played) then AnzeigenCap = ((math.floor( sensor1.value / DeltaCap) * DeltaCap) / 1000) system.playNumber (AnzeigenCap, 1, "Ah", "Capacity") print ("Delta ermittelt: ", AnzeigenCap, sensor1.value, DeltaCap) Schalter2Played = true end else Schalter2Played = false end end if(time.min % 5 == 0) then if(not timePlayed) then ---system.playNumber (time.hour, 0, "h") ---system.playNumber (time.min, 0, "min") system.playNumber (time.hour, 0) system.playFile("uhr.wav") system.playNumber (time.min, 0) timePlayed = true end else if(timePlayed) then timePlayed = false end end collectgarbage() end --------------------------------------------------------------------------------- local function init() local pLoad, registerForm = system.pLoad, system.registerForm registerForm(1, MENU_APPS, "MB Werte ansagen lassen", initForm1) Schalter1 = pLoad("Schalter1", nil) Schalter2 = pLoad("Schalter2", nil) DeltaWertAusweisen = pLoad("DeltaWertAusweisen", 100) local time = system.getDateTime() system.playNumber (time.hour, 0, "h") system.playNumber (time.min, 0, "min") print ("gestartet") local sensors = system.getSensors() if(sensors == nil) then print ("Keine Sensor angeschlossen") else for i, sensor in ipairs(sensors) do if(sensor.type == 4) then if (sensor.label == "Cap.") then sensorsX = i print ("Einmalig: ", sensorsX) currentCap = sensor.value break end end end end collectgarbage() end -------------------------------------------------------------------------------- return {init=init, loop=loop, author="Katharina", version="1.1", name="Kathis_App4"}