Cart_Reader.ino: Deduplicate HW5 mainMenu pagination logic

This commit is contained in:
Vincent Pelletier 2022-10-30 00:31:09 +00:00
parent a35c882662
commit 4a2a2c69d2

View File

@ -913,6 +913,8 @@ static const char* const modeOptions[] PROGMEM = { modeItem1, modeItem2, modeIte
void mainMenu() { void mainMenu() {
// create menu with title and 15 options to choose from // create menu with title and 15 options to choose from
unsigned char modeMenu; unsigned char modeMenu;
byte num_answers;
byte option_offset;
// Main menu spans across two pages // Main menu spans across two pages
currPage = 1; currPage = 1;
@ -921,23 +923,23 @@ void mainMenu() {
while (1) { while (1) {
if (currPage == 1) { if (currPage == 1) {
// Copy menuOptions out of progmem option_offset = 0;
convertPgm(modeOptions + 0, 7); num_answers = 7;
modeMenu = question_box(F("OPEN SOURCE CART READER"), menuOptions, 7, 0);
} }
if (currPage == 2) { if (currPage == 2) {
// Copy menuOptions out of progmem option_offset = 7;
convertPgm(modeOptions + 7, 7); num_answers = 7;
modeMenu = question_box(F("OPEN SOURCE CART READER"), menuOptions, 7, 0);
} }
if (currPage == 3) { if (currPage == 3) {
// Copy menuOptions out of progmem option_offset = 14;
convertPgm(modeOptions + 14, 2); num_answers = 2;
modeMenu = question_box(F("OPEN SOURCE CART READER"), menuOptions, 2, 0);
} }
// Copy menuOptions out of progmem
convertPgm(modeOptions + option_offset, num_answers);
modeMenu = question_box(F("OPEN SOURCE CART READER"), menuOptions, num_answers, 0);
if (numPages == 0) { if (numPages == 0) {
// Execute choice // Execute choice
modeMenu = (currPage - 1) * 7 + modeMenu; modeMenu += option_offset;
break; break;
} }
} }