mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 16:55:36 +03:00
Refactor OSD element display code
Remove the giant `select` block that contained all the code to generate the elements and transition them to individual functions called only when the element is active. Simplifies the code and results in a performance improvement as it's not necessary to fall through the large `select` statement for every element that will be drawn. The individual functions and the element to function mapping are moved to a new `osd_elements.c` file. Moved the OSD related code files to a new `osd/` directory. Also pre-analyze the active elements and only process those that are active. This also saves processing as it's not necessary to loop through all 50 or so elements when only a couple are active. Various other cleanup and removal of stale or unnecessary code. In the default configuration the element drawing phase of the OSD task is reduced from ~51us to ~35us - resulting in about a 30% decrease in processing time.
This commit is contained in:
parent
e053965489
commit
30672a37c5
31 changed files with 2435 additions and 2133 deletions
|
@ -40,11 +40,11 @@ extern "C" {
|
|||
#include "flight/servos.h"
|
||||
#include "io/beeper.h"
|
||||
#include "io/ledstrip.h"
|
||||
#include "io/osd.h"
|
||||
#include "io/serial.h"
|
||||
#include "io/vtx.h"
|
||||
#include "msp/msp.h"
|
||||
#include "msp/msp_box.h"
|
||||
#include "osd/osd.h"
|
||||
#include "pg/pg.h"
|
||||
#include "pg/pg_ids.h"
|
||||
#include "pg/beeper.h"
|
||||
|
|
|
@ -52,7 +52,9 @@ extern "C" {
|
|||
|
||||
#include "io/beeper.h"
|
||||
#include "io/gps.h"
|
||||
#include "io/osd.h"
|
||||
|
||||
#include "osd/osd.h"
|
||||
#include "osd/osd_elements.h"
|
||||
|
||||
#include "sensors/acceleration.h"
|
||||
#include "sensors/battery.h"
|
||||
|
@ -62,7 +64,6 @@ extern "C" {
|
|||
|
||||
void osdRefresh(timeUs_t currentTimeUs);
|
||||
void osdFormatTime(char * buff, osd_timer_precision_e precision, timeUs_t time);
|
||||
void osdFormatTimer(char *buff, bool showSymbol, int timerIndex);
|
||||
int osdConvertTemperatureToSelectedUnit(int tempInDegreesCelcius);
|
||||
|
||||
uint16_t rssi;
|
||||
|
@ -481,6 +482,8 @@ TEST(OsdTest, TestAlarms)
|
|||
osdConfigMutable()->cap_alarm = 2200;
|
||||
osdConfigMutable()->alt_alarm = 100; // meters
|
||||
|
||||
osdAnalyzeActiveElements();
|
||||
|
||||
// and
|
||||
// this timer 1 configuration
|
||||
osdConfigMutable()->timers[OSD_TIMER_1] = OSD_TIMER(OSD_TIMER_SRC_ON, OSD_TIMER_PREC_HUNDREDTHS, 2);
|
||||
|
@ -562,6 +565,8 @@ TEST(OsdTest, TestElementRssi)
|
|||
osdConfigMutable()->item_pos[OSD_RSSI_VALUE] = OSD_POS(8, 1) | OSD_PROFILE_1_FLAG;
|
||||
osdConfigMutable()->rssi_alarm = 0;
|
||||
|
||||
osdAnalyzeActiveElements();
|
||||
|
||||
// when
|
||||
rssi = 1024;
|
||||
displayClearScreen(&testDisplayPort);
|
||||
|
@ -595,6 +600,8 @@ TEST(OsdTest, TestElementAmperage)
|
|||
// given
|
||||
osdConfigMutable()->item_pos[OSD_CURRENT_DRAW] = OSD_POS(1, 12) | OSD_PROFILE_1_FLAG;
|
||||
|
||||
osdAnalyzeActiveElements();
|
||||
|
||||
// when
|
||||
simulationBatteryAmperage = 0;
|
||||
displayClearScreen(&testDisplayPort);
|
||||
|
@ -628,6 +635,8 @@ TEST(OsdTest, TestElementMahDrawn)
|
|||
// given
|
||||
osdConfigMutable()->item_pos[OSD_MAH_DRAWN] = OSD_POS(1, 11) | OSD_PROFILE_1_FLAG;
|
||||
|
||||
osdAnalyzeActiveElements();
|
||||
|
||||
// when
|
||||
simulationMahDrawn = 0;
|
||||
displayClearScreen(&testDisplayPort);
|
||||
|
@ -677,6 +686,8 @@ TEST(OsdTest, TestElementPower)
|
|||
// given
|
||||
osdConfigMutable()->item_pos[OSD_POWER] = OSD_POS(1, 10) | OSD_PROFILE_1_FLAG;
|
||||
|
||||
osdAnalyzeActiveElements();
|
||||
|
||||
// and
|
||||
simulationBatteryVoltage = 1000; // 10V
|
||||
|
||||
|
@ -739,6 +750,8 @@ TEST(OsdTest, TestElementAltitude)
|
|||
// given
|
||||
osdConfigMutable()->item_pos[OSD_ALTITUDE] = OSD_POS(23, 7) | OSD_PROFILE_1_FLAG;
|
||||
|
||||
osdAnalyzeActiveElements();
|
||||
|
||||
// and
|
||||
osdConfigMutable()->units = OSD_UNIT_METRIC;
|
||||
sensorsClear(SENSOR_GPS);
|
||||
|
@ -800,6 +813,8 @@ TEST(OsdTest, TestElementCoreTemperature)
|
|||
// given
|
||||
osdConfigMutable()->item_pos[OSD_CORE_TEMPERATURE] = OSD_POS(1, 8) | OSD_PROFILE_1_FLAG;
|
||||
|
||||
osdAnalyzeActiveElements();
|
||||
|
||||
// and
|
||||
osdConfigMutable()->units = OSD_UNIT_METRIC;
|
||||
|
||||
|
@ -846,6 +861,8 @@ TEST(OsdTest, TestElementWarningsBattery)
|
|||
osdWarnSetState(OSD_WARNING_BATTERY_CRITICAL, true);
|
||||
osdWarnSetState(OSD_WARNING_BATTERY_NOT_FULL, true);
|
||||
|
||||
osdAnalyzeActiveElements();
|
||||
|
||||
// and
|
||||
batteryConfigMutable()->vbatfullcellvoltage = 410;
|
||||
|
||||
|
|
|
@ -40,9 +40,10 @@ extern "C" {
|
|||
|
||||
#include "scheduler/scheduler.h"
|
||||
#include "io/rcdevice_cam.h"
|
||||
#include "io/osd.h"
|
||||
#include "io/rcdevice.h"
|
||||
|
||||
#include "osd/osd.h"
|
||||
|
||||
#include "pg/pg.h"
|
||||
#include "pg/pg_ids.h"
|
||||
#include "pg/vcd.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue