mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 15:25:36 +03:00
Improve OSD blink logic
Changes the blink logic to be OSD task loop based instead of time based. The previous logic used a 200ms time interval for the blinking which didn't align well with the default 12hz OSD update frequency resulting in the logic periodically missing intervals resulting in an inconsistent blinking. As the revised logic is now tied to the OSD task iterations the blinking will be consistent. However due to the timing the blink will be slightly faster - 167ms (6hz) vs. the previous 200ms (5hz) intervals. Technically the blinking was 6hz before but stuttered every 5th blink. Since the OSD task rate can be changed from the default 60hz, the logic will fall back to the time-based implementation for non-default task rates.
This commit is contained in:
parent
3f116fd103
commit
f7d992b2bd
4 changed files with 15 additions and 3 deletions
|
@ -448,7 +448,7 @@ task_t tasks[TASK_COUNT] = {
|
|||
#endif
|
||||
|
||||
#ifdef USE_OSD
|
||||
[TASK_OSD] = DEFINE_TASK("OSD", NULL, NULL, osdUpdate, TASK_PERIOD_HZ(60), TASK_PRIORITY_LOW),
|
||||
[TASK_OSD] = DEFINE_TASK("OSD", NULL, NULL, osdUpdate, TASK_PERIOD_HZ(OSD_TASK_FREQUENCY_DEFAULT), TASK_PRIORITY_LOW),
|
||||
#endif
|
||||
|
||||
#ifdef USE_TELEMETRY
|
||||
|
|
|
@ -340,7 +340,7 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig)
|
|||
osdConfig->camera_frame_width = 24;
|
||||
osdConfig->camera_frame_height = 11;
|
||||
|
||||
osdConfig->task_frequency = 60;
|
||||
osdConfig->task_frequency = OSD_TASK_FREQUENCY_DEFAULT;
|
||||
}
|
||||
|
||||
void pgResetFn_osdElementConfig(osdElementConfig_t *osdElementConfig)
|
||||
|
|
|
@ -51,6 +51,7 @@ extern const char * const osdTimerSourceNames[OSD_NUM_TIMER_TYPES];
|
|||
|
||||
#define OSD_TASK_FREQUENCY_MIN 30
|
||||
#define OSD_TASK_FREQUENCY_MAX 300
|
||||
#define OSD_TASK_FREQUENCY_DEFAULT 60
|
||||
|
||||
#define OSD_PROFILE_BITS_POS 11
|
||||
#define OSD_PROFILE_MASK (((1 << OSD_PROFILE_COUNT) - 1) << OSD_PROFILE_BITS_POS)
|
||||
|
|
|
@ -1879,6 +1879,8 @@ static void osdDrawSingleElementBackground(displayPort_t *osdDisplayPort, uint8_
|
|||
|
||||
void osdDrawActiveElements(displayPort_t *osdDisplayPort, timeUs_t currentTimeUs)
|
||||
{
|
||||
static int blinkLoopCounter = 0;
|
||||
|
||||
#ifdef USE_GPS
|
||||
static bool lastGpsSensorState;
|
||||
// Handle the case that the GPS_SENSOR may be delayed in activation
|
||||
|
@ -1890,7 +1892,16 @@ 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;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < activeOsdElementCount; i++) {
|
||||
if (!backgroundLayerSupported) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue