--=============================================================== -- Top-Speed Horus widget. Displays fastest speed during the -- current flight. The 'SH' momentary switch will call-out -- the current top speed. -- -- Defaults to Imperial (MPH). If you want to change to metric -- (KPH) changed the Units variable on line 28. To change the -- switch that is used for the call-out, change line 69 -- -- T3chDadĀ® August-2018 ****NON-COMMERCIAL USE ONLY**** --=============================================================== local defaultOptions = { } local function getTelemetryId(name) field = getFieldInfo(name) if field then return field.id else return -1 end end local TopSpeed = 0 --================================== -- Units: use either "mph" or "kph" local Units = "mph" --================================== local block = 0 local function createWidget(zone, options) TopSpeed = 0 return { zone=zone, options=options } end local function updateWidget(widgetToUpdate, newOptions) widgetToUpdate.options = newOptions updateSpeed(widgetToUpdate) end local function backgroundProcessWidget(widgetToProcessInBackground) updateSpeed(widgetToProcessInBackground) end local function round(num, numDecimalPlaces) local mult = 10^(numDecimalPlaces or 0) return math.floor(num * mult + 0.5) / mult end function updateSpeed(widget) local TelID = getTelemetryId("GSpd") x = widget.zone.x y = widget.zone.y if TelID == -1 then lcd.drawText(x, y, "No Speed Sensor",MIDSIZE) else local spd = getValue(TelID) --conversion from KNOTS to MPH if Units == "mph" then spd = round(spd * 1.150, 1) else --conversion from KNOTS to KPH spd = round(spd * 1.852, 1) end if spd > TopSpeed then TopSpeed = spd end -- Change the 'sh' on the next line to change the switch used for call-out if getValue('sh') > 800 then if getTime() > block + 300 then block = getTime() if Units == "mph" then playNumber(TopSpeed * 10, UNIT_MPH, PREC1) else playNumber(TopSpeed * 10, UNIT_KMH, PREC1) end end end lcd.drawText(x,y,"Top Speed", SMLSIZE) lcd.drawText(x,y+13,TopSpeed..Units,MIDSIZE) end end local function refreshWidget(widgetToRefresh) updateSpeed(widgetToRefresh) end return { name="Top-Speed", options=defaultOptions, create=createWidget, update=updateWidget, refresh=refreshWidget, background=backgroundProcessWidget }