diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index c0cad428d9..15c83d244e 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -1657,6 +1657,9 @@ groups: max: INT32_MAX - name: stats_total_dist max: INT32_MAX + - name: stats_total_energy + max: INT32_MAX + condition: USE_ADC - name: PG_TIME_CONFIG type: timeConfig_t diff --git a/src/main/fc/stats.c b/src/main/fc/stats.c index 1bf328e1fc..f2f471e003 100644 --- a/src/main/fc/stats.c +++ b/src/main/fc/stats.c @@ -5,6 +5,8 @@ #include "fc/stats.h" +#include "sensors/battery.h" + #include "drivers/time.h" #include "navigation/navigation.h" @@ -15,21 +17,30 @@ #define MIN_FLIGHT_TIME_TO_RECORD_STATS_S 10 //prevent recording stats for that short "flights" [s] -PG_REGISTER_WITH_RESET_TEMPLATE(statsConfig_t, statsConfig, PG_STATS_CONFIG, 0); +PG_REGISTER_WITH_RESET_TEMPLATE(statsConfig_t, statsConfig, PG_STATS_CONFIG, 1); PG_RESET_TEMPLATE(statsConfig_t, statsConfig, .stats_enabled = 0, .stats_total_time = 0, .stats_total_dist = 0, +#ifdef USE_ADC + .stats_total_energy = 0 +#endif ); static uint32_t arm_millis; static uint32_t arm_distance_cm; +#ifdef USE_ADC +static uint32_t arm_mWhDrawn; +#endif void statsOnArm(void) { arm_millis = millis(); arm_distance_cm = getTotalTravelDistance(); +#ifdef USE_ADC + arm_mWhDrawn = getMWhDrawn(); +#endif } void statsOnDisarm(void) @@ -39,6 +50,10 @@ void statsOnDisarm(void) if (dt >= MIN_FLIGHT_TIME_TO_RECORD_STATS_S) { statsConfigMutable()->stats_total_time += dt; //[s] statsConfigMutable()->stats_total_dist += (getTotalTravelDistance() - arm_distance_cm) / 100; //[m] +#ifdef USE_ADC + if (feature(FEATURE_VBAT) && feature(FEATURE_CURRENT_METER)) + statsConfigMutable()->stats_total_energy += getMWhDrawn() - arm_mWhDrawn; +#endif writeEEPROM(); } } diff --git a/src/main/fc/stats.h b/src/main/fc/stats.h index e9aaa7406c..c77025b81c 100644 --- a/src/main/fc/stats.h +++ b/src/main/fc/stats.h @@ -5,6 +5,9 @@ typedef struct statsConfig_s { uint32_t stats_total_time; // [s] uint32_t stats_total_dist; // [m] +#ifdef USE_ADC + uint32_t stats_total_energy; // deciWatt hour (x0.1Wh) +#endif uint8_t stats_enabled; } statsConfig_t; diff --git a/src/main/io/osd.c b/src/main/io/osd.c index ea4bb6bebd..7afe3e6e50 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -1705,17 +1705,44 @@ void osdInit(displayPort_t *osdDisplayPortToUse) #endif #ifdef USE_STATS +#define STATS_LABEL_X_POS 4 +#define STATS_VALUE_X_POS 24 if (statsConfig()->stats_enabled) { - displayWrite(osdDisplayPort, 3, ++y, "ODOMETER:"); + displayWrite(osdDisplayPort, STATS_LABEL_X_POS, ++y, "ODOMETER:"); if (osdConfig()->units == OSD_UNIT_IMPERIAL) { - tfp_sprintf(string_buffer, "%d MI", statsConfig()->stats_total_dist / METERS_PER_MILE); + tfp_sprintf(string_buffer, "%5d", statsConfig()->stats_total_dist / METERS_PER_MILE); + string_buffer[5] = SYM_MI; } else { - tfp_sprintf(string_buffer, "%d KM", statsConfig()->stats_total_dist / METERS_PER_KILOMETER); + tfp_sprintf(string_buffer, "%5d", statsConfig()->stats_total_dist / METERS_PER_KILOMETER); + string_buffer[5] = SYM_KM; } - displayWrite(osdDisplayPort, 13, y++, string_buffer); + string_buffer[6] = '\0'; + displayWrite(osdDisplayPort, STATS_VALUE_X_POS-5, y, string_buffer); + + displayWrite(osdDisplayPort, STATS_LABEL_X_POS, ++y, "TOTAL TIME:"); uint32_t tot_mins = statsConfig()->stats_total_time / 60; - tfp_sprintf(string_buffer, "%d:%02d H", tot_mins / 60, tot_mins % 60); - displayWrite(osdDisplayPort, 13, y++, string_buffer); + tfp_sprintf(string_buffer, "%2d:%02dHM", tot_mins / 60, tot_mins % 60); + displayWrite(osdDisplayPort, STATS_VALUE_X_POS-5, y, string_buffer); + +#ifdef USE_ADC + if (feature(FEATURE_VBAT) && feature(FEATURE_CURRENT_METER)) { + displayWrite(osdDisplayPort, STATS_LABEL_X_POS, ++y, "TOTAL ENERGY:"); + osdFormatCentiNumber(string_buffer, statsConfig()->stats_total_energy / 10, 0, 2, 0, 4); + strcat(string_buffer, "\xAB"); // SYM_WH + displayWrite(osdDisplayPort, STATS_VALUE_X_POS-4, y, string_buffer); + + displayWrite(osdDisplayPort, STATS_LABEL_X_POS, ++y, "AVG EFFICIENCY:"); + if (statsConfig()->stats_total_dist) { + uint32_t avg_efficiency = statsConfig()->stats_total_energy / (statsConfig()->stats_total_dist / METERS_PER_KILOMETER); // mWh/km + osdFormatCentiNumber(string_buffer, avg_efficiency / 10, 0, 2, 0, 3); + } else + strcpy(string_buffer, "---"); + string_buffer[3] = SYM_WH_KM_0; + string_buffer[4] = SYM_WH_KM_1; + string_buffer[5] = '\0'; + displayWrite(osdDisplayPort, STATS_VALUE_X_POS-3, y, string_buffer); + } +#endif // USE_ADC } #endif