Handle sub menus in a generic way and moved adjust menu logic to separate file

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.
This commit is contained in:
Mikael Degerfält 2019-06-22 14:25:31 +02:00
parent ca5b2b9484
commit 699546df8c
6 changed files with 724 additions and 762 deletions

View file

@ -4,8 +4,8 @@
#include "Wiring.h"
#define MENU_ROW_HEIGHT 9
#define MENU_HEADER_OFFSET 3
#define MENU_NUM_ROWS 5
#define MENU_HEADER_OFFSET 12
#define MENU_NUM_ROWS 6
//display states
#define DISPLAYOFF_IDL 0
@ -17,6 +17,23 @@
#define ROTATOR_MENU 100
#define VIBRATO_MENU 110
#define ARR_LEN(a) (sizeof (a) / sizeof (a[0]))
#define BTN_DOWN 1
#define BTN_ENTER 2
#define BTN_UP 4
#define BTN_MENU 8
extern const unsigned long debounceDelay; // the debounce time; increase if the output flickers
extern const unsigned long buttonRepeatInterval;
extern const unsigned long buttonRepeatDelay;
extern const unsigned long cursorBlinkInterval; // the cursor blink toggle interval time
extern const unsigned long patchViewTimeUp; // ms until patch view shuts off
extern const unsigned long menuTimeUp; // menu shuts off after one minute of button inactivity
extern byte subVibSquelch;
@ -27,4 +44,7 @@ void drawSensorPixels();
unsigned short readSetting(byte address);
void writeSetting(byte address, unsigned short value);
int updateAdjustMenu(uint32_t timeNow, uint8_t buttons, bool firstRun, bool updateSensor);
#endif