From dadedd059f0db4d974e5b5568c5419915fc26c34 Mon Sep 17 00:00:00 2001 From: Miguel Angel Mulero Martinez Date: Tue, 24 Oct 2017 08:35:02 +0200 Subject: [PATCH] Show stats only if enabled If no enabled stat to show, don't show the stats page in the OSD --- src/main/io/osd.c | 17 +++++++++++++++++ src/test/unit/osd_unittest.cc | 17 +++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 29c424d932..e2ba089784 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -1015,8 +1015,25 @@ static void osdDisplayStatisticLabel(uint8_t y, const char * text, const char * displayWrite(osdDisplayPort, 22, y, value); } +/* + * Test if there's some stat enabled + */ +static bool isSomeStatEnabled(void) { + for (int i = 0; i < OSD_STAT_COUNT; i++) { + if (osdConfig()->enabled_stats[i]) { + return true; + } + } + return false; +} + static void osdShowStats(void) { + + if (!isSomeStatEnabled()) { + return; + } + uint8_t top = 2; char buff[10]; diff --git a/src/test/unit/osd_unittest.cc b/src/test/unit/osd_unittest.cc index 534db8b60f..7c126383d6 100644 --- a/src/test/unit/osd_unittest.cc +++ b/src/test/unit/osd_unittest.cc @@ -131,6 +131,18 @@ void doTestArm(bool testEmpty = true) } } +/* + * Auxiliary function. Test is there're stats that must be shown + */ +bool isSomeStatEnabled(void) { + for (int i = 0; i < OSD_STAT_COUNT; i++) { + if (osdConfigMutable()->enabled_stats[i]) { + return true; + } + } + return false; +} + /* * Performs a test of the OSD actions on disarming. * (reused throughout the test suite) @@ -147,10 +159,11 @@ void doTestDisarm() // then // post flight statistics displayed - displayPortTestBufferSubstring(2, 2, " --- STATS ---"); + if (isSomeStatEnabled()) { + displayPortTestBufferSubstring(2, 2, " --- STATS ---"); + } } - /* * Tests initialisation of the OSD and the power on splash screen. */