/*
Arduino_LCD_Menu Library
Copyright Dustin Andrews, David Andrews 2012
Licensed under the follwing license:
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the distribution.
The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "MenuManager.h"
#include "MenuEntry.h"
MenuManager::MenuManager(MenuLCD* pMenuLCD)
: m_pMenuLCD( pMenuLCD),
m_fDoingIntInput( false )
{
}
bool MenuManager::addMenuRoot( MenuEntry * p_menuItem)
{
m_pRootMenuEntry = p_menuItem;
m_pCurrentMenuEntry = p_menuItem;
}
void MenuManager::addSibling( MenuEntry * p_menuItem)
{
m_pCurrentMenuEntry->addSibling( p_menuItem );
}
void MenuManager::addChild( MenuEntry * p_menuItem)
{
m_pCurrentMenuEntry->addChild( p_menuItem );
}
MenuEntry * MenuManager::getMenuRoot()
{
return m_pRootMenuEntry;
}
void MenuManager::WipeMenu( MenuLCD::Direction dir )
{
if( dir == MenuLCD::LEFT )
{
for( int i = 0; i < m_pMenuLCD->getCharacters(); ++i )
{
m_pMenuLCD->getLCD()->scrollDisplayLeft();
delay(75);
}
}
else
{
for( int i = 0; i < m_pMenuLCD->getCharacters(); ++i )
{
m_pMenuLCD->getLCD()->scrollDisplayRight();
delay(75);
}
}
}
void MenuManager::DrawMenu()
{
if( m_pCurrentMenuEntry->getNextSibling() == NULL )
{
if( m_pCurrentMenuEntry->getPrevSibling() != NULL )
{
char *pMenuTexts[2] = {m_pCurrentMenuEntry->getPrevSibling()->getMenuText(), m_pCurrentMenuEntry->getMenuText()};
m_pMenuLCD->PrintMenu( pMenuTexts, 2, 1 );
}
else
{
char * pText = m_pCurrentMenuEntry->getMenuText();
m_pMenuLCD->PrintMenu( &pText, 1, 0 );
}
}
else
{
char *pMenuTexts[2] = {m_pCurrentMenuEntry->getMenuText(), m_pCurrentMenuEntry->getNextSibling()->getMenuText()};
m_pMenuLCD->PrintMenu( pMenuTexts, 2, 0 );
}
}
void MenuManager::DoMenuAction( MENU_ACTION action )
{
if( m_fDoingIntInput == true )
{
int iNewNum = m_pMenuIntHelper->getInt();
char buff[64];
switch (action )
{
case MENU_ACTION_UP:
iNewNum = m_pMenuIntHelper->numDecrease();
itoa( iNewNum, buff, 10 );
DrawInputRow( buff );
*m_pInt = iNewNum;
break;
case MENU_ACTION_DOWN:
iNewNum = m_pMenuIntHelper->numIncrease();
itoa( iNewNum, buff, 10 );
DrawInputRow( buff );
*m_pInt = iNewNum;
break;
case MENU_ACTION_SELECT:
m_fDoingIntInput = false;
DrawMenu();
break;
case MENU_ACTION_BACK:
m_fDoingIntInput = false;
DrawMenu();
break;
}
}
else
{
m_pMenuLCD->ClearLCD();
delay(10);
DrawMenu();
switch (action )
{
case MENU_ACTION_UP:
this->MenuUp();
break;
case MENU_ACTION_DOWN:
this->MenuDown();
break;
case MENU_ACTION_SELECT:
this->MenuSelect();
break;
case MENU_ACTION_BACK:
this->MenuBack();
break;
}
}
}
void MenuManager::MenuUp()
{
MenuEntry *prev = m_pCurrentMenuEntry->getPrevSibling();
if( prev != NULL )
{
m_pCurrentMenuEntry = prev;
}
else
{
//Flash?
}
DrawMenu();
}
void MenuManager::MenuDown()
{
MenuEntry *next = m_pCurrentMenuEntry->getNextSibling();
if( next != NULL )
{
m_pCurrentMenuEntry = next;
}
else
{
//Flash?
}
DrawMenu();
}
void MenuManager::MenuSelect()
{
MenuEntry *child = m_pCurrentMenuEntry->getChild();
if( child != NULL )
{
WipeMenu( MenuLCD::LEFT);
m_pCurrentMenuEntry = child;
DrawMenu();
}
else
{
if( !m_pCurrentMenuEntry->isBackEntry() )
{
WipeMenu( MenuLCD::LEFT);
}
m_pCurrentMenuEntry->ExecuteCallback();
if( !m_fDoingIntInput )
{
DrawMenu();
}
}
}
void MenuManager::MenuBack()
{
if( m_pCurrentMenuEntry->getParent() != NULL )
{
WipeMenu( MenuLCD::RIGHT);
m_pCurrentMenuEntry = m_pCurrentMenuEntry->getParent();
DrawMenu();
}
}
void MenuManager::SelectRoot()
{
m_pCurrentMenuEntry = m_pRootMenuEntry;
}
void MenuManager::DrawInputRow( char *pString )
{
m_pMenuLCD->PrintLineRight( pString, m_pMenuLCD->getLines() - 1 );
}
void MenuManager::DoIntInput( int iMin, int iMax, int iStart, int iSteps, char **label, int iLabelLines, int *pInt )
{
char buff[64];
m_fDoingIntInput = true;
m_pInt = pInt;
*pInt = iStart;
//The MenuIntHelper class will keep track of the input, but all other logic will stay here
if( m_pMenuIntHelper != NULL )
{
delete m_pMenuIntHelper;
}
m_pMenuIntHelper = new MenuIntHelper( iMin, iMax, iStart, iSteps );
//print the label
m_pMenuLCD->PrintMenu( label, iLabelLines, -1 );
m_iIntLine = iLabelLines; //Off by one because index is zero based
itoa( m_pMenuIntHelper->getInt(), buff, 10 );
DrawInputRow( buff );
}
没有合适的资源?快使用搜索试试~ 我知道了~
Arduino LCD 菜单设计
共10个文件
cpp:4个
h:4个
readme:1个
需积分: 50 24 下载量 99 浏览量
2017-11-22
12:29:11
上传
评论 3
收藏 17KB ZIP 举报
温馨提示
在Arduino上实现了LCD的分层菜单显示,要求LCD必须支持CrystalLiquid库
资源推荐
资源详情
资源评论
收起资源包目录
Arduino_LCD_Menu-master.zip (10个子文件)
Arduino_LCD_Menu-master
MenuManager.h 2KB
MenuLCD.h 2KB
Arduino_LCD_Menu.ino 11KB
MenuIntHelper.cpp 2KB
MenuEntry.cpp 3KB
MenuLCD.cpp 4KB
MenuIntHelper.h 2KB
MenuManager.cpp 6KB
readme 3KB
MenuEntry.h 4KB
共 10 条
- 1
资源评论
柠檬
- 粉丝: 1
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功