Skip to content

Commit

Permalink
add ibat_drawn
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Jul 7, 2024
1 parent 0c9c5b4 commit 4a2e8d1
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/core/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down
20 changes: 10 additions & 10 deletions src/core/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/flight/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
2 changes: 2 additions & 0 deletions src/flight/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) \
Expand Down
1 change: 1 addition & 0 deletions src/io/vbat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/osd/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/osd/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef enum {
OSD_VTX_CHANNEL,
OSD_CURRENT_DRAW,
OSD_CROSSHAIR,
OSD_CURRENT_DRAWN,

OSD_ELEMENT_MAX
} osd_elements_t;
Expand Down

0 comments on commit 4a2e8d1

Please sign in to comment.