
This is a big one where I can finally reap what I sown. Sub menu entries now provide two functions, one to get the text for the current value and one to apply changes aka save to EEPROM. With this I can replace so much code in the menu() function that handles input, but was _almost_ identical. The process of converting the old menus are not completed, and I can probably remove about 200 lines more code. The question is still what to do with less general menus like the rotator and fast patch menu. One problem with the current implementation is that it is RAM heavy. It seems the const MenuEntry structs are placed in ram, because there is a pointer to RAM that I assume is allocated during execution and therefore the address cannot be stored in ROM. My plan has been to put all the configuration fields (that are stored in EEPROM) into a struct or an array. When that is implemented, I can instead store the offset into the array in the const struct, which should be available at compile time and therefore can reside completely in ROM.
86 lines
1.3 KiB
C
86 lines
1.3 KiB
C
#ifndef __NUMENU_H
|
|
#define __NUMENU_H
|
|
|
|
//***********************************************************
|
|
|
|
enum MenuType {
|
|
ESub,
|
|
ESubNew,
|
|
ESubRotator,
|
|
EStateChange,
|
|
};
|
|
|
|
struct MenuEntry {
|
|
enum MenuType type;
|
|
const char* title;
|
|
};
|
|
|
|
struct MenuEntrySub {
|
|
enum MenuType type;
|
|
const char* title;
|
|
const char* subTitle;
|
|
byte* flag;
|
|
void (*subMenuFunc)(int color);
|
|
};
|
|
|
|
enum MenuEntryFlags {
|
|
ENone = 0,
|
|
EWrap = (1<<0),
|
|
ECustom = (1<<1),
|
|
};
|
|
|
|
struct MenuEntrySubNew {
|
|
enum MenuType type;
|
|
const char* title;
|
|
const char* subTitle;
|
|
uint16_t* valuePtr;
|
|
uint16_t min;
|
|
uint16_t max;
|
|
uint16_t flags;
|
|
void (*getSubTextFunc)(char*textBuffer, const char**label);
|
|
void (*applyFunc)(void);
|
|
};
|
|
|
|
|
|
struct MenuEntrySubRotator {
|
|
enum MenuType type;
|
|
const char* title;
|
|
const char* subTitle;
|
|
byte flagValue;
|
|
byte* flag;
|
|
void (*subMenuFunc)(int color);
|
|
};
|
|
|
|
struct MenuEntryStateCh {
|
|
enum MenuType type;
|
|
const char* title;
|
|
byte state;
|
|
};
|
|
|
|
struct MenuPage {
|
|
const char* title;
|
|
byte cursor;
|
|
byte parentPage;
|
|
byte numEntries;
|
|
const MenuEntry** entries;
|
|
};
|
|
|
|
|
|
//***********************************************************
|
|
|
|
|
|
|
|
struct AdjustValue {
|
|
uint16_t *value;
|
|
uint16_t limitLow;
|
|
uint16_t limitHigh;
|
|
};
|
|
|
|
struct AdjustMenuEntry {
|
|
const char* title;
|
|
AdjustValue entries[2];
|
|
void (*saveFunc)(const AdjustMenuEntry&);
|
|
};
|
|
|
|
|
|
#endif
|