From 05e42db90b41ea558f8dbf8bceab1889ecb6ed6c Mon Sep 17 00:00:00 2001 From: leocb Date: Tue, 17 Jul 2018 11:44:01 -0300 Subject: [PATCH 1/2] Added Max G-force OSD stat --- src/main/interface/settings.c | 1 + src/main/io/osd.c | 14 +++++++++++++- src/main/io/osd.h | 1 + src/test/unit/osd_unittest.cc | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index 0844343695..f185b2cbed 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -982,6 +982,7 @@ const clivalue_t valueTable[] = { { "osd_stat_max_alt", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_STAT_MAX_ALTITUDE, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats)}, { "osd_stat_bbox", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_STAT_BLACKBOX, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats)}, { "osd_stat_bb_no", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_STAT_BLACKBOX_NUMBER, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats)}, + { "osd_stat_max_g_force", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_STAT_MAX_G_FORCE, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats)}, #endif diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 6c59416c7e..dc0bfb5f20 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -126,6 +126,7 @@ static uint32_t blinkBits[(OSD_ITEM_COUNT + 31)/32]; #define IS_MID(X) (rcData[X] > 1250 && rcData[X] < 1750) static timeUs_t flyTime = 0; +static float osdGForce = 0; typedef struct statistic_s { timeUs_t armed_time; @@ -135,6 +136,7 @@ typedef struct statistic_s { int16_t min_rssi; int32_t max_altitude; int16_t max_distance; + float max_g_force; } statistic_t; static statistic_t stats; @@ -694,7 +696,7 @@ static bool osdDrawSingleElement(uint8_t item) case OSD_G_FORCE: { - float osdGForce = 0; + osdGForce = 0.0f; for (int axis = 0; axis < XYZ_AXIS_COUNT; axis++) { const float a = accAverage[axis]; osdGForce += a * a; @@ -1233,6 +1235,7 @@ static void osdResetStats(void) stats.max_altitude = 0; stats.max_distance = 0; stats.armed_time = 0; + stats.max_g_force = 0; } static void osdUpdateStats(void) @@ -1272,6 +1275,10 @@ static void osdUpdateStats(void) stats.max_altitude = altitude; } + if (stats.max_g_force < osdGForce){ + stats.max_g_force = osdGForce; + } + #ifdef USE_GPS if (STATE(GPS_FIX) && STATE(GPS_FIX_HOME)) { value = GPS_distanceToHome; @@ -1439,6 +1446,11 @@ static void osdShowStats(uint16_t endBatteryVoltage) } #endif + if (osdStatGetState(OSD_STAT_MAX_G_FORCE)) { + tfp_sprintf(buff, "%01d.%01dG", (int)stats.max_g_force, (int)(stats.max_g_force * 10) % 10); + osdDisplayStatisticLabel(top++, "MAX G-FORCE", buff); + } + } static void osdShowArmed(void) diff --git a/src/main/io/osd.h b/src/main/io/osd.h index 6addd762b2..d7f676cbf1 100644 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -123,6 +123,7 @@ typedef enum { OSD_STAT_MAX_ALTITUDE, OSD_STAT_BLACKBOX, OSD_STAT_BLACKBOX_NUMBER, + OSD_STAT_MAX_G_FORCE, OSD_STAT_COUNT // MUST BE LAST } osd_stats_e; diff --git a/src/test/unit/osd_unittest.cc b/src/test/unit/osd_unittest.cc index e766d2f789..86841668d4 100644 --- a/src/test/unit/osd_unittest.cc +++ b/src/test/unit/osd_unittest.cc @@ -303,6 +303,7 @@ TEST(OsdTest, TestStatsImperial) osdStatSetState(OSD_STAT_RTC_DATE_TIME, true); osdStatSetState(OSD_STAT_MAX_DISTANCE, true); osdStatSetState(OSD_STAT_BLACKBOX_NUMBER, false); + osdStatSetState(OSD_STAT_MAX_G_FORCE, false); // and // using imperial unit system From 4b415d54cb0e8509355df656e4806b6e3f9a6adb Mon Sep 17 00:00:00 2001 From: leocb Date: Wed, 18 Jul 2018 07:56:24 -0300 Subject: [PATCH 2/2] code formating --- src/main/io/osd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index dc0bfb5f20..df70e2d253 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -1275,7 +1275,7 @@ static void osdUpdateStats(void) stats.max_altitude = altitude; } - if (stats.max_g_force < osdGForce){ + if (stats.max_g_force < osdGForce) { stats.max_g_force = osdGForce; }