diff --git a/MenuEntry.cpp b/MenuEntry.cpp index 1201270..1b6cc5f 100644 --- a/MenuEntry.cpp +++ b/MenuEntry.cpp @@ -19,7 +19,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI */ -#include +#include #include "MenuEntry.h" #include "MenuManager.h" diff --git a/MenuEntry.h b/MenuEntry.h index 7ce0d9c..9c8c556 100644 --- a/MenuEntry.h +++ b/MenuEntry.h @@ -19,7 +19,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI */ -#include +#include #ifndef MenuEntry_h #define MenuEntry_h 1 diff --git a/MenuLCD.cpp b/MenuLCD.cpp index 93f8713..b7d5af8 100644 --- a/MenuLCD.cpp +++ b/MenuLCD.cpp @@ -18,7 +18,7 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include "MenuLCD.h" @@ -49,11 +49,11 @@ bool MenuLCD::PrintMenu( char* pString[], int nLines, int nSelectedLine = 0 ) if( i == nSelectedLine ) {//this line should be surrounded by [] m_pLCD->setCursor(0, i); - m_pLCD->write( '['); + m_pLCD->write( '>'); m_pLCD->setCursor(1,i); m_pLCD->print( pString[i] ); m_pLCD->setCursor(m_characters - 1, i); - m_pLCD->write( ']'); + //m_pLCD->write( ']'); } else { diff --git a/MenuManager.cpp b/MenuManager.cpp index 1f2afc2..ebc8e4b 100644 --- a/MenuManager.cpp +++ b/MenuManager.cpp @@ -29,6 +29,14 @@ MenuManager::MenuManager(MenuLCD* pMenuLCD) { } +// new Constructor which allows us to define in class if we want actions being executed +// on menus which have a child - or not. +MenuManager::MenuManager(MenuLCD* pMenuLCD, bool execRootAction ): m_pMenuLCD( pMenuLCD), m_fDoingIntInput( false ) { + m_execRootMenuAction = execRootAction ; +} + + + bool MenuManager::addMenuRoot( MenuEntry * p_menuItem) { m_pRootMenuEntry = p_menuItem; @@ -178,7 +186,16 @@ void MenuManager::MenuDown() } void MenuManager::MenuSelect() -{ +{ + + // + // EDIT: Changed library to always do a callback even if the + // menu has a child. This allows me to keep track of the menu we are in. + // + if ( m_execRootMenuAction == true) { + m_pCurrentMenuEntry->ExecuteCallback(); + } + MenuEntry *child = m_pCurrentMenuEntry->getChild(); if( child != NULL ) { diff --git a/MenuManager.h b/MenuManager.h index 799635e..5ec41d3 100644 --- a/MenuManager.h +++ b/MenuManager.h @@ -28,7 +28,9 @@ enum MENU_ACTION { MENU_ACTION_UP, MENU_ACTION_DOWN, MENU_ACTION_SELECT, MENU_AC class MenuManager { public: - MenuManager(MenuLCD* pMenuLCD); + MenuManager(MenuLCD* pMenuLCD); + MenuManager(MenuLCD* pMenuLCD, bool rootAction); + bool addMenuRoot( MenuEntry * p_menuEntry); MenuEntry * getMenuRoot(); void DrawMenu(); @@ -54,7 +56,9 @@ class MenuManager unsigned int m_fDoingIntInput; MenuIntHelper *m_pMenuIntHelper; int m_iIntLine; - int *m_pInt; + int *m_pInt; + bool m_execRootMenuAction; + }; diff --git a/readme b/README.md similarity index 87% rename from readme rename to README.md index 305a985..d1902c2 100644 --- a/readme +++ b/README.md @@ -1,11 +1,23 @@ -Adruino_LCD_MENU README +# Adruino_LCD_MENU README -By David Andrews - May 6, 2012 +Original library: By David Andrews - May 6, 2012 + +Modified by Tweep, February 2017 License: Modified BSD (See complete license at end) Purpose: To shorten the time to get an Adriuno project running using a menuing system. + +Changes : + - new constructor added which allows to enable / disable the execution of callback functions when the root + menu has been selected. + + const bool doRootAction = false; + MenuLCD g_menuLCD( LCDRS, LCDE, LCDD4, LCDD5, LCDD6, LCDD7, 16, 2); + MenuManager g_menuManager( &g_menuLCD, doRootAction); + + Getting Started: Open the Arduino_Menu_LCD.ino sketch in the Arduino IDE. Upload the sketch. In the serial window, send the following keys to control the menu: u - move UP diff --git a/Arduino_LCD_Menu.ino b/examples/Arduino_LCD_Menu/Arduino_LCD_Menu.ino similarity index 100% rename from Arduino_LCD_Menu.ino rename to examples/Arduino_LCD_Menu/Arduino_LCD_Menu.ino