From 4a2a2c69d2a1c4744fc1e9b787097d8f7f7a4ded Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sun, 30 Oct 2022 00:31:09 +0000 Subject: [PATCH] Cart_Reader.ino: Deduplicate HW5 mainMenu pagination logic --- Cart_Reader/Cart_Reader.ino | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 7cbad04..ee13c96 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -913,6 +913,8 @@ static const char* const modeOptions[] PROGMEM = { modeItem1, modeItem2, modeIte void mainMenu() { // create menu with title and 15 options to choose from unsigned char modeMenu; + byte num_answers; + byte option_offset; // Main menu spans across two pages currPage = 1; @@ -921,23 +923,23 @@ void mainMenu() { while (1) { if (currPage == 1) { - // Copy menuOptions out of progmem - convertPgm(modeOptions + 0, 7); - modeMenu = question_box(F("OPEN SOURCE CART READER"), menuOptions, 7, 0); + option_offset = 0; + num_answers = 7; } if (currPage == 2) { - // Copy menuOptions out of progmem - convertPgm(modeOptions + 7, 7); - modeMenu = question_box(F("OPEN SOURCE CART READER"), menuOptions, 7, 0); + option_offset = 7; + num_answers = 7; } if (currPage == 3) { - // Copy menuOptions out of progmem - convertPgm(modeOptions + 14, 2); - modeMenu = question_box(F("OPEN SOURCE CART READER"), menuOptions, 2, 0); + option_offset = 14; + num_answers = 2; } + // 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) { // Execute choice - modeMenu = (currPage - 1) * 7 + modeMenu; + modeMenu += option_offset; break; } }