local timePlayed = false local Schalter1Played = false local Schalter2Played = false local currentCap = 0 local DeltaCap = 100 local AnzeigenCap = 0 local Schalter1 = nil local Schalter2 = nil local DeltaWertAusweisen local SensorIndexAusgewaehlt = 1 local SensorIdAusgewaehlt = nil local ParamUsed = 0 --------------------------------------------------------------------------------- local function isSwitch(value) if (value) then local info = system.getSwitchInfo(value) return info and info.assigned end end --------------------------------------------------------------------------------- local function readSensors() local sensors = system.getSensors() local outSensors = {} local sensorIds = {} local paramList = {} local counter = 2 outSensors[1] = "--Kein Sensor--" for i, sensor in ipairs(sensors) do if(string.match(sensor.unit, "Ah")) then local currentIndex = counter outSensors[currentIndex] = sensor.label.." "..sensor.unit sensorIds[currentIndex] = sensor.id paramList[currentIndex] = sensor.param counter = counter + 1 end end return outSensors, sensorIds, paramList end ---------------------------------------------- local function initForm1() local addRow, addLabel = form.addRow, form.addLabel local addInputbox, addSpacer, addIntbox, addSelectBox = form.addInputbox, form.addSpacer, form.addIntbox, form.addSelectbox local SensorAuswaehlen, sensorIds, paramList = readSensors() addSpacer(318, 16) addRow(2) addLabel({label= "Schalter für Uhr 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 für Kapa 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) addRow(2) addLabel({label= "Sensor auswählen", width=220}) addSelectBox(SensorAuswaehlen, SensorIndexAusgewaehlt, true, function(val) SensorIndexAusgewaehlt = val SensorIdAusgewaehlt = sensorIds[val] ParamUsed = paramList[val] system.pSave("SensorIndexAusgewaehlt", SensorIndexAusgewaehlt) system.pSave("SensorIdAusgewaehlt", SensorIdAusgewaehlt) system.pSave("ParamUsed", ParamUsed) end) --addRow(1) --addLabel({label="Version kathi4_715"}) end ------------------------------------------------- local function SensorAusgeben() local sensors = system.getSensors() for i, sensor in ipairs(sensors) do if (sensor.type == 5) then if (sensor.decimals == 0) then -- Time print (sensor.type, " ", string.format("%s = %d:%02d:%02d", sensor.label, sensor.valHour, sensor.valMin, sensor.valSec)) else -- Date print (sensor.type, " ", string.format("%s = %d-%02d-%02d", sensor.label, sensor.valYear, sensor.valMonth, sensor.valDay)) end elseif (sensor.type == 9) then print (sensor.type, " GPS gefunden") else if (sensor.param == 0) then -- Sensor label print (sensor.type, " ", string.format("%s:", sensor.label)) else -- Other numeric value print (sensor.type, " ", string.format("%s = %.1f %s (min: %.1f, max: %.1f)", sensor.label, sensor.value, sensor.unit, sensor.min, sensor.max)) end end end 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(SensorIdAusgewaehlt ~= nil) then local sensor = system.getSensorValueByID(SensorIdAusgewaehlt, ParamUsed) local newCap = sensor.value local DeltaCap = system.pLoad("DeltaWertAusweisen",100) if(math.abs(newCap - currentCap) >= DeltaCap) then AnzeigenCap = ((math.floor( newCap / DeltaCap) * DeltaCap) / 1000) system.playNumber (AnzeigenCap, 1, "Ah", "Capacity") currentCap = newCap --print ("Delta ermittelt: ", AnzeigenCap, newCap, DeltaCap) end if (Schalter2gedrueckt == 1) then if(not Schalter2Played) then AnzeigenCap = ((math.floor( newCap / DeltaCap) * DeltaCap) / 1000) system.playNumber (AnzeigenCap, 1, "Ah", "Capacity") Schalter2Played = true --print ("Delta ermittelt: ", AnzeigenCap, newCap, DeltaCap) 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 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) SensorIndexAusgewaehlt = pLoad("SensorIndexAusgewaehlt", 1) SensorIdAusgewaehlt = pLoad("SensorIdAusgewaehlt", nil) ParamUsed = pLoad("ParamUsed", 0) 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 Sensoren angeschlossen") else if(SensorIdAusgewaehlt ~= nil) then currentCap = system.getSensorByID(SensorIdAusgewaehlt, ParamUsed) print("Capacity: ", currentCap) end end end -------------------------------------------------------------------------------- return {init=init, loop=loop, author="Katharina", version="2.1", name="Kathis_App4"}