Skip to content

Commit a389e66

Browse files
Merge pull request #11206 from hntirgeam/osd_freq_command
Configurable OSD refresh rate
2 parents c36b5d7 + 3732e51 commit a389e66

6 files changed

Lines changed: 63 additions & 8 deletions

File tree

docs/Settings.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4842,6 +4842,16 @@ Force OSD to work in grid mode even if the OSD device supports pixel level acces
48424842

48434843
---
48444844

4845+
### osd_framerate_hz
4846+
4847+
Target refresh rate for OSD elements in Hz. Each element is redrawn at approximately this rate. Values above 10 Hz provide no visible improvement for typical flight data but increase CPU load. Artificial horizon and telemetry are always updated every cycle regardless of this setting. Set to -1 for legacy behavior (one element per frame).
4848+
4849+
| Default | Min | Max |
4850+
| --- | --- | --- |
4851+
| -1 | -1 | 15 |
4852+
4853+
---
4854+
48454855
### osd_gforce_alarm
48464856

48474857
Value above which the OSD g force indicator will blink (g)

src/main/build/debug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ typedef enum {
7979
DEBUG_GPS,
8080
DEBUG_LULU,
8181
DEBUG_SBUS2,
82+
DEBUG_OSD_REFRESH,
8283
DEBUG_COUNT // also update debugModeNames in cli.c
8384
} debugType_e;
8485

src/main/fc/cli.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ static const char *debugModeNames[DEBUG_COUNT] = {
222222
"HEADTRACKER",
223223
"GPS",
224224
"LULU",
225-
"SBUS2"
225+
"SBUS2",
226+
"OSD_REFRESH"
226227
};
227228

228229
/* Sensor names (used in lookup tables for *_hardware settings and in status

src/main/fc/settings.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ tables:
8484
"VIBE", "CRUISE", "REM_FLIGHT_TIME", "SMARTAUDIO", "ACC",
8585
"NAV_YAW", "PCF8574", "DYN_GYRO_LPF", "AUTOLEVEL", "ALTITUDE",
8686
"AUTOTRIM", "AUTOTUNE", "RATE_DYNAMICS", "LANDING", "POS_EST",
87-
"ADAPTIVE_FILTER", "HEADTRACKER", "GPS", "LULU", "SBUS2"]
87+
"ADAPTIVE_FILTER", "HEADTRACKER", "GPS", "LULU", "SBUS2", "OSD_REFRESH"]
8888
- name: aux_operator
8989
values: ["OR", "AND"]
9090
enum: modeActivationOperator_e
@@ -3334,6 +3334,13 @@ groups:
33343334
max: 600
33353335
type: int16_t
33363336
field: msp_displayport_fullframe_interval
3337+
- name: osd_framerate_hz
3338+
description: "Target refresh rate for OSD elements in Hz. Each element is redrawn at approximately this rate. Values above 10 Hz provide no visible improvement for typical flight data but increase CPU load. Artificial horizon and telemetry are always updated every cycle regardless of this setting. Set to -1 for legacy behavior (one element per frame)."
3339+
default_value: -1
3340+
min: -1
3341+
max: 15
3342+
type: int8_t
3343+
field: osd_framerate_hz
33373344
- name: osd_units
33383345
description: "IMPERIAL, METRIC, UK"
33393346
default_value: "METRIC"

src/main/io/osd.c

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <ctype.h>
3030
#include <math.h>
3131
#include <inttypes.h>
32+
#include <limits.h>
3233

3334
#include "platform.h"
3435

@@ -4246,15 +4247,48 @@ uint8_t osdIncElementIndex(uint8_t elementIndex)
42464247
void osdDrawNextElement(void)
42474248
{
42484249
static uint8_t elementIndex = 0;
4249-
// Flag for end of loop, also prevents infinite loop when no elements are enabled
4250-
uint8_t index = elementIndex;
4251-
do {
4252-
elementIndex = osdIncElementIndex(elementIndex);
4253-
} while (!osdDrawSingleElement(elementIndex) && index != elementIndex);
4250+
static uint8_t activeElements = 0;
4251+
static unsigned lastLayout = UINT_MAX;
4252+
4253+
// Recount visible elements on layout change
4254+
if (currentLayout != lastLayout) {
4255+
lastLayout = currentLayout;
4256+
activeElements = 0;
4257+
uint8_t idx = 0;
4258+
do {
4259+
idx = osdIncElementIndex(idx);
4260+
if (OSD_VISIBLE(osdLayoutsConfig()->item_pos[currentLayout][idx])) {
4261+
activeElements++;
4262+
}
4263+
} while (idx > 0);
4264+
}
4265+
4266+
int8_t framerate_hz = osdConfig()->osd_framerate_hz;
4267+
4268+
uint8_t elementsPerCycle;
4269+
if (framerate_hz <= 0 || activeElements == 0) {
4270+
elementsPerCycle = 1; // legacy: one element per cycle
4271+
} else {
4272+
elementsPerCycle = ((uint16_t)activeElements * framerate_hz * 2 + 124) / 125;
4273+
if (elementsPerCycle < 1) elementsPerCycle = 1;
4274+
if (elementsPerCycle > activeElements) elementsPerCycle = activeElements;
4275+
}
4276+
4277+
DEBUG_SET(DEBUG_OSD_REFRESH, 0, elementsPerCycle);
4278+
DEBUG_SET(DEBUG_OSD_REFRESH, 1, activeElements);
4279+
DEBUG_SET(DEBUG_OSD_REFRESH, 2, elementIndex);
4280+
DEBUG_SET(DEBUG_OSD_REFRESH, 3, framerate_hz);
4281+
4282+
for (uint8_t i = 0; i < elementsPerCycle; i++) {
4283+
uint8_t index = elementIndex;
4284+
do {
4285+
elementIndex = osdIncElementIndex(elementIndex);
4286+
} while (!osdDrawSingleElement(elementIndex) && index != elementIndex);
4287+
}
42544288

42554289
// Draw artificial horizon + tracking telemetry last
42564290
osdDrawSingleElement(OSD_ARTIFICIAL_HORIZON);
4257-
if (osdConfig()->telemetry>0){
4291+
if (osdConfig()->telemetry > 0) {
42584292
osdDisplayTelemetry();
42594293
}
42604294
}
@@ -4305,6 +4339,7 @@ PG_RESET_TEMPLATE(osdConfig_t, osdConfig,
43054339
.video_system = SETTING_OSD_VIDEO_SYSTEM_DEFAULT,
43064340
.row_shiftdown = SETTING_OSD_ROW_SHIFTDOWN_DEFAULT,
43074341
.msp_displayport_fullframe_interval = SETTING_OSD_MSP_DISPLAYPORT_FULLFRAME_INTERVAL_DEFAULT,
4342+
.osd_framerate_hz = SETTING_OSD_FRAMERATE_HZ_DEFAULT,
43084343

43094344
.ahi_reverse_roll = SETTING_OSD_AHI_REVERSE_ROLL_DEFAULT,
43104345
.ahi_max_pitch = SETTING_OSD_AHI_MAX_PITCH_DEFAULT,

src/main/io/osd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ typedef struct osdConfig_s {
451451
videoSystem_e video_system;
452452
uint8_t row_shiftdown;
453453
int16_t msp_displayport_fullframe_interval;
454+
int8_t osd_framerate_hz;
454455

455456
// Preferences
456457
uint8_t main_voltage_decimals;

0 commit comments

Comments
 (0)