Simplified the OSD blink frequency calculation.

This commit is contained in:
Michael Keller 2021-01-01 23:50:23 +01:00
parent 932d6dc153
commit a702ee1a5b
5 changed files with 23 additions and 24 deletions

View File

@ -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

View File

@ -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 ***

View File

@ -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++) {

View File

@ -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);

View File

@ -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 ");