Skip to content

Commit 5a81bfe

Browse files
committed
Numerous changes
1 parent de44e63 commit 5a81bfe

File tree

7 files changed

+169
-29
lines changed

7 files changed

+169
-29
lines changed

Arduino_LCD_Menu.ino

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,28 @@ long g_timerTarget = 0;
5050
long g_autoReset = false;
5151
long g_stopMillis = 0;
5252
long g_startMillis = 0;
53+
54+
byte g_smiley[8] = {
55+
B00000,
56+
B10001,
57+
B00000,
58+
B00000,
59+
B10001,
60+
B01110,
61+
B00000,
62+
};
63+
64+
byte g_frown[8] = {
65+
B00000,
66+
B10001,
67+
B00000,
68+
B00000,
69+
B00000,
70+
B01110,
71+
B10001,
72+
};
73+
74+
5375
//end Global variables section
5476

5577
//setupMenus
@@ -119,6 +141,11 @@ void setupMenus()
119141
g_menuManager.addSibling( new MenuEntry( "Credits", NULL, CreditsCallback) );
120142
//Make sure the menu is drawn correctly after all changes are done
121143
g_menuManager.DrawMenu();
144+
145+
g_menuManager.addSibling( new MenuEntry( "Draw Smiley", NULL, SmileyCallback) );
146+
147+
g_menuLCD.getLCD()->createChar( 0, g_smiley );
148+
g_menuLCD.getLCD()->createChar( 1, g_frown );
122149
}
123150

124151

@@ -273,3 +300,18 @@ void CreditsCallback( char* pMenuText, void *pUserData )
273300
g_isDisplaying = true;
274301
}
275302

303+
void SmileyCallback( char* pMenuText, void *pUserData )
304+
{
305+
for( int i = 0; i < 10 ; ++i )
306+
{
307+
g_menuLCD.ClearLCD();
308+
g_menuLCD.getLCD()->setCursor( 8,0 );
309+
g_menuLCD.getLCD()->print( (char)0 );
310+
delay(500);
311+
g_menuLCD.ClearLCD();
312+
g_menuLCD.getLCD()->setCursor( 8,0 );
313+
g_menuLCD.getLCD()->print( (char)1 );
314+
delay(500);
315+
}
316+
}
317+

MenuEntry.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
2727

2828
typedef void (*MENU_ACTION_CALLBACK_FUNC)( char * pMenuText, void * pUserData );
2929

30+
31+
//To use these functions, pass a function pointer as the argument to the MenuEntry constructor.
32+
//pUserData should point to an unsigned int that will be set to true or false.
33+
void MenuEntry_BoolTrueCallbackFunc( char * pMenuText, void * pUserData );
34+
void MenuEntry_BoolFalseCallbackFunc( char * pMenuText, void * pUserData );
35+
36+
//Use this callback function for a "Back" menu item for hardware that doesn't include a back button
37+
//pUserData should point to a MenfsuManager object.
38+
void MenuEntry_BackCallbackFunc( char * pMenuText, void * pUserData );
39+
3040
//The MenuEntry class represents one menu item in the overall menu system, such as "Set Time" or "Back"
3141
//The MenuEntry classes point to each other to create a tree of menu items. You can navigate
3242
// the classes using the get* calls. MenuManager uses the get* calls to figure out what to draw to the LCD
@@ -57,6 +67,8 @@ class MenuEntry
5767
//This call will call the action callback for use when the menu item is selected.
5868
//if this menu entry has any children, the callback will not be executed.
5969
void ExecuteCallback();
70+
71+
bool isBackEntry() { return (m_callback == MenuEntry_BackCallbackFunc); }
6072

6173

6274
private:
@@ -69,14 +81,6 @@ class MenuEntry
6981
MenuEntry* m_prevSibling;
7082
};
7183

72-
//To use these functions, pass a function pointer as the argument to the MenuEntry constructor.
73-
//pUserData should point to an unsigned int that will be set to true or false.
74-
void MenuEntry_BoolTrueCallbackFunc( char * pMenuText, void * pUserData );
75-
void MenuEntry_BoolFalseCallbackFunc( char * pMenuText, void * pUserData );
76-
77-
//Use this callback function for a "Back" menu item for hardware that doesn't include a back button
78-
//pUserData should point to a MenfsuManager object.
79-
void MenuEntry_BackCallbackFunc( char * pMenuText, void * pUserData );
8084

8185

8286
#endif

MenuIntHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int MenuIntHelper::numIncrease()
2828
{
2929
//This function may have bugs when m_max is near the MAXINT limit
3030
//but if your UI requires users to input MAXINT numbers, you have bigger problems.
31-
if( m_curNum + m_step < m_max )
31+
if( m_curNum + m_step <= m_max )
3232
{
3333
m_curNum += m_step;
3434
}

MenuLCD.cpp

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
1818
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1919
*/
2020

21-
21+
#include <arduino.h>
2222
#include <LiquidCrystal.h>
2323
#include "MenuLCD.h"
2424

@@ -36,34 +36,73 @@ MenuLCD::MenuLCD(int LCDRS, int LCDE, int LCDD4, int LCDD5, int LCDD6, int LCDD7
3636

3737
bool MenuLCD::MenuLCDSetup()
3838
{
39-
m_pLcd = new LiquidCrystal(m_LCDRS, m_LCDE, m_LCDD4, m_LCDD5, m_LCDD6, m_LCDD7);
40-
m_pLcd->begin(m_characters, m_lines);
39+
m_pLCD = new LiquidCrystal(m_LCDRS, m_LCDE, m_LCDD4, m_LCDD5, m_LCDD6, m_LCDD7);
40+
m_pLCD->begin(m_characters, m_lines);
4141
}
4242

4343
bool MenuLCD::PrintMenu( char* pString[], int nLines, int nSelectedLine = 0 )
4444
{
45-
m_pLcd->clear();
45+
m_pLCD->clear();
4646
for( int i =0; i < nLines; i++ )
4747

4848
{
4949
if( i == nSelectedLine )
5050
{//this line should be surrounded by []
51-
m_pLcd->setCursor(0, i);
52-
m_pLcd->write( '[');
53-
m_pLcd->setCursor(1,i);
54-
m_pLcd->print( pString[i] );
55-
m_pLcd->setCursor(m_characters - 1, i);
56-
m_pLcd->write( ']');
51+
m_pLCD->setCursor(0, i);
52+
m_pLCD->write( '[');
53+
m_pLCD->setCursor(1,i);
54+
m_pLCD->print( pString[i] );
55+
m_pLCD->setCursor(m_characters - 1, i);
56+
m_pLCD->write( ']');
5757
}
5858
else
5959
{
60-
m_pLcd->setCursor(0,i);
61-
m_pLcd->print( pString[i] );
60+
m_pLCD->setCursor(0,i);
61+
m_pLCD->print( pString[i] );
6262
}
6363

6464
}
6565
}
6666

67+
void MenuLCD::WipeMenu( char* pString[], int nLines, MenuLCD::Direction dir )
68+
{
69+
char lineBuff[ 256 ];
70+
m_pLCD->clear();
71+
for( int i = 0; i < m_characters; ++i )
72+
{
73+
for( int j =0; j < nLines; ++j )
74+
{
75+
m_pLCD->setCursor( 0, j );
76+
m_pLCD->setCursor(0,j);
77+
if (strlen( pString[j] ) > i )
78+
{
79+
if( dir == LEFT )
80+
{
81+
strcpy(lineBuff, (pString[j] + i ) );
82+
strcat(lineBuff, " " );
83+
}
84+
else
85+
{
86+
lineBuff[0] = '\0';
87+
for( int k = 0; k < i; ++k )
88+
{
89+
strcat(lineBuff, " " );
90+
}
91+
strcat(lineBuff, pString[j]);
92+
}
93+
}
94+
else
95+
{
96+
strcpy(lineBuff, " " );
97+
}
98+
m_pLCD->print( lineBuff );
99+
100+
}
101+
delay(50);
102+
}
103+
}
104+
105+
67106
bool MenuLCD::PrintLineRight( char* pString, int iRow )
68107
{
69108
//clear the line
@@ -72,11 +111,18 @@ bool MenuLCD::PrintLineRight( char* pString, int iRow )
72111
{
73112
buff[i] = ' ';
74113
}
75-
m_pLcd->setCursor( 0, iRow );
76-
m_pLcd->print( buff );
114+
m_pLCD->setCursor( 0, iRow );
115+
m_pLCD->print( buff );
77116
//now print the new number
78-
m_pLcd->setCursor(m_characters - strlen(pString),iRow);
79-
m_pLcd->print( pString );
117+
m_pLCD->setCursor(m_characters - strlen(pString),iRow);
118+
m_pLCD->print( pString );
119+
}
120+
121+
bool MenuLCD::PrintLine( char* pString, int iRow )
122+
{
123+
//clear the line
124+
m_pLCD->setCursor( 0, iRow );
125+
m_pLCD->print( pString );
80126
}
81127

82128
int MenuLCD::getLines()
@@ -89,5 +135,11 @@ int MenuLCD::getCharacters()
89135
}
90136
void MenuLCD::ClearLCD()
91137
{
92-
m_pLcd->clear();
138+
m_pLCD->clear();
93139
}
140+
141+
LiquidCrystal * MenuLCD::getLCD()
142+
{
143+
return m_pLCD;
144+
}
145+

MenuLCD.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@ class MenuLCD
3030
bool MenuLCDSetup();
3131
bool PrintMenu( char ** pString, int nLines, int nSelectedLine /*= 0*/ );
3232
bool PrintLineRight( char* pString, int iRow );
33+
bool PrintLine( char* pString, int iRow );
3334
int getLines();
3435
int getCharacters();
3536
void ClearLCD();
37+
LiquidCrystal * getLCD();
38+
39+
enum Direction{ LEFT, RIGHT };
40+
41+
42+
void WipeMenu( char* pString[], int nLines, MenuLCD::Direction dir );
43+
3644

3745
private:
38-
LiquidCrystal* m_pLcd;
46+
LiquidCrystal* m_pLCD;
3947
int m_LCDRS;
4048
int m_LCDE;
4149
int m_LCDD4;

MenuManager.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
1919
*/
2020

2121

22+
2223
#include "MenuManager.h"
2324
#include "MenuEntry.h"
2425

@@ -51,6 +52,26 @@ MenuEntry * MenuManager::getMenuRoot()
5152
}
5253

5354

55+
void MenuManager::WipeMenu( MenuLCD::Direction dir )
56+
{
57+
if( dir == MenuLCD::LEFT )
58+
{
59+
for( int i = 0; i < m_pMenuLCD->getCharacters(); ++i )
60+
{
61+
m_pMenuLCD->getLCD()->scrollDisplayLeft();
62+
delay(75);
63+
}
64+
}
65+
else
66+
{
67+
for( int i = 0; i < m_pMenuLCD->getCharacters(); ++i )
68+
{
69+
m_pMenuLCD->getLCD()->scrollDisplayRight();
70+
delay(75);
71+
}
72+
}
73+
}
74+
5475

5576
void MenuManager::DrawMenu()
5677
{
@@ -83,13 +104,13 @@ void MenuManager::DoMenuAction( MENU_ACTION action )
83104
switch (action )
84105
{
85106
case MENU_ACTION_UP:
86-
iNewNum = m_pMenuIntHelper->numIncrease();
107+
iNewNum = m_pMenuIntHelper->numDecrease();
87108
itoa( iNewNum, buff, 10 );
88109
DrawInputRow( buff );
89110
*m_pInt = iNewNum;
90111
break;
91112
case MENU_ACTION_DOWN:
92-
iNewNum = m_pMenuIntHelper->numDecrease();
113+
iNewNum = m_pMenuIntHelper->numIncrease();
93114
itoa( iNewNum, buff, 10 );
94115
DrawInputRow( buff );
95116
*m_pInt = iNewNum;
@@ -161,19 +182,29 @@ void MenuManager::MenuSelect()
161182
MenuEntry *child = m_pCurrentMenuEntry->getChild();
162183
if( child != NULL )
163184
{
185+
WipeMenu( MenuLCD::LEFT);
164186
m_pCurrentMenuEntry = child;
165187
DrawMenu();
166188
}
167189
else
168190
{
191+
if( !m_pCurrentMenuEntry->isBackEntry() )
192+
{
193+
WipeMenu( MenuLCD::LEFT);
194+
}
169195
m_pCurrentMenuEntry->ExecuteCallback();
196+
if( !m_fDoingIntInput )
197+
{
198+
DrawMenu();
199+
}
170200
}
171201
}
172202

173203
void MenuManager::MenuBack()
174204
{
175205
if( m_pCurrentMenuEntry->getParent() != NULL )
176206
{
207+
WipeMenu( MenuLCD::RIGHT);
177208
m_pCurrentMenuEntry = m_pCurrentMenuEntry->getParent();
178209
DrawMenu();
179210
}

MenuManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class MenuManager
4343
void DoIntInput( int iMin, int iMax, int iStart, int iSteps, char **label, int iLabelLines, int *pInt );
4444
void DrawInputRow( char *pString );
4545

46+
void WipeMenu( MenuLCD::Direction dir);
47+
48+
4649

4750
private:
4851
MenuEntry* m_pRootMenuEntry;

0 commit comments

Comments
 (0)