2020-01-28 15:52:18 +00:00
|
|
|
#include "./home.h"
|
2020-01-30 14:16:52 +00:00
|
|
|
#include "./move.h"
|
2020-02-01 15:55:33 +00:00
|
|
|
#include "./move-sensorerror.h"
|
2020-01-30 09:28:01 +00:00
|
|
|
#include "include/config.h"
|
2020-01-31 11:22:06 +00:00
|
|
|
#include "include/metrics.h"
|
2020-01-30 09:28:01 +00:00
|
|
|
#include "lib/settings.h"
|
2020-01-31 11:22:06 +00:00
|
|
|
#include "lib/control.h"
|
2020-01-31 15:50:19 +00:00
|
|
|
#include "lib/state.h"
|
2020-01-31 09:36:36 +00:00
|
|
|
#include "./menu.h"
|
2020-01-30 09:28:01 +00:00
|
|
|
|
|
|
|
|
2020-01-28 15:52:18 +00:00
|
|
|
|
|
|
|
void HomeScreen::onShow()
|
|
|
|
{
|
2020-01-31 15:50:19 +00:00
|
|
|
this->showTime = CurrentTime;
|
2020-01-30 09:28:01 +00:00
|
|
|
|
2020-02-01 15:55:33 +00:00
|
|
|
this->display->setFont(Metrics::LargeFont);
|
|
|
|
this->display->setTextSize(Metrics::LargeFontTextSize);
|
2020-01-28 15:52:18 +00:00
|
|
|
|
2020-02-01 15:55:33 +00:00
|
|
|
this->display->fillScreen(Config::ColorHomeBackground);
|
2020-01-30 09:28:01 +00:00
|
|
|
|
|
|
|
this->drawPreset1();
|
|
|
|
this->drawMenu();
|
|
|
|
this->drawPreset2();
|
2020-01-28 15:52:18 +00:00
|
|
|
|
2020-01-30 19:06:13 +00:00
|
|
|
this->drawNonPresetHeight();
|
2020-01-28 15:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HomeScreen::onButton(Button button)
|
|
|
|
{
|
2020-01-30 15:01:26 +00:00
|
|
|
if (this->idle)
|
|
|
|
{
|
2020-02-01 15:55:33 +00:00
|
|
|
this->screenManager->displayOn();
|
2020-01-30 15:01:26 +00:00
|
|
|
this->idle = false;
|
2020-01-31 15:50:19 +00:00
|
|
|
this->showTime = CurrentTime;
|
2020-01-30 15:01:26 +00:00
|
|
|
|
2020-01-31 11:22:06 +00:00
|
|
|
// Preset buttons activate immediately
|
2020-02-01 15:55:33 +00:00
|
|
|
if (button == Button::Middle)
|
2020-01-31 11:22:06 +00:00
|
|
|
return;
|
2020-01-30 15:01:26 +00:00
|
|
|
}
|
|
|
|
|
2020-02-01 15:55:33 +00:00
|
|
|
uint16_t targetHeight;
|
|
|
|
|
2020-01-30 14:16:52 +00:00
|
|
|
switch (button)
|
|
|
|
{
|
2020-02-01 15:55:33 +00:00
|
|
|
case Button::Top:
|
|
|
|
targetHeight = Settings.Height.Preset[0];
|
2020-01-30 14:16:52 +00:00
|
|
|
break;
|
|
|
|
|
2020-02-01 15:55:33 +00:00
|
|
|
case Button::Bottom:
|
|
|
|
targetHeight = Settings.Height.Preset[1];
|
2020-01-30 14:16:52 +00:00
|
|
|
break;
|
|
|
|
|
2020-02-01 15:55:33 +00:00
|
|
|
case Button::Middle:
|
|
|
|
this->screenManager->show<MenuScreen>();
|
|
|
|
return;
|
2020-01-30 14:16:52 +00:00
|
|
|
}
|
2020-02-01 15:55:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
Control.moveStart(targetHeight);
|
|
|
|
this->screenManager->show<MoveScreen>();
|
2020-01-28 15:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HomeScreen::onTick()
|
|
|
|
{
|
2020-01-31 15:50:19 +00:00
|
|
|
if (!this->idle && CurrentTime - this->showTime >= Config::DisplayIdleTime)
|
2020-01-30 15:01:26 +00:00
|
|
|
{
|
2020-02-01 15:55:33 +00:00
|
|
|
this->screenManager->displayOff();
|
2020-01-30 15:01:26 +00:00
|
|
|
this->idle = true;
|
|
|
|
}
|
2020-01-30 09:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HomeScreen::drawPreset1()
|
|
|
|
{
|
2020-01-31 11:22:06 +00:00
|
|
|
this->drawPreset(0, Settings.Height.Preset[0]);
|
2020-01-30 09:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HomeScreen::drawPreset2()
|
|
|
|
{
|
2020-01-31 11:22:06 +00:00
|
|
|
this->drawPreset(Config::DisplayHeight - Metrics::LargeTextLineHeight, Settings.Height.Preset[1]);
|
2020-01-30 19:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HomeScreen::drawNonPresetHeight()
|
|
|
|
{
|
2020-01-31 11:22:06 +00:00
|
|
|
auto y = Metrics::LargeTextLineHeight;
|
2020-01-30 19:06:13 +00:00
|
|
|
|
2020-01-31 15:50:19 +00:00
|
|
|
if (Control.getCurrentHeight() != Settings.Height.Preset[0] &&
|
|
|
|
Control.getCurrentHeight() != Settings.Height.Preset[1])
|
2020-01-30 19:06:13 +00:00
|
|
|
{
|
2020-02-01 15:55:33 +00:00
|
|
|
this->display->setTextColor(Config::ColorNonPresetText);
|
2020-01-31 15:50:19 +00:00
|
|
|
this->drawHeight(y, Control.getCurrentHeight());
|
2020-01-30 19:06:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-31 09:36:36 +00:00
|
|
|
void HomeScreen::drawPreset(int16_t y, uint16_t value)
|
2020-01-30 09:28:01 +00:00
|
|
|
{
|
|
|
|
uint16_t textColor;
|
|
|
|
uint16_t backgroundColor;
|
2020-01-30 19:06:13 +00:00
|
|
|
uint16_t arrowColor;
|
2020-01-30 09:28:01 +00:00
|
|
|
|
|
|
|
// An exact comparison is enough here, the movement code takes care of that if it's "close enough"
|
2020-01-31 15:50:19 +00:00
|
|
|
if (value == Control.getCurrentHeight())
|
2020-01-30 09:28:01 +00:00
|
|
|
{
|
|
|
|
textColor = Config::ColorPresetSelectedText;
|
|
|
|
backgroundColor = Config::ColorPresetSelectedBackground;
|
2020-01-30 19:06:13 +00:00
|
|
|
arrowColor = 0;
|
2020-01-30 09:28:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textColor = Config::ColorPresetText;
|
|
|
|
backgroundColor = Config::ColorPresetBackground;
|
2020-01-31 09:36:36 +00:00
|
|
|
arrowColor = Config::ColorPresetArrow;
|
2020-01-30 09:28:01 +00:00
|
|
|
}
|
|
|
|
|
2020-02-01 15:55:33 +00:00
|
|
|
this->display->fillRect(0, y, Config::DisplayWidth, Metrics::LargeTextLineHeight, backgroundColor);
|
2020-01-30 09:28:01 +00:00
|
|
|
|
2020-01-30 19:06:13 +00:00
|
|
|
if (arrowColor)
|
2020-01-31 11:22:06 +00:00
|
|
|
this->drawArrowLeft(Metrics::ArrowMargin, y + Metrics::LargeTextLineHArrowYOffset, arrowColor);
|
2020-01-30 09:28:01 +00:00
|
|
|
|
2020-02-01 15:55:33 +00:00
|
|
|
this->display->setTextColor(textColor);
|
2020-01-30 19:06:13 +00:00
|
|
|
this->drawHeight(y, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-31 09:36:36 +00:00
|
|
|
void HomeScreen::drawHeight(int16_t y, uint16_t value)
|
2020-01-30 19:06:13 +00:00
|
|
|
{
|
2020-01-30 09:28:01 +00:00
|
|
|
char textValue[6];
|
2020-01-31 15:50:19 +00:00
|
|
|
Control.getDisplayHeight(&textValue[0], value);
|
2020-01-31 09:36:36 +00:00
|
|
|
|
2020-01-31 11:22:06 +00:00
|
|
|
this->printCentered(&textValue[0], y + Metrics::LargeTextLineYOffset);
|
2020-01-30 09:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HomeScreen::drawMenu()
|
|
|
|
{
|
2020-01-31 11:22:06 +00:00
|
|
|
this->drawArrowLeft(Metrics::ArrowMargin, Metrics::MiddleLargeTextLineY, Config::ColorHomeMenuArrow);
|
2020-01-30 19:06:13 +00:00
|
|
|
|
2020-02-01 15:55:33 +00:00
|
|
|
this->display->setTextColor(Config::ColorHomeMenuText);
|
2020-01-31 11:22:06 +00:00
|
|
|
this->printCentered("Menu", Metrics::MiddleLargeTextLineY + Metrics::LargeTextLineYOffset);
|
2020-01-30 09:28:01 +00:00
|
|
|
}
|