From 389361c9b290cd06ad593842ed76d3f34f9422cc Mon Sep 17 00:00:00 2001 From: bkleiner Date: Sun, 7 Jul 2024 17:24:42 +0200 Subject: [PATCH] add ibat_drawn --- src/core/profile.c | 6 ++++-- src/core/profile.h | 20 ++++++++++---------- src/flight/control.c | 1 + src/flight/control.h | 2 ++ src/io/vbat.c | 1 + src/osd/render.c | 10 ++++++++++ src/osd/render.h | 1 + 7 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/core/profile.c b/src/core/profile.c index 2da3ea299..bc25ed6e3 100644 --- a/src/core/profile.c +++ b/src/core/profile.c @@ -445,10 +445,11 @@ const profile_t default_profile = { ENCODE_OSD_ELEMENT(1, 0, 24, 1), // OSD_RSSI ENCODE_OSD_ELEMENT(1, 0, 24, 13), // OSD_STOPWATCH ENCODE_OSD_ELEMENT(1, 0, 4, 6), // OSD_SYSTEM_STATUS - ENCODE_OSD_ELEMENT(1, 0, 1, 13), // OSD_THROTTLE + ENCODE_OSD_ELEMENT(1, 0, 1, 1), // OSD_THROTTLE ENCODE_OSD_ELEMENT(0, 0, 1, 1), // OSD_VTX_CHANNEL ENCODE_OSD_ELEMENT(1, 0, 1, 14), // OSD_CURRENT_DRAW ENCODE_OSD_ELEMENT(0, 0, 14, 6), // OSD_CROSSHAIR + ENCODE_OSD_ELEMENT(1, 0, 1, 13), // OSD_CURRENT_DRAWN }, .elements_hd = { ENCODE_OSD_ELEMENT(1, 1, 19, 0), // OSD_CALLSIGN @@ -460,10 +461,11 @@ const profile_t default_profile = { ENCODE_OSD_ELEMENT(1, 0, 44, 0), // OSD_RSSI ENCODE_OSD_ELEMENT(1, 0, 44, 16), // OSD_STOPWATCH ENCODE_OSD_ELEMENT(1, 0, 14, 8), // OSD_SYSTEM_STATUS - ENCODE_OSD_ELEMENT(1, 0, 0, 16), // OSD_THROTTLE + ENCODE_OSD_ELEMENT(1, 0, 0, 0), // OSD_THROTTLE ENCODE_OSD_ELEMENT(0, 0, 0, 0), // OSD_VTX_CHANNEL ENCODE_OSD_ELEMENT(1, 0, 0, 17), // OSD_CURRENT_DRAW ENCODE_OSD_ELEMENT(0, 0, 15, 8), // OSD_CROSSHAIR + ENCODE_OSD_ELEMENT(1, 0, 0, 16), // OSD_CURRENT_DRAWN }, }, .blackbox = { diff --git a/src/core/profile.h b/src/core/profile.h index bdffcff01..db7da7bc8 100644 --- a/src/core/profile.h +++ b/src/core/profile.h @@ -9,7 +9,7 @@ #define OSD_NUMBER_ELEMENTS 32 -#define PROFILE_VERSION MAKE_SEMVER(0, 2, 3) +#define PROFILE_VERSION MAKE_SEMVER(0, 2, 4) // Rates typedef enum { @@ -229,16 +229,16 @@ typedef struct { float ibat_scale; } profile_voltage_t; -#define VOLTAGE_MEMBERS \ - START_STRUCT(profile_voltage_t) \ - MEMBER(lipo_cell_count, uint8_t) \ - MEMBER(pid_voltage_compensation, uint8_t) \ - MEMBER(vbattlow, float) \ - MEMBER(actual_battery_voltage, float) \ - MEMBER(reported_telemetry_voltage, float) \ +#define VOLTAGE_MEMBERS \ + START_STRUCT(profile_voltage_t) \ + MEMBER(lipo_cell_count, uint8_t) \ + MEMBER(pid_voltage_compensation, uint8_t) \ + MEMBER(vbattlow, float) \ + MEMBER(actual_battery_voltage, float) \ + MEMBER(reported_telemetry_voltage, float) \ MEMBER(use_filtered_voltage_for_warnings, uint8_t) \ - MEMBER(vbat_scale, float) \ - MEMBER(ibat_scale, float) \ + MEMBER(vbat_scale, float) \ + MEMBER(ibat_scale, float) \ END_STRUCT() typedef struct { diff --git a/src/flight/control.c b/src/flight/control.c index 95af4af83..d5c97759a 100644 --- a/src/flight/control.c +++ b/src/flight/control.c @@ -64,6 +64,7 @@ FAST_RAM control_state_t state = { .ibat = 0.0, .ibat_filtered = 0.0, + .ibat_drawn = 0.0, .stick_calibration_wizard = STICK_WIZARD_INACTIVE, diff --git a/src/flight/control.h b/src/flight/control.h index 79700be7c..ade71fd0d 100644 --- a/src/flight/control.h +++ b/src/flight/control.h @@ -68,6 +68,7 @@ typedef struct { float ibat; float ibat_filtered; + float ibat_drawn; vec4_t rx; // holds the raw or calibrated main four channels, roll, pitch, yaw, throttle vec4_t rx_filtered; // same as above, but with constraints (just in case), smoothing and deadband applied @@ -129,6 +130,7 @@ typedef struct { MEMBER(vbat_compensated_cell_avg, float) \ MEMBER(ibat, float) \ MEMBER(ibat_filtered, float) \ + MEMBER(ibat_drawn, float) \ MEMBER(rx, vec4_t) \ MEMBER(rx_filtered, vec4_t) \ MEMBER(rx_override, vec4_t) \ diff --git a/src/io/vbat.c b/src/io/vbat.c index 8a9a20f01..8751169ad 100644 --- a/src/io/vbat.c +++ b/src/io/vbat.c @@ -82,6 +82,7 @@ void vbat_calc() { // read acd and scale based on processor voltage state.ibat = adc_read(ADC_CHAN_IBAT); lpf(&state.ibat_filtered, state.ibat, lpfcalc_hz(0.001, 1)); + state.ibat_drawn += state.ibat_filtered / (60.f * 60.f * 1000.f); // li-ion battery model compensation time decay ( 18 seconds ) state.vbat = adc_read(ADC_CHAN_VBAT); diff --git a/src/osd/render.c b/src/osd/render.c index 586960bbb..5cfc9b8a3 100644 --- a/src/osd/render.c +++ b/src/osd/render.c @@ -19,6 +19,7 @@ #define ICON_CELSIUS 0xe #define ICON_THROTTLE 0x4 #define ICON_VOLT 0x6 +#define ICON_MAH 0x7 #define ICON_AMP 0x9a #define ICON_DOWN 0x76 #define ICON_GAUGE 0x70 @@ -491,6 +492,15 @@ static void osd_display_regular() { break; } + case OSD_CURRENT_DRAWN: { + osd_start(osd_attr(el), el->pos_x, el->pos_y); + osd_write_float(state.ibat_drawn / 1000.0f, 4, 2); + osd_write_char(ICON_MAH); + + osd_state.element++; + break; + } + case OSD_ELEMENT_MAX: { if (osd_system == OSD_SYS_NONE) { // display warning if we can not detect a camera diff --git a/src/osd/render.h b/src/osd/render.h index cc6427d3a..83af1de52 100644 --- a/src/osd/render.h +++ b/src/osd/render.h @@ -69,6 +69,7 @@ typedef enum { OSD_VTX_CHANNEL, OSD_CURRENT_DRAW, OSD_CROSSHAIR, + OSD_CURRENT_DRAWN, OSD_ELEMENT_MAX } osd_elements_t;