127 lines
2.9 KiB
C++
127 lines
2.9 KiB
C++
#include "./home.h"
|
|
#include "fonts/FreeSansBold18pt7b.trimmed.h"
|
|
#include "include/config.h"
|
|
#include "lib/settings.h"
|
|
|
|
|
|
#define HOME_FONT_BASELINE 25
|
|
#define HOME_FONT_HEIGHT 42
|
|
|
|
#define HOME_MOVING_REFRESHRATE 250
|
|
|
|
#define PRESET_MARGIN 7
|
|
|
|
// HOME_FONT_BASELINE is not a mistake, as there are no characters used which
|
|
// go below the baseline.
|
|
#define PRESET_LINEHEIGHT (HOME_FONT_BASELINE + (2 * PRESET_MARGIN))
|
|
|
|
|
|
// TODO move to shared file
|
|
// Formats a height value as "0.00m" (always exactly 5 characters long).
|
|
// Buffer must be at least 5 bytes long. No null character is added.
|
|
void getDisplayHeight(char* buffer, uint8_t value)
|
|
{
|
|
if (value > 99)
|
|
buffer[0] = '0' + ((value / 100) % 10);
|
|
else
|
|
buffer[0] = '0';
|
|
|
|
buffer[1] = '.';
|
|
buffer[2] = '0' + ((value / 10) % 10);
|
|
buffer[3] = '0' + (value % 10);
|
|
buffer[4] = 'm';
|
|
}
|
|
|
|
|
|
void HomeScreen::onShow()
|
|
{
|
|
this->showTime = State.CurrentTime;
|
|
|
|
auto display = this->getDisplay();
|
|
|
|
display->setFont(&FreeSansBold18pt7bTrimmed);
|
|
display->fillScreen(Config::ColorMenuBackground);
|
|
|
|
this->drawPreset1();
|
|
this->drawMenu();
|
|
this->drawPreset2();
|
|
|
|
// TODO if the height does not match either preset, display the actual height
|
|
}
|
|
|
|
|
|
void HomeScreen::onButton(Button button)
|
|
{
|
|
}
|
|
|
|
|
|
void HomeScreen::onTick()
|
|
{
|
|
// TODO turn off screen after timeout
|
|
//if (State.CurrentTime )
|
|
}
|
|
|
|
|
|
void HomeScreen::drawPreset1()
|
|
{
|
|
this->drawPreset(1, 0, Settings.Height.Preset[0]);
|
|
}
|
|
|
|
|
|
void HomeScreen::drawPreset2()
|
|
{
|
|
this->drawPreset(2, Config::DisplayHeight - PRESET_LINEHEIGHT, Settings.Height.Preset[1]);
|
|
}
|
|
|
|
|
|
void HomeScreen::drawPreset(uint8_t number, uint8_t y, uint8_t value)
|
|
{
|
|
auto display = this->getDisplay();
|
|
uint16_t numberColor;
|
|
uint16_t textColor;
|
|
uint16_t backgroundColor;
|
|
|
|
// An exact comparison is enough here, the movement code takes care of that if it's "close enough"
|
|
if (value == State.CurrentHeight)
|
|
{
|
|
textColor = Config::ColorPresetSelectedText;
|
|
numberColor = Config::ColorPresetSelectedNumber;
|
|
backgroundColor = Config::ColorPresetSelectedBackground;
|
|
}
|
|
else
|
|
{
|
|
textColor = Config::ColorPresetText;
|
|
numberColor = Config::ColorPresetNumber;
|
|
backgroundColor = Config::ColorPresetBackground;
|
|
}
|
|
|
|
display->fillRect(0, y, Config::DisplayWidth, PRESET_LINEHEIGHT, backgroundColor);
|
|
|
|
display->setCursor(0, y + HOME_FONT_BASELINE + PRESET_MARGIN);
|
|
display->setTextColor(numberColor);
|
|
display->print("P");
|
|
display->print(number);
|
|
|
|
|
|
char textValue[6];
|
|
getDisplayHeight(&textValue[0], value);
|
|
textValue[5] = 0;
|
|
|
|
// Calculate the center position
|
|
int16_t textX;
|
|
int16_t textY;
|
|
uint16_t textW;
|
|
uint16_t textH;
|
|
display->getTextBounds(&textValue[0], 0, 0, &textX, &textY, &textW, &textH);
|
|
|
|
textX = (Config::DisplayWidth - textW) / 2;
|
|
display->setCursor(textX, y + HOME_FONT_BASELINE + PRESET_MARGIN);
|
|
display->setTextColor(textColor);
|
|
display->print(textValue);
|
|
}
|
|
|
|
|
|
void HomeScreen::drawMenu()
|
|
{
|
|
}
|