collectgarbage() local model = " " local measure = false local measure_switch = 0 local integral_switch = 0; local app_name = "Eigensinken" local sensorId, vario_param, attitude_param local sensor_label = "" local timestamp, diff_time local vario, min_vario, max_vario, vario_integral = 0.0, 0.0, 0.0, 0.0 local attitude_start, attitude_end = 0, 0 local flight = {} local flight_num, flight_index = 0, 0 local last_integral_time = 0 local vario_list = {} local function Page1(width, height) if( system.getTime() % 2 == 0 and measure ) then lcd.drawText(1, 1, " Flugnr. Zeit MinVar MaxVar ØSteigen", FONT_BOLD|FONT_REVERSED ) else lcd.drawText(1, 1, " Flugnr. Zeit MinVar MaxVar ØSteigen", FONT_BOLD ) end if ( #flight ) then for i = 1, #flight do lcd.drawText (40 - lcd.getTextWidth (FONT_NORMAL, string.format("%3d", flight[i]["num"] )), flight[i]["line_offs"], string.format("%3d",flight[i]["num"]), FONT_NORMAL ) lcd.drawText (105 - lcd.getTextWidth (FONT_NORMAL, string.format("%3.2f", flight[i]["time"] )), flight[i]["line_offs"], string.format("%3.2f",flight[i]["time"]), FONT_NORMAL ) lcd.drawText (170 - lcd.getTextWidth (FONT_NORMAL, string.format("%3.2f", flight[i]["min"] )), flight[i]["line_offs"], string.format("%3.2f",flight[i]["min"]), FONT_NORMAL ) lcd.drawText (235 - lcd.getTextWidth (FONT_NORMAL, string.format("%3.2f", flight[i]["max"] )), flight[i]["line_offs"], string.format("%3.2f",flight[i]["max"]), FONT_NORMAL ) lcd.drawText (300 - lcd.getTextWidth (FONT_NORMAL, string.format("%3.2f", flight[i]["average"] )), flight[i]["line_offs"], string.format("%3.2f",flight[i]["average"]), FONT_NORMAL ) end end end local function measure_switchChanged(value) measure_switch = value system.pSave("measure_switch", measure_switch) end local function integral_switchChanged(value) integral_switch = value system.pSave("integral_switch", integral_switch) end local function setupForm(formID) local available = system.getSensors() for index,sensor in ipairs(available) do if(sensor.param == 0) then if ( sensor.label == "LiVa" or sensor.label == "AlexVarioEX" ) then if ( sensor.label == "LiVa" ) then vario_param = 2 attitude_param = 1 elseif ( sensor.label == "AlexVarioEX" ) then vario_param = 7 attitude_param = 3 end sensorId = sensor.id system.pSave("sensor_label", sensor.label) system.pSave("sensorId", sensor.id) system.pSave("vario_param", vario_param) system.pSave("attitude_param", attitude_param) break end end end form.setTitle("Telemetrieeinstellungen") form.addSpacer(318,7) form.addRow(1) form.addLabel({label="Schalterwahl",font=FONT_BOLD}) form.addSpacer(318,7) form.addRow(2) form.addLabel({label="Start Stop Schalter", width=220}) form.addInputbox(measure_switch,true,measure_switchChanged) form.addSpacer(318,7) form.addRow(2) form.addLabel({label="Integral Schalter", width=220}) form.addInputbox(integral_switch,true,integral_switchChanged) form.addSpacer(318,40) form.addLabel({label="Eigensinken " .. Version .. " ", font=FONT_MINI, alignRight=true}) collectgarbage() end function average(value) -- integral vario helper local sum_varios = 0 local vario local i if ( #vario_list == 200 ) then table.remove(vario_list, 1) end vario_list[#vario_list + 1] = value for i,vario in ipairs(vario_list) do sum_varios = sum_varios + vario end collectgarbage() return sum_varios / #vario_list end local function loop() local sensor local avr_timestamp if ( 1 == system.getInputsVal(measure_switch) ) then -- transition to measure state if ( measure == false ) then measure = true timestamp = system.getTimeCounter() sensor = system.getSensorValueByID(sensorId, attitude_param) if ( sensor and sensor.valid ) then --if ( sensor ) then --fake valid sensor attitude_start = sensor.value --attitude_start = system.getInputs ("P6") * 100 + 100 --fake attitude else attitude_start = 0.0 end min_vario = 100 max_vario = -100 vario_list = {} system.playBeep( 0, 1200, 500 ) end sensor = system.getSensorValueByID(sensorId, vario_param) if ( sensor and sensor.valid ) then --if ( sensor) then --fake valid sensor vario = sensor.value --vario = system.getInputs ("P8") * 10 --fake vario if ( 1 == system.getInputsVal(integral_switch) ) then avr_timestamp = system.getTimeCounter() if avr_timestamp >= (last_integral_time + 10) then -- one 1/100 second period vario_integral = average(vario) -- average integral vario over 200 samples with 1/100 sencond period ( ie. 2 Sec ) last_integral_time = avr_timestamp end if (vario_integral > max_vario ) then max_vario = vario_integral end if (vario_integral < min_vario ) then min_vario = vario_integral end else if (vario > max_vario ) then max_vario = vario end if (vario < min_vario ) then min_vario = vario end end else vario = 0.0 end else -- transition to non measure state if ( measure == true ) then measure = false diff_time = system.getTimeCounter() - timestamp sensor = system.getSensorValueByID(sensorId, attitude_param) if ( sensor and sensor.valid) then --if ( sensor ) then --fake valid sensor attitude_stop = sensor.value --attitude_stop = system.getInputs ("P6") * 100 + 100 --fake attitude else attitude_stop = 0.0 end average_vario = (attitude_stop - attitude_start) / ( diff_time / 1000 ) if ( flight_index == 8 ) then flight_index = 0 end flight_num = flight_num + 1 flight_index = flight_index + 1 flight[flight_index] = {} flight[flight_index]["num"] = flight_num flight[flight_index]["line_offs"] = flight_index * 17 + 4 flight[flight_index]["time"] = diff_time / 1000 flight[flight_index]["min"] = min_vario flight[flight_index]["max"] = max_vario flight[flight_index]["average"] = average_vario system.playBeep( 1, 1200, 500 ) end end collectgarbage() end local function init(code1) model = system.getProperty("Model") measure_switch = system.pLoad("measure_switch") integral_switch = system.pLoad("integral_switch") vario_param = system.pLoad("vario_param") attitude_param = system.pLoad("attitude_param") sensorId = system.pLoad("sensorId") vario_param = system.pLoad("vario_param") attitude_param = system.pLoad("attitude_param") sensor_label = system.pLoad("sensor_label", "") system.registerForm(1, MENU_APPS, app_name, setupForm) system.registerTelemetry(1, app_name .. " " .. model .. " " .. sensor_label, 4, Page1) collectgarbage() end Version = "1.0" collectgarbage() return {init=init, loop=loop, author="nichtgedacht", version=Version, name=app_name}