Hi,
I'm trying to make a menuHandler which handles actions based on user input. The below code is only a partial extract of my code but it should describe the problem i am facing.
I have:
Main
|
--MenuHandler.h
|
--Menu.h
The menu.h defines the structure of the menu using char * constants and assign them to arrays. The resulting array of 'strings' is a single menu page. The first item in the array defines the menu name. So for example:
Root, itm1, itm2, itm3, itmBck
submenu1, itm4, itm5, itm6, itmBck
The problem I'm having is with; why is checkCurrentMenu() always returning false.I would expect that the first call to the method returns 1 and the second call would return 0
Note that i need to be able to pass the complete array for comparison as it's also used elsewhere. Also note that this is just a simplification of the logic i'm working with.
//
// Created by Raoul on 13/02/2020.
//
#include <Arduino.h>
#include "menuHandler.h"
void setup() {
Serial.begin(9600);
}
void loop() {
menuHandler handler;
Serial.print("Current menu is root: ");
Serial.println(handler.checkCurrentMenu(mnuRoot), DEC);
Serial.print ("Current menu is menu2: ");
Serial.println(handler.checkCurrentMenu(mnu2), DEC);
delay(1000);
}
//
// Created by Raoul on 13/02/2020.
//
#ifndef TEST_MENUHANDLER_H
#define TEST_MENUHANDLER_H
#include "menuItems.h"
class menuHandler {
public:
menuHandler();
bool checkCurrentMenu(const char * const * page);
};
#endif //TEST_MENUHANDLER_H
//
// Created by Raoul on 13/02/2020.
//
#include "menuHandler.h"
menuHandler::menuHandler() {}
bool menuHandler::checkCurrentMenu(const char* const * page) {
return (page == mnuRoot);
}
//
// Created by Raoul on 13/02/2020.
//
#include "menuHandler.h"
menuHandler::menuHandler() {}
bool menuHandler::checkCurrentMenu(const char* const * page) {
return (page == mnuRoot);
}
//
// Created by Raoul on 13/02/2020.
//
#ifndef TEST_MENUITEMS_H
#define TEST_MENUITEMS_H
#include <avr/pgmspace.h>
const char * const PROGMEM itmRoot= "Reflow Oven Menu";
const char * const PROGMEM itmMenu2 = "Menu2";
const char * const PROGMEM itmSave = "Save";
const char * const PROGMEM itmStart = "Start";
const char * const PROGMEM itmBack = "< Back";
const char * const mnuRoot[] PROGMEM = {itmRoot, itmMenu2, itmStart, itmBack};
const char *const mnu2[] PROGMEM = {itmMenu2, itmSave, itmStart, itmBack};
#endif //TEST_MENUITEMS_H
Output
Current menu is menu2: 0
Current menu is root: 0
Current menu is menu2: 0
Current menu is root: 0
Current menu is menu2: 0
Current menu is root: 0
Current menu is menu2: 0