196 lines
3.4 KiB
C++
196 lines
3.4 KiB
C++
#include "screen/menu.h"
|
|
#include "config.h"
|
|
#include "buzzer.h"
|
|
#include "display.h"
|
|
#include "state.h"
|
|
|
|
#include "menu/start.h"
|
|
#include "menu/time.h"
|
|
#include "menu/intensity.h"
|
|
#include "menu/sound.h"
|
|
|
|
|
|
MenuScreen::MenuScreen(ScreenManager* screenManager) : BaseScreen(screenManager)
|
|
{
|
|
mCount = 4;
|
|
mItems = new MenuItem*[mCount];
|
|
|
|
mItems[0] = new StartMenuItem();
|
|
mItems[1] = new TimeMenuItem();
|
|
mItems[2] = new IntensityMenuItem();
|
|
mItems[3] = new SoundMenuItem();
|
|
}
|
|
|
|
|
|
MenuScreen::~MenuScreen()
|
|
{
|
|
for (uint8_t i = 0; i < mCount; i++)
|
|
delete mItems[i];
|
|
|
|
delete[] mItems;
|
|
}
|
|
|
|
|
|
void MenuScreen::onShow()
|
|
{
|
|
printFullUpdate();
|
|
}
|
|
|
|
|
|
void MenuScreen::onHide()
|
|
{
|
|
}
|
|
|
|
|
|
void MenuScreen::printFullUpdate()
|
|
{
|
|
printTitle();
|
|
printScrollIndicators();
|
|
printValue();
|
|
}
|
|
|
|
|
|
void MenuScreen::printTitle()
|
|
{
|
|
const char* title = mItems[mSelected]->getTitle();
|
|
LCDPrintLineCentered(getDisplay(), 0, title, 1);
|
|
|
|
if (title != NULL)
|
|
delete[] title;
|
|
}
|
|
|
|
|
|
void MenuScreen::printScrollIndicators()
|
|
{
|
|
LiquidCrystal* display = getDisplay();
|
|
|
|
display->setCursor(0, 0);
|
|
if (mSelected > 0)
|
|
display->write(mEditing ? LCDCharArrowLeftHollow : LCDCharArrowLeft);
|
|
else
|
|
display->write(' ');
|
|
|
|
display->setCursor(LCDWidth - 1, 0);
|
|
if (mSelected < mCount - 1)
|
|
display->write(mEditing ? LCDCharArrowRightHollow : LCDCharArrowRight);
|
|
else
|
|
display->write(' ');
|
|
}
|
|
|
|
|
|
void MenuScreen::printValue()
|
|
{
|
|
LiquidCrystal* display = getDisplay();
|
|
|
|
const char* value = mItems[mSelected]->getValue();
|
|
|
|
if (mEditing && value != NULL)
|
|
{
|
|
uint8_t valueLength = strlen(value);
|
|
char* editingValue = new char[valueLength + 5];
|
|
|
|
editingValue[0] = ' ';
|
|
editingValue[1] = ' ';
|
|
strcpy(editingValue + 2, value);
|
|
editingValue[valueLength + 2] = ' ';
|
|
|
|
bool canIncrement = mItems[mSelected]->canIncrement();
|
|
bool canDecrement = mItems[mSelected]->canDecrement();
|
|
|
|
if (canIncrement && canDecrement)
|
|
editingValue[valueLength + 3] = LCDCharUpDown;
|
|
else if (canIncrement)
|
|
editingValue[valueLength + 3] = LCDCharUp;
|
|
else if (canDecrement)
|
|
editingValue[valueLength + 3] = LCDCharDown;
|
|
else
|
|
editingValue[valueLength + 3] = ' ';
|
|
|
|
editingValue[valueLength + 4] = 0;
|
|
|
|
LCDPrintLineCentered(display, 1, editingValue);
|
|
|
|
delete[] editingValue;
|
|
}
|
|
else
|
|
LCDPrintLineCentered(display, 1, value);
|
|
|
|
if (value != NULL)
|
|
delete[] value;
|
|
}
|
|
|
|
|
|
|
|
void MenuScreen::onButton()
|
|
{
|
|
if (mItems[mSelected]->editable())
|
|
{
|
|
Buzzer::select();
|
|
|
|
if (mEditing)
|
|
SaveSettings();
|
|
|
|
mEditing = !mEditing;
|
|
printScrollIndicators();
|
|
printValue();
|
|
}
|
|
else
|
|
{
|
|
mItems[mSelected]->execute(getScreenManager(), getCurrentTime());
|
|
}
|
|
}
|
|
|
|
|
|
void MenuScreen::onEncoder(int32_t lastPosition, int32_t newPosition)
|
|
{
|
|
if (mEditing)
|
|
{
|
|
if (newPosition > lastPosition)
|
|
{
|
|
if (mItems[mSelected]->canIncrement())
|
|
{
|
|
mItems[mSelected]->incrementValue();
|
|
Buzzer::select();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (mItems[mSelected]->canDecrement())
|
|
{
|
|
mItems[mSelected]->decrementValue();
|
|
Buzzer::select();
|
|
}
|
|
}
|
|
|
|
printValue();
|
|
}
|
|
else
|
|
{
|
|
if (newPosition > lastPosition)
|
|
{
|
|
if (mSelected < mCount - 1)
|
|
{
|
|
Buzzer::select();
|
|
mSelected++;
|
|
|
|
printFullUpdate();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (mSelected > 0)
|
|
{
|
|
Buzzer::select();
|
|
mSelected--;
|
|
|
|
printFullUpdate();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void MenuScreen::onTick()
|
|
{
|
|
}
|