Cleaned up the interface

This commit is contained in:
Mark van Renswoude 2020-01-30 20:06:13 +01:00
parent df61b1f24d
commit 61a4072738
6 changed files with 96 additions and 24 deletions

View File

@ -45,5 +45,4 @@ upload_speed = 19200
[env:platformio-home-debug] [env:platformio-home-debug]
platform = atmelavr platform = atmelavr
board = atmega2560 board = atmega2560
board_build.f_cpu = 16000000L
framework = arduino framework = arduino

View File

@ -69,20 +69,20 @@ class Config
// the initialisation code skips reassigning the address to save calls. // the initialisation code skips reassigning the address to save calls.
static const uint8_t HeightSensorI2CAddress = 0x29; static const uint8_t HeightSensorI2CAddress = 0x29;
static const uint16_t HeightSensorBudget = 33000; static const uint32_t HeightSensorBudget = 200000;
// Values above this will be disregarded as invalid // Values above this will be disregarded as invalid
static const uint16_t HeightMeasurementMax = 1500; static const uint16_t HeightMeasurementMax = 1500;
// How much the measurements can change to still be considered "stable" // How much the measurements can change to still be considered "stable"
static const uint8_t HeightMeasurementDeltaStable = 5; static const uint8_t HeightMeasurementDeltaStable = 10;
// How far in advance to stop the motor // How far in advance to stop the motor
static const uint8_t HeightMeasurementDeltaStop = 0; static const uint8_t HeightMeasurementDeltaStop = 0;
// How far off we can be from the target height to still be considered on target // How far off we can be from the target height to still be considered on target
static const uint8_t HeightMeasurementDeltaOnTarget = 5; static const uint8_t HeightMeasurementDeltaOnTarget = 15;
// How long we allow invalid measurements until the move operation is aborted // How long we allow invalid measurements until the move operation is aborted
static const uint8_t HeightMeasurementAbortTimeout = 100; static const uint8_t HeightMeasurementAbortTimeout = 100;
@ -104,11 +104,19 @@ class Config
static const uint16_t ColorInitSeqSuccess = GREEN; static const uint16_t ColorInitSeqSuccess = GREEN;
static const uint16_t ColorInitSeqError = RED; static const uint16_t ColorInitSeqError = RED;
static const uint16_t ColorMenuBackground = BLACK; static const uint16_t ColorHomeBackground = BLACK;
static const uint16_t ColorHomeMenuTextColor = WHITE;
static const uint16_t ColorHomeMenuArrowColor = 0x528A; // Dark gray
static const uint16_t ColorNonPresetText = 0x9492; // Light gray
static const uint16_t ColorNonPresetBackground = BLACK;
//static const uint16_t ColorNonPresetIndicator = 0x528A; // Dark gray
static const uint16_t ColorPresetText = 0x9492; // Light gray static const uint16_t ColorPresetText = 0x9492; // Light gray
static const uint16_t ColorPresetBackground = BLACK; static const uint16_t ColorPresetBackground = 0x2965; // Very dark gray
static const uint16_t ColorPresetNumber = 0x528A; // Dark gray //static const uint16_t ColorPresetNumber = 0x528A; // Dark gray
static const uint16_t ColorPresetArrowColor = 0x528A; // Dark gray
static const uint16_t ColorPresetSelectedText = WHITE; static const uint16_t ColorPresetSelectedText = WHITE;
static const uint16_t ColorPresetSelectedBackground = 0x2BE7; // Soft green static const uint16_t ColorPresetSelectedBackground = 0x2BE7; // Soft green

View File

@ -17,6 +17,15 @@
// go below the baseline. // go below the baseline.
#define PRESET_LINEHEIGHT (HOME_FONT_BASELINE + (2 * PRESET_MARGIN)) #define PRESET_LINEHEIGHT (HOME_FONT_BASELINE + (2 * PRESET_MARGIN))
#define HOME_ARROW_WIDTH 10
#define HOME_ARROW_HEIGHT 20
#define HOME_ARROW_MARGIN 8
#define HOME_ARROW_YOFFSET ((PRESET_LINEHEIGHT - HOME_ARROW_HEIGHT) / 2)
#define HOME_INDICATOR_OFFSET (HOME_ARROW_WIDTH + (2 * HOME_ARROW_MARGIN))
#define HOME_MENU_Y 100
void HomeScreen::onShow() void HomeScreen::onShow()
@ -26,13 +35,13 @@ void HomeScreen::onShow()
auto display = this->getDisplay(); auto display = this->getDisplay();
display->setFont(&FreeSansBold18pt7bTrimmed); display->setFont(&FreeSansBold18pt7bTrimmed);
display->fillScreen(Config::ColorMenuBackground); display->fillScreen(Config::ColorHomeBackground);
this->drawPreset1(); this->drawPreset1();
this->drawMenu(); this->drawMenu();
this->drawPreset2(); this->drawPreset2();
// TODO if the height does not match either preset, display the actual height this->drawNonPresetHeight();
} }
@ -69,54 +78,90 @@ void HomeScreen::onButton(Button button)
void HomeScreen::onTick() void HomeScreen::onTick()
{ {
// TODO reactivate
/*
if (!this->idle && State.CurrentTime - this->showTime >= Config::DisplayIdleTime) if (!this->idle && State.CurrentTime - this->showTime >= Config::DisplayIdleTime)
{ {
this->getScreenManager()->displayOff(); this->getScreenManager()->displayOff();
this->idle = true; this->idle = true;
} }
*/
} }
void HomeScreen::drawPreset1() void HomeScreen::drawPreset1()
{ {
this->drawPreset(1, 0, Settings.Height.Preset[0]); //this->drawPreset(0, Settings.Height.Preset[0]);
this->drawPreset(0, State.CurrentHeight);
} }
void HomeScreen::drawPreset2() void HomeScreen::drawPreset2()
{ {
this->drawPreset(2, Config::DisplayHeight - PRESET_LINEHEIGHT, Settings.Height.Preset[1]); this->drawPreset(Config::DisplayHeight - PRESET_LINEHEIGHT, Settings.Height.Preset[1]);
} }
void HomeScreen::drawPreset(uint8_t number, uint8_t y, uint16_t value) void HomeScreen::drawNonPresetHeight()
{
auto display = this->getDisplay();
auto y = PRESET_LINEHEIGHT;
display->fillRect(0, y, Config::DisplayWidth, PRESET_LINEHEIGHT, Config::ColorNonPresetBackground);
if (State.CurrentHeight != Settings.Height.Preset[0] &&
State.CurrentHeight != Settings.Height.Preset[1])
{
display->setTextColor(Config::ColorNonPresetText);
this->drawHeight(y, State.CurrentHeight);
}
}
void HomeScreen::drawArrow(uint8_t y, uint16_t color)
{
this->getDisplay()->fillTriangle(
HOME_ARROW_MARGIN, y + HOME_ARROW_YOFFSET + (HOME_ARROW_HEIGHT / 2), // Middle left
HOME_ARROW_MARGIN + HOME_ARROW_WIDTH, y + HOME_ARROW_YOFFSET, // Top right
HOME_ARROW_MARGIN + HOME_ARROW_WIDTH, y + HOME_ARROW_YOFFSET + HOME_ARROW_HEIGHT, // Bottom right
color);
}
void HomeScreen::drawPreset(uint8_t y, uint16_t value)
{ {
auto display = this->getDisplay(); auto display = this->getDisplay();
uint16_t numberColor;
uint16_t textColor; uint16_t textColor;
uint16_t backgroundColor; uint16_t backgroundColor;
uint16_t arrowColor;
// An exact comparison is enough here, the movement code takes care of that if it's "close enough" // An exact comparison is enough here, the movement code takes care of that if it's "close enough"
if (value == State.CurrentHeight) if (value == State.CurrentHeight)
{ {
textColor = Config::ColorPresetSelectedText; textColor = Config::ColorPresetSelectedText;
numberColor = Config::ColorPresetSelectedNumber;
backgroundColor = Config::ColorPresetSelectedBackground; backgroundColor = Config::ColorPresetSelectedBackground;
arrowColor = 0;
} }
else else
{ {
textColor = Config::ColorPresetText; textColor = Config::ColorPresetText;
numberColor = Config::ColorPresetNumber;
backgroundColor = Config::ColorPresetBackground; backgroundColor = Config::ColorPresetBackground;
arrowColor = Config::ColorPresetArrowColor;
} }
display->fillRect(0, y, Config::DisplayWidth, PRESET_LINEHEIGHT, backgroundColor); display->fillRect(0, y, Config::DisplayWidth, PRESET_LINEHEIGHT, backgroundColor);
display->setCursor(0, y + HOME_FONT_BASELINE + PRESET_MARGIN); if (arrowColor)
display->setTextColor(numberColor); this->drawArrow(y, arrowColor);
display->print("P");
display->print(number);
display->setTextColor(textColor);
this->drawHeight(y, value);
}
void HomeScreen::drawHeight(uint8_t y, uint16_t value)
{
auto display = this->getDisplay();
char textValue[6]; char textValue[6];
getDisplayHeight(&textValue[0], value); getDisplayHeight(&textValue[0], value);
@ -131,11 +176,24 @@ void HomeScreen::drawPreset(uint8_t number, uint8_t y, uint16_t value)
textX = (Config::DisplayWidth - textW) / 2; textX = (Config::DisplayWidth - textW) / 2;
display->setCursor(textX, y + HOME_FONT_BASELINE + PRESET_MARGIN); display->setCursor(textX, y + HOME_FONT_BASELINE + PRESET_MARGIN);
display->setTextColor(textColor);
display->print(textValue); display->print(textValue);
} }
void HomeScreen::drawMenu() void HomeScreen::drawMenu()
{ {
auto display = this->getDisplay();
this->drawArrow(HOME_MENU_Y, Config::ColorHomeMenuArrowColor);
int16_t textX;
int16_t textY;
uint16_t textW;
uint16_t textH;
display->getTextBounds("Menu", 0, 0, &textX, &textY, &textW, &textH);
textX = (Config::DisplayWidth - textW) / 2;
display->setCursor(textX, HOME_MENU_Y + HOME_FONT_BASELINE + PRESET_MARGIN);
display->setTextColor(Config::ColorHomeMenuTextColor);
display->print("Menu");
} }

View File

@ -24,7 +24,11 @@ class HomeScreen : public BaseScreen
void drawPreset1(); void drawPreset1();
void drawPreset2(); void drawPreset2();
void drawPreset(uint8_t number, uint8_t y, uint16_t value); void drawNonPresetHeight();
void drawArrow(uint8_t y, uint16_t color);
void drawPreset(uint8_t y, uint16_t value);
void drawHeight(uint8_t y, uint16_t value);
void drawMenu(); void drawMenu();
}; };

View File

@ -17,7 +17,7 @@ void MoveScreen::onShow()
auto display = this->getDisplay(); auto display = this->getDisplay();
display->setFont(&FreeSansBold18pt7bTrimmed); display->setFont(&FreeSansBold18pt7bTrimmed);
display->fillScreen(Config::ColorMenuBackground); display->fillScreen(Config::ColorHomeBackground);
// TODO draw current and target height // TODO draw current and target height
} }

View File

@ -80,9 +80,11 @@ void setup()
State.CurrentTime = millis(); State.CurrentTime = millis();
// TODO check if close to either preset, then use the preset height
State.CurrentHeight = currentHeight;
if (initialized) if (initialized)
{ {
State.CurrentHeight = currentHeight;
screenManager.show<HomeScreen>(); screenManager.show<HomeScreen>();
} }
else else
@ -142,7 +144,8 @@ inline uint16_t testHeightSensor()
uint8_t closeCount = 0; uint8_t closeCount = 0;
uint16_t measurement; uint16_t measurement;
while (closeCount < 3) // TODO while (closeCount < 3)
while (closeCount < 1)
{ {
if (heightSensorGetRange(&measurement)) if (heightSensorGetRange(&measurement))
{ {