68 lines
2.1 KiB
C++
68 lines
2.1 KiB
C++
/*
|
|
* "Menu.h" defines the classe "Menuitem", which replaces the original macros used to
|
|
* instantiate the menus in the original code.
|
|
*/
|
|
|
|
#ifndef _MENU_H_ // Prevent double include
|
|
#define _MENU_H_
|
|
|
|
#include <Arduino.h> // Basic Arduino stuff
|
|
|
|
typedef void (*fptr)( int ); // Functions all take an integer argument
|
|
|
|
enum { MT_FUNC, MT_MENU, MT_CLOSE, MT_BACK, MT_END }; // Symbols for "type" of menu object
|
|
|
|
|
|
class Menuitem
|
|
{
|
|
public:
|
|
|
|
/*
|
|
* Four constructors; the first just creates a placeholder instance of the object.
|
|
*
|
|
* The second fills in the "type", button label and callback function address for
|
|
* "MT_FUNC" type objects.
|
|
*
|
|
* The third constructor is used for creating "MT_MENU" type objects. Its third
|
|
* argument is a pointer to a sub-menu to be displayed.
|
|
*
|
|
* The fourth constructor is used for the "MT_BACK" and "MT_END" type objects where
|
|
* we need only the type and maybe a label, but no menu or function pointer. Note
|
|
* that the "text" argument defaults to a NULL pointer for the "MT_END" type
|
|
* object.
|
|
*/
|
|
|
|
explicit Menuitem ();
|
|
explicit Menuitem ( uint8_t type, const char* text, fptr callback );
|
|
explicit Menuitem ( uint8_t type, const char* text, Menuitem* submenu );
|
|
explicit Menuitem ( uint8_t type, const char* text = NULL );
|
|
|
|
void Call ( int num ); // Executes the callback function
|
|
|
|
const char* Text1 (); // Returns the button label - line 1
|
|
const char* Text2 (); // Returns the button label - line 2 (or NULL)
|
|
|
|
uint8_t Type (); // Returns the menu item "type"
|
|
|
|
bool isMultiline (); // Returns "true" if a multiline label
|
|
|
|
Menuitem* GetSubmenu (); // For "MT_MENU" type object, returns the sub-menu pointer
|
|
|
|
|
|
private:
|
|
|
|
void ParseLabel ( const char* text ); // Parse two line labels
|
|
|
|
|
|
private: // All the data is private
|
|
|
|
uint8_t _type = -1; // Menu item type (invalid default)
|
|
const char* _text1 = NULL; // Label line 1
|
|
const char* _text2 = NULL; // Label line 2
|
|
fptr _callback = NULL; // Address of callback function
|
|
Menuitem* _submenu = NULL; // Address of a sub-menu
|
|
|
|
};
|
|
|
|
#endif
|