collectgarbage() local sensorID,sensorParam local stepSize local resetSwitch local altitudeStep=0 local altitudeGained=0 local resetSwitchState local function printForm(formID) local telSensors=system.getSensors() local sensorIDs={0} local sensorParams={0} local sensorLabels={"..."} local sensorIndex=0 for k,v in ipairs(telSensors) do if v.param>0 then table.insert(sensorIDs,v.id) table.insert(sensorParams,v.param) table.insert(sensorLabels,v.sensorName..": "..v.label.." ["..v.unit.."]") if (sensorID==v.id and sensorParam==v.param) then sensorIndex=k end end end form.addRow(2) form.addLabel({label="Sensor",width=80}) form.addSelectbox(sensorLabels,sensorIndex,true,function(i) sensorID=sensorIDs[i] sensorParam=sensorParams[i] system.pSave("sensorID",sensorID) system.pSave("sensorParam",sensorParam) end,{width=232}) form.addRow(2) form.addLabel({label="Step Size"}) form.addIntbox(stepSize,1,50,10,0,1,function(i) stepSize=i system.pSave("stepSize",stepSize) end) form.addRow(2) form.addLabel({label="Reset Switch"}) form.addInputbox(resetSwitch,true,function(i) resetSwitch=i system.pSave("resetSwitch",resetSwitch) end) end local function init(code) sensorID=system.pLoad("sensorID",0) sensorParam=system.pLoad("sensorParam",0) stepSize=system.pLoad("stepSize",10) resetSwitch=system.pLoad("resetSwitch") system.registerTelemetry(1,"Altitude Gain",0,function() lcd.drawText(5,0,altitudeGained.."m",FONT_BIG) end) system.registerForm(1,MENU_APPS,"Altitude Gain",printForm) end local function loop() local sensor=system.getSensorValueByID(sensorID,sensorParam) if (not sensor) then return end if (resetSwitch) then local resetSwitchStateNew=system.getInputsVal(resetSwitch) if (resetSwitchState~=resetSwitchStateNew) then resetSwitchState=resetSwitchStateNew altitudeGained=0 end end if (sensor.value>altitudeStep+stepSize) then altitudeStep=altitudeStep+stepSize altitudeGained=altitudeGained+stepSize elseif (sensor.value