From 61a4072738552768912844ad826e622065625f67 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Thu, 30 Jan 2020 20:06:13 +0100 Subject: [PATCH] Cleaned up the interface --- platformio.ini | 1 - src/include/config.h | 20 +++++++--- src/lib/screen/home.cpp | 84 ++++++++++++++++++++++++++++++++++------- src/lib/screen/home.h | 6 ++- src/lib/screen/move.cpp | 2 +- src/main.cpp | 7 +++- 6 files changed, 96 insertions(+), 24 deletions(-) diff --git a/platformio.ini b/platformio.ini index 8949348..e991e11 100644 --- a/platformio.ini +++ b/platformio.ini @@ -45,5 +45,4 @@ upload_speed = 19200 [env:platformio-home-debug] platform = atmelavr board = atmega2560 -board_build.f_cpu = 16000000L framework = arduino \ No newline at end of file diff --git a/src/include/config.h b/src/include/config.h index e8a8c90..d15d978 100644 --- a/src/include/config.h +++ b/src/include/config.h @@ -69,20 +69,20 @@ class Config // the initialisation code skips reassigning the address to save calls. 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 static const uint16_t HeightMeasurementMax = 1500; // 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 static const uint8_t HeightMeasurementDeltaStop = 0; // 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 static const uint8_t HeightMeasurementAbortTimeout = 100; @@ -104,11 +104,19 @@ class Config static const uint16_t ColorInitSeqSuccess = GREEN; 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 ColorPresetBackground = BLACK; - static const uint16_t ColorPresetNumber = 0x528A; // Dark gray + static const uint16_t ColorPresetBackground = 0x2965; // Very 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 ColorPresetSelectedBackground = 0x2BE7; // Soft green diff --git a/src/lib/screen/home.cpp b/src/lib/screen/home.cpp index 335800a..db00c5b 100644 --- a/src/lib/screen/home.cpp +++ b/src/lib/screen/home.cpp @@ -17,6 +17,15 @@ // go below the baseline. #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() @@ -26,13 +35,13 @@ void HomeScreen::onShow() auto display = this->getDisplay(); display->setFont(&FreeSansBold18pt7bTrimmed); - display->fillScreen(Config::ColorMenuBackground); + display->fillScreen(Config::ColorHomeBackground); this->drawPreset1(); this->drawMenu(); 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() { + // TODO reactivate + /* if (!this->idle && State.CurrentTime - this->showTime >= Config::DisplayIdleTime) { this->getScreenManager()->displayOff(); this->idle = true; } + */ } 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() { - 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(); - uint16_t numberColor; uint16_t textColor; uint16_t backgroundColor; + uint16_t arrowColor; // 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; + arrowColor = 0; } else { textColor = Config::ColorPresetText; - numberColor = Config::ColorPresetNumber; backgroundColor = Config::ColorPresetBackground; + arrowColor = Config::ColorPresetArrowColor; } 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); + if (arrowColor) + this->drawArrow(y, arrowColor); + display->setTextColor(textColor); + this->drawHeight(y, value); +} + + +void HomeScreen::drawHeight(uint8_t y, uint16_t value) +{ + auto display = this->getDisplay(); char textValue[6]; 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; display->setCursor(textX, y + HOME_FONT_BASELINE + PRESET_MARGIN); - display->setTextColor(textColor); display->print(textValue); } 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"); } diff --git a/src/lib/screen/home.h b/src/lib/screen/home.h index 559153e..616abd4 100644 --- a/src/lib/screen/home.h +++ b/src/lib/screen/home.h @@ -24,7 +24,11 @@ class HomeScreen : public BaseScreen void drawPreset1(); 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(); }; diff --git a/src/lib/screen/move.cpp b/src/lib/screen/move.cpp index 4fc16d4..2c4f748 100644 --- a/src/lib/screen/move.cpp +++ b/src/lib/screen/move.cpp @@ -17,7 +17,7 @@ void MoveScreen::onShow() auto display = this->getDisplay(); display->setFont(&FreeSansBold18pt7bTrimmed); - display->fillScreen(Config::ColorMenuBackground); + display->fillScreen(Config::ColorHomeBackground); // TODO draw current and target height } diff --git a/src/main.cpp b/src/main.cpp index 33c49af..09cc669 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,9 +80,11 @@ void setup() State.CurrentTime = millis(); + // TODO check if close to either preset, then use the preset height + State.CurrentHeight = currentHeight; + if (initialized) { - State.CurrentHeight = currentHeight; screenManager.show(); } else @@ -142,7 +144,8 @@ inline uint16_t testHeightSensor() uint8_t closeCount = 0; uint16_t measurement; - while (closeCount < 3) + // TODO while (closeCount < 3) + while (closeCount < 1) { if (heightSensorGetRange(&measurement)) {