diff --git a/docs/Configuration-Settings.md b/docs/Configuration-Settings.md index a1b7150..0b870e0 100644 --- a/docs/Configuration-Settings.md +++ b/docs/Configuration-Settings.md @@ -101,6 +101,7 @@ Note also that on some of the smaller B&W radios (Boxer, Zorro, TX12) with a rol * **GPS** - GPS coordinates as decimal or degrees/minutes format (default: Decimal) * **Playback Log** - Playback telemetry log files (latest 5 logs from the last 2 weeks) **[[help](../Configuration-Settings/#playback-telemetry-log-files)]** * **Greyscale Gfx** - Turn on/off the use of greyscale display graphics (only for monochrome displays) + * **CRSF Fuel Delay** - Set the delay before CRSF telemetry values are used for fuel calc, after the FC is initialised ### Suggested Battery Settings #### Voltage and Current Calibration diff --git a/src/SCRIPTS/TELEMETRY/iNav/config.lua b/src/SCRIPTS/TELEMETRY/iNav/config.lua index 1b1c033..e800c6a 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/config.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/config.lua @@ -38,6 +38,7 @@ local config = { { o = 34, c = 1, v = 0, l = {[0] = "?"}, x = -1 }, -- Review Log Date - 34 { o = 35, c = 1, v = 0 }, -- Greyscale toggle - 35 { o = 36, c = 1, v = 0 }, -- Horizon Mode - 36 + { o = 37, c = 2, v = 2.0, d = true, x = 5.0 }, -- CRSF Fuel Delay - 37 } for i = 1, #config do diff --git a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua index 7243fbc..0516ef1 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua @@ -13,6 +13,7 @@ data.fpv_id = getTelemetryId("Hdg") data.tpwr = 0 data.rfmd = "--" data.fuelRaw = 0 + config[9].v = 0 config[14].v = 0 config[21].v = 2.5 @@ -52,16 +53,33 @@ local function crsf(data) data.heading = math.deg(getValue(data.hdg_id)) if data.fpv_id > -1 then data.fpv = getValue(data.fpv_id) * 10 end ]] + data.fuelRaw = data.fuel if data.showFuel and config[23].v == 0 then - if data.fuelEst == -1 and data.cell > 0 then - if data.fuel < 25 and config[29].v - data.cell >= 0.2 then - data.fuelEst = math.max(math.min(1 - (data.cell - config[2].v + 0.1) / (config[29].v - config[2].v), 1), 0) * config[27].v - else - data.fuelEst = 0 + if config[37].v == 0 and data.voltStab == false then data.voltStab = true end + if data.voltStab then + if data.fuelEst == -1 and data.cell > 0 then + if data.fuel < 25 and config[29].v - data.cell >= 0.2 then + data.fuelEst = math.max(math.min(1 - (data.cell - config[2].v + 0.1) / (config[29].v - config[2].v), 1), 0) * config[27].v + else + data.fuelEst = 0 + end + end + data.fuel = math.max(math.min(math.floor((1 - (data.fuel + data.fuelEst) / config[27].v) * 100 + 0.5), 100), 0) + else + data.fuel = -1 -- fuel set to -1 for obvious feedback that fuel is not yet calculated + if data.cell_prev ~= data.cell then + if data.cell > data.cell_prev then + data.voltTimer = getTime() + end + data.cell_prev = data.cell + end + if data.voltTimer > 0 and ( data.voltTimer and (getTime() - data.voltTimer) >= (config[37].v * 100) ) then + -- if no voltage increase in the set time, the pack voltage reading is taken as stabilised. + data.voltStab = true + data.voltTimer = (getTime() - data.voltTimer) end end - data.fuel = math.max(math.min(math.floor((1 - (data.fuel + data.fuelEst) / config[27].v) * 100 + 0.5), 100), 0) end data.fm = getValue(data.fm_id) data.modePrev = data.mode diff --git a/src/SCRIPTS/TELEMETRY/iNav/menu.lua b/src/SCRIPTS/TELEMETRY/iNav/menu.lua index 1b55f7e..af4b8d5 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/menu.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/menu.lua @@ -46,6 +46,7 @@ local function view(data, config, units, lang, event, gpsDegMin, getTelemetryId, { t = "Playback Log", l = config[34].l }, -- 34 { t = "Greyscale Gfx", l = {[0] = "On", "Off"} }, -- 35 { t = "Horizon Mode", l = {[0] = "Standard", "Fixed"} }, -- 36 + { t = "CRSF Fuel Delay", m = 0, i = 0.5, a = "s" }, -- 37 } -- Import language changes @@ -81,6 +82,8 @@ local function view(data, config, units, lang, event, gpsDegMin, getTelemetryId, config2[24].p = data.crsf and 1 or (config[7].v < 2 and 1 or nil) config2[27].p = (not data.crsf or config[23].v > 0) and 1 or nil config2[35].p = HORUS and 1 or nil + config2[36].p = not data.crsf and 1 or nil + if config2[17].p == nil then config2[17].p = (not data.showCurr or config[23].v ~= 0) and 1 or nil config2[18].p = config2[17].p diff --git a/src/SCRIPTS/TELEMETRY/iNav/reset.lua b/src/SCRIPTS/TELEMETRY/iNav/reset.lua index 57bcfcc..77b8ac4 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/reset.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/reset.lua @@ -1,5 +1,8 @@ local data = ... +data.voltTimer = 0 +data.voltStab = false +data.cell_prev = 0.0 data.armed = false data.startup = 1 data.timerStart = 0