diff --git a/src/main/osd/osd.c b/src/main/osd/osd.c index 128b5f340..eb7cf1e90 100644 --- a/src/main/osd/osd.c +++ b/src/main/osd/osd.c @@ -250,7 +250,7 @@ void osdAnalyzeActiveElements(void) osdDrawActiveElementsBackground(osdDisplayPort); } -static void osdDrawElements(timeUs_t currentTimeUs) +static void osdDrawElements(void) { // Hide OSD when OSDSW mode is active if (IS_RC_MODE_ACTIVE(BOXOSD)) { @@ -268,7 +268,7 @@ static void osdDrawElements(timeUs_t currentTimeUs) displayClearScreen(osdDisplayPort); } - osdDrawActiveElements(osdDisplayPort, currentTimeUs); + osdDrawActiveElements(osdDisplayPort); } const uint16_t osdTimerDefault[OSD_TIMER_COUNT] = { @@ -982,7 +982,7 @@ STATIC_UNIT_TESTED void osdRefresh(timeUs_t currentTimeUs) #endif { osdUpdateAlarms(); - osdDrawElements(currentTimeUs); + osdDrawElements(); displayHeartbeat(osdDisplayPort); } displayCommitTransaction(osdDisplayPort); @@ -1024,13 +1024,7 @@ void osdUpdate(timeUs_t currentTimeUs) #endif // redraw values in buffer -#ifdef USE_MAX7456 -#define DRAW_FREQ_DENOM 5 -#else -#define DRAW_FREQ_DENOM 10 // MWOSD @ 115200 baud ( -#endif - - if (counter % DRAW_FREQ_DENOM == 0) { + if (counter % OSD_DRAW_FREQ_DENOM == 0) { osdRefresh(currentTimeUs); showVisualBeeper = false; } else { @@ -1039,7 +1033,7 @@ void osdUpdate(timeUs_t currentTimeUs) // For the MSP displayPort device only do the drawScreen once per // logical OSD cycle as there is no output buffering needing to be flushed. if (osdDisplayPortDeviceType == OSD_DISPLAYPORT_DEVICE_MSP) { - doDrawScreen = (counter % DRAW_FREQ_DENOM == 1); + doDrawScreen = (counter % OSD_DRAW_FREQ_DENOM == 1); } #endif // Redraw a portion of the chars per idle to spread out the load and SPI bus utilization diff --git a/src/main/osd/osd.h b/src/main/osd/osd.h index 623f2878f..c7af5310b 100644 --- a/src/main/osd/osd.h +++ b/src/main/osd/osd.h @@ -84,6 +84,13 @@ extern const char * const osdTimerSourceNames[OSD_NUM_TIMER_TYPES]; #define OSD_TIMER_PRECISION(timer) ((timer >> 4) & 0x0F) #define OSD_TIMER_ALARM(timer) ((timer >> 8) & 0xFF) +#ifdef USE_MAX7456 +#define OSD_DRAW_FREQ_DENOM 5 +#else +// MWOSD @ 115200 baud +#define OSD_DRAW_FREQ_DENOM 10 +#endif + // NB: to ensure backwards compatibility, new enum values must be appended at the end but before the OSD_XXXX_COUNT entry. // *** IMPORTANT *** diff --git a/src/main/osd/osd_elements.c b/src/main/osd/osd_elements.c index b14e0254e..8fe95f0f5 100644 --- a/src/main/osd/osd_elements.c +++ b/src/main/osd/osd_elements.c @@ -1877,9 +1877,11 @@ static void osdDrawSingleElementBackground(displayPort_t *osdDisplayPort, uint8_ } } -void osdDrawActiveElements(displayPort_t *osdDisplayPort, timeUs_t currentTimeUs) +#define OSD_BLINK_FREQUENCY_HZ 2.5f + +void osdDrawActiveElements(displayPort_t *osdDisplayPort) { - static int blinkLoopCounter = 0; + static unsigned blinkLoopCounter = 0; #ifdef USE_GPS static bool lastGpsSensorState; @@ -1892,15 +1894,10 @@ void osdDrawActiveElements(displayPort_t *osdDisplayPort, timeUs_t currentTimeUs } #endif // USE_GPS - if (osdConfig()->task_frequency == OSD_TASK_FREQUENCY_DEFAULT) { - // synchronize the blinking with the OSD task loop - if (++blinkLoopCounter >= 2) { - blinkState = !blinkState; - blinkLoopCounter = 0; - } - } else { - // OSD task frequency is non-standard so revert to time-based blink intervals - blinkState = (currentTimeUs / 200000) % 2; + // synchronize the blinking with the OSD task loop + if (++blinkLoopCounter >= lrintf(osdConfig()->task_frequency / OSD_DRAW_FREQ_DENOM / (OSD_BLINK_FREQUENCY_HZ * 2))) { + blinkState = !blinkState; + blinkLoopCounter = 0; } for (unsigned i = 0; i < activeOsdElementCount; i++) { diff --git a/src/main/osd/osd_elements.h b/src/main/osd/osd_elements.h index d7aca9047..ed7241716 100644 --- a/src/main/osd/osd_elements.h +++ b/src/main/osd/osd_elements.h @@ -47,7 +47,7 @@ int32_t osdGetSpeedToSelectedUnit(int32_t value); char osdGetSpeedToSelectedUnitSymbol(void); char osdGetTemperatureSymbolForSelectedUnit(void); void osdAddActiveElements(void); -void osdDrawActiveElements(displayPort_t *osdDisplayPort, timeUs_t currentTimeUs); +void osdDrawActiveElements(displayPort_t *osdDisplayPort); void osdDrawActiveElementsBackground(displayPort_t *osdDisplayPort); void osdElementsInit(bool backgroundLayerFlag); void osdResetAlarms(void); diff --git a/src/test/unit/osd_unittest.cc b/src/test/unit/osd_unittest.cc index f15baf006..22d57d3f1 100644 --- a/src/test/unit/osd_unittest.cc +++ b/src/test/unit/osd_unittest.cc @@ -673,7 +673,7 @@ TEST_F(OsdTest, TestAlarms) printf("%d\n", i); displayPortTestPrint(); #endif - if (i % 2 == 0) { + if (i % 2 == 1) { displayPortTestBufferSubstring(8, 1, "%c12", SYM_RSSI); displayPortTestBufferSubstring(12, 1, "%c13.5%c", SYM_MAIN_BATT, SYM_VOLT); displayPortTestBufferSubstring(1, 1, "%c02:", SYM_FLY_M); // only test the minute part of the timer @@ -1044,6 +1044,7 @@ TEST_F(OsdTest, TestElementWarningsBattery) // when displayClearScreen(&testDisplayPort); osdRefresh(simulationTime); + osdRefresh(simulationTime); // then displayPortTestBufferSubstring(9, 10, " LAND NOW ");