From 012058a9bca2e6231a15b51b45f5becfe7daa83a Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Mon, 28 May 2018 17:47:03 -0400 Subject: [PATCH] Reduce flash usage in OSD element display logic Saves 132 bytes of flash. --- src/main/io/osd.c | 67 ++++++++++++++++++++++++++++++------------------------- src/main/io/osd.h | 3 +++ 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 3637b19ec..7da641964 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -167,6 +167,39 @@ static const char compassBar[] = { SYM_HEADING_LINE, SYM_HEADING_DIVIDED_LINE, SYM_HEADING_LINE }; +static const uint8_t osdElementDisplayOrder[] = { + OSD_MAIN_BATT_VOLTAGE, + OSD_RSSI_VALUE, + OSD_CROSSHAIRS, + OSD_HORIZON_SIDEBARS, + OSD_ITEM_TIMER_1, + OSD_ITEM_TIMER_2, + OSD_REMAINING_TIME_ESTIMATE, + OSD_FLYMODE, + OSD_THROTTLE_POS, + OSD_VTX_CHANNEL, + OSD_CURRENT_DRAW, + OSD_MAH_DRAWN, + OSD_CRAFT_NAME, + OSD_ALTITUDE, + OSD_ROLL_PIDS, + OSD_PITCH_PIDS, + OSD_YAW_PIDS, + OSD_POWER, + OSD_PIDRATE_PROFILE, + OSD_WARNINGS, + OSD_AVG_CELL_VOLTAGE, + OSD_DEBUG, + OSD_PITCH_ANGLE, + OSD_ROLL_ANGLE, + OSD_MAIN_BATT_USAGE, + OSD_DISARMED, + OSD_NUMERICAL_HEADING, + OSD_NUMERICAL_VARIO, + OSD_COMPASS_BAR, + OSD_ANTI_GRAVITY +}; + PG_REGISTER_WITH_RESET_FN(osdConfig_t, osdConfig, PG_OSD_CONFIG, 3); /** @@ -916,36 +949,10 @@ static void osdDrawElements(void) osdDrawSingleElement(OSD_ARTIFICIAL_HORIZON); } - osdDrawSingleElement(OSD_MAIN_BATT_VOLTAGE); - osdDrawSingleElement(OSD_RSSI_VALUE); - osdDrawSingleElement(OSD_CROSSHAIRS); - osdDrawSingleElement(OSD_HORIZON_SIDEBARS); - osdDrawSingleElement(OSD_ITEM_TIMER_1); - osdDrawSingleElement(OSD_ITEM_TIMER_2); - osdDrawSingleElement(OSD_REMAINING_TIME_ESTIMATE); - osdDrawSingleElement(OSD_FLYMODE); - osdDrawSingleElement(OSD_THROTTLE_POS); - osdDrawSingleElement(OSD_VTX_CHANNEL); - osdDrawSingleElement(OSD_CURRENT_DRAW); - osdDrawSingleElement(OSD_MAH_DRAWN); - osdDrawSingleElement(OSD_CRAFT_NAME); - osdDrawSingleElement(OSD_ALTITUDE); - osdDrawSingleElement(OSD_ROLL_PIDS); - osdDrawSingleElement(OSD_PITCH_PIDS); - osdDrawSingleElement(OSD_YAW_PIDS); - osdDrawSingleElement(OSD_POWER); - osdDrawSingleElement(OSD_PIDRATE_PROFILE); - osdDrawSingleElement(OSD_WARNINGS); - osdDrawSingleElement(OSD_AVG_CELL_VOLTAGE); - osdDrawSingleElement(OSD_DEBUG); - osdDrawSingleElement(OSD_PITCH_ANGLE); - osdDrawSingleElement(OSD_ROLL_ANGLE); - osdDrawSingleElement(OSD_MAIN_BATT_USAGE); - osdDrawSingleElement(OSD_DISARMED); - osdDrawSingleElement(OSD_NUMERICAL_HEADING); - osdDrawSingleElement(OSD_NUMERICAL_VARIO); - osdDrawSingleElement(OSD_COMPASS_BAR); - osdDrawSingleElement(OSD_ANTI_GRAVITY); + + for (unsigned i = 0; i < sizeof(osdElementDisplayOrder); i++) { + osdDrawSingleElement(osdElementDisplayOrder[i]); + } #ifdef USE_GPS if (sensors(SENSOR_GPS)) { diff --git a/src/main/io/osd.h b/src/main/io/osd.h index 43a828ede..644ed0718 100644 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -49,6 +49,9 @@ extern const char * const osdTimerSourceNames[OSD_NUM_TIMER_TYPES]; // NB: to ensure backwards compatibility, new enum values must be appended at the end but before the OSD_XXXX_COUNT entry. +// *** IMPORTANT *** +// If you are adding additional elements that do not require any conditional display logic, +// you must add the elements to the osdElementDisplayOrder[] array in src/main/io/osd.c typedef enum { OSD_RSSI_VALUE, OSD_MAIN_BATT_VOLTAGE, -- 2.11.4.GIT