1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-25 01:05:21 +03:00

Add support for modifying settings directly in CMS (#2262)

* Add macros for injecting CMS key presses

Useful for testing and debugging

* Add support for CMS elements represented by just a bool function

Function is called for both getting and setting the value. Will
allow simplying the code for several CMS items.

* Use OME_BoolFunc on cms_menu_ledstrip.c

Allows removing a couple of static variables and replacing two
functions with just one.

* Add support for manipulating settings directly in CMS

Allows changing settings without intermediary values/functions,
reducing memory usage. Due to the required code to support this
feature we're using ~250 bytes of flash, but we're saving around
~300 bytes of RAM. However, eventually we should be able to migrate
all CMS code to use the settings API and end up saving flash space.
Also, the memory overhead per memory setting is now way smaller.

* Don't use SETTING_VBAT_* when the target doesn't use the ADC

Fixes build on COLIBRI

* Add support for CMS setting data types

This allows us to format angular rates without introducing a function
pointer for formatting on every CMS setting.

* Remove CMS_INJECTED_KEYS used for debugging

* Fix off-by-one error in setting_get_max() for MODE_LOOKUP values

Maximum value is one less than the number of entries in the table
This commit is contained in:
Alberto García Hierro 2017-10-07 13:02:44 +01:00 committed by GitHub
parent 206940461a
commit f1fb918803
9 changed files with 278 additions and 232 deletions

View file

@ -79,35 +79,16 @@ CMS_Menu cmsx_menuRcPreview = {
.entries = cmsx_menuRcEntries
};
static uint16_t motorConfig_minthrottle;
static uint8_t batteryConfig_vbatscale;
static uint8_t batteryConfig_vbatmaxcellvoltage;
static long cmsx_menuMiscOnEnter(void)
{
motorConfig_minthrottle = motorConfig()->minthrottle;
batteryConfig_vbatscale = batteryConfig()->vbatscale;
batteryConfig_vbatmaxcellvoltage = batteryConfig()->vbatmaxcellvoltage;
return 0;
}
static long cmsx_menuMiscOnExit(const OSD_Entry *self)
{
UNUSED(self);
motorConfigMutable()->minthrottle = motorConfig_minthrottle;
batteryConfigMutable()->vbatscale = batteryConfig_vbatscale;
batteryConfigMutable()->vbatmaxcellvoltage = batteryConfig_vbatmaxcellvoltage;
return 0;
}
static OSD_Entry menuMiscEntries[]=
{
{ "-- MISC --", OME_Label, NULL, NULL, 0 },
{ "MIN THR", OME_UINT16, NULL, &(OSD_UINT16_t){ &motorConfig_minthrottle, 1000, 2000, 1 }, 0 },
{ "VBAT SCALE", OME_UINT8, NULL, &(OSD_UINT8_t) { &batteryConfig_vbatscale, 1, 250, 1 }, 0 },
{ "VBAT CLMAX", OME_UINT8, NULL, &(OSD_UINT8_t) { &batteryConfig_vbatmaxcellvoltage, 10, 50, 1 }, 0 },
OSD_SETTING_ENTRY("MIN THR", SETTING_MIN_THROTTLE),
#ifdef USE_ADC
OSD_SETTING_ENTRY("VBAT SCALE", SETTING_VBAT_SCALE),
OSD_SETTING_ENTRY("VBAT CLMAX", SETTING_VBAT_MAX_CELL_VOLTAGE),
#endif
{ "RC PREV", OME_Submenu, cmsMenuChange, &cmsx_menuRcPreview, 0},
{ "BACK", OME_Back, NULL, NULL, 0},
@ -117,8 +98,8 @@ static OSD_Entry menuMiscEntries[]=
CMS_Menu cmsx_menuMisc = {
.GUARD_text = "XMISC",
.GUARD_type = OME_MENU,
.onEnter = cmsx_menuMiscOnEnter,
.onExit = cmsx_menuMiscOnExit,
.onEnter = NULL,
.onExit = NULL,
.onGlobalExit = NULL,
.entries = menuMiscEntries
};