1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-20 06:45:16 +03:00

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); osdDrawActiveElementsBackground(osdDisplayPort);
} }
static void osdDrawElements(timeUs_t currentTimeUs) static void osdDrawElements(void)
{ {
// Hide OSD when OSDSW mode is active // Hide OSD when OSDSW mode is active
if (IS_RC_MODE_ACTIVE(BOXOSD)) { if (IS_RC_MODE_ACTIVE(BOXOSD)) {
@ -268,7 +268,7 @@ static void osdDrawElements(timeUs_t currentTimeUs)
displayClearScreen(osdDisplayPort); displayClearScreen(osdDisplayPort);
} }
osdDrawActiveElements(osdDisplayPort, currentTimeUs); osdDrawActiveElements(osdDisplayPort);
} }
const uint16_t osdTimerDefault[OSD_TIMER_COUNT] = { const uint16_t osdTimerDefault[OSD_TIMER_COUNT] = {
@ -982,7 +982,7 @@ STATIC_UNIT_TESTED void osdRefresh(timeUs_t currentTimeUs)
#endif #endif
{ {
osdUpdateAlarms(); osdUpdateAlarms();
osdDrawElements(currentTimeUs); osdDrawElements();
displayHeartbeat(osdDisplayPort); displayHeartbeat(osdDisplayPort);
} }
displayCommitTransaction(osdDisplayPort); displayCommitTransaction(osdDisplayPort);
@ -1024,13 +1024,7 @@ void osdUpdate(timeUs_t currentTimeUs)
#endif #endif
// redraw values in buffer // redraw values in buffer
#ifdef USE_MAX7456 if (counter % OSD_DRAW_FREQ_DENOM == 0) {
#define DRAW_FREQ_DENOM 5
#else
#define DRAW_FREQ_DENOM 10 // MWOSD @ 115200 baud (
#endif
if (counter % DRAW_FREQ_DENOM == 0) {
osdRefresh(currentTimeUs); osdRefresh(currentTimeUs);
showVisualBeeper = false; showVisualBeeper = false;
} else { } else {
@ -1039,7 +1033,7 @@ void osdUpdate(timeUs_t currentTimeUs)
// For the MSP displayPort device only do the drawScreen once per // For the MSP displayPort device only do the drawScreen once per
// logical OSD cycle as there is no output buffering needing to be flushed. // logical OSD cycle as there is no output buffering needing to be flushed.
if (osdDisplayPortDeviceType == OSD_DISPLAYPORT_DEVICE_MSP) { if (osdDisplayPortDeviceType == OSD_DISPLAYPORT_DEVICE_MSP) {
doDrawScreen = (counter % DRAW_FREQ_DENOM == 1); doDrawScreen = (counter % OSD_DRAW_FREQ_DENOM == 1);
} }
#endif #endif
// Redraw a portion of the chars per idle to spread out the load and SPI bus utilization // 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_PRECISION(timer) ((timer >> 4) & 0x0F)
#define OSD_TIMER_ALARM(timer) ((timer >> 8) & 0xFF) #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. // NB: to ensure backwards compatibility, new enum values must be appended at the end but before the OSD_XXXX_COUNT entry.
// *** IMPORTANT *** // *** 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 #ifdef USE_GPS
static bool lastGpsSensorState; static bool lastGpsSensorState;
@ -1892,15 +1894,10 @@ void osdDrawActiveElements(displayPort_t *osdDisplayPort, timeUs_t currentTimeUs
} }
#endif // USE_GPS #endif // USE_GPS
if (osdConfig()->task_frequency == OSD_TASK_FREQUENCY_DEFAULT) { // synchronize the blinking with the OSD task loop
// synchronize the blinking with the OSD task loop if (++blinkLoopCounter >= lrintf(osdConfig()->task_frequency / OSD_DRAW_FREQ_DENOM / (OSD_BLINK_FREQUENCY_HZ * 2))) {
if (++blinkLoopCounter >= 2) { blinkState = !blinkState;
blinkState = !blinkState; blinkLoopCounter = 0;
blinkLoopCounter = 0;
}
} else {
// OSD task frequency is non-standard so revert to time-based blink intervals
blinkState = (currentTimeUs / 200000) % 2;
} }
for (unsigned i = 0; i < activeOsdElementCount; i++) { for (unsigned i = 0; i < activeOsdElementCount; i++) {

View file

@ -47,7 +47,7 @@ int32_t osdGetSpeedToSelectedUnit(int32_t value);
char osdGetSpeedToSelectedUnitSymbol(void); char osdGetSpeedToSelectedUnitSymbol(void);
char osdGetTemperatureSymbolForSelectedUnit(void); char osdGetTemperatureSymbolForSelectedUnit(void);
void osdAddActiveElements(void); void osdAddActiveElements(void);
void osdDrawActiveElements(displayPort_t *osdDisplayPort, timeUs_t currentTimeUs); void osdDrawActiveElements(displayPort_t *osdDisplayPort);
void osdDrawActiveElementsBackground(displayPort_t *osdDisplayPort); void osdDrawActiveElementsBackground(displayPort_t *osdDisplayPort);
void osdElementsInit(bool backgroundLayerFlag); void osdElementsInit(bool backgroundLayerFlag);
void osdResetAlarms(void); void osdResetAlarms(void);

View file

@ -673,7 +673,7 @@ TEST_F(OsdTest, TestAlarms)
printf("%d\n", i); printf("%d\n", i);
displayPortTestPrint(); displayPortTestPrint();
#endif #endif
if (i % 2 == 0) { if (i % 2 == 1) {
displayPortTestBufferSubstring(8, 1, "%c12", SYM_RSSI); displayPortTestBufferSubstring(8, 1, "%c12", SYM_RSSI);
displayPortTestBufferSubstring(12, 1, "%c13.5%c", SYM_MAIN_BATT, SYM_VOLT); 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 displayPortTestBufferSubstring(1, 1, "%c02:", SYM_FLY_M); // only test the minute part of the timer
@ -1044,6 +1044,7 @@ TEST_F(OsdTest, TestElementWarningsBattery)
// when // when
displayClearScreen(&testDisplayPort); displayClearScreen(&testDisplayPort);
osdRefresh(simulationTime); osdRefresh(simulationTime);
osdRefresh(simulationTime);
// then // then
displayPortTestBufferSubstring(9, 10, " LAND NOW "); displayPortTestBufferSubstring(9, 10, " LAND NOW ");