From 91181efef8f2c2fb473086407d67ba01a3b34ed2 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 11 Jan 2022 22:41:50 +0100 Subject: [PATCH] Smaller fixes and added change value display for chrono durations --- CMakeLists.txt | 1 + src/actions/setvalueaction.h | 2 +- src/changevaluedisplay.h | 14 +++ src/changevaluedisplay_chrono.h | 129 ++++++++++++++++++++++++ src/changevaluedisplay_ip_address_t.cpp | 7 ++ src/changevaluedisplay_ip_address_t.h | 1 + src/changevaluedisplay_string.cpp | 7 ++ src/changevaluedisplay_string.h | 1 + src/menudisplay.cpp | 6 ++ src/menudisplay.h | 1 + src/textwithvaluehelper.h | 2 + 11 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 src/changevaluedisplay_chrono.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c2f2b6..2147539 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ set(headers src/buttonsinterface.h src/changevaluedisplay.h src/changevaluedisplay_bool.h + src/changevaluedisplay_chrono.h src/changevaluedisplay_daylightsavingmode.h src/changevaluedisplay_ip_address_t.h src/changevaluedisplay_sntp_sync_mode_t.h diff --git a/src/actions/setvalueaction.h b/src/actions/setvalueaction.h index 27ee39b..9bb907d 100644 --- a/src/actions/setvalueaction.h +++ b/src/actions/setvalueaction.h @@ -11,7 +11,7 @@ template class SetValueAction : public virtual ActionInterface { public: - SetValueAction(T value,AccessorInterface &accessorInterface, + SetValueAction(T value, AccessorInterface &accessorInterface, ConfirmInterface &confirmInterface, ErrorHandlerInterface &errorHandlerInterface) : m_value{value}, m_accessorInterface{accessorInterface}, diff --git a/src/changevaluedisplay.h b/src/changevaluedisplay.h index f886d78..ca98003 100644 --- a/src/changevaluedisplay.h +++ b/src/changevaluedisplay.h @@ -1,5 +1,8 @@ #pragma once +// system includes +#include + // local includes #include "displaywithtitle.h" #include "textinterface.h" @@ -55,12 +58,15 @@ class ChangeValueDisplay : { using Base = ChangeValueDisplayInterface; + static_assert((std::is_integral_v || std::is_floating_point_v) && !std::is_same_v); + public: void start() override; void update() override; void redraw() override; void buttonPressed(Button button) override; + void buttonReleased(Button button) override; int shownValue() const { return m_value; } void setShownValue(int value) { m_value = value; } @@ -132,4 +138,12 @@ void ChangeValueDisplay::buttonPressed(Button button) } } +template +void ChangeValueDisplay::buttonReleased(Button button) +{ + //Base::buttonPressed(button); + + // TODO stop auto scroll +} + } // namespace espgui diff --git a/src/changevaluedisplay_chrono.h b/src/changevaluedisplay_chrono.h new file mode 100644 index 0000000..858463f --- /dev/null +++ b/src/changevaluedisplay_chrono.h @@ -0,0 +1,129 @@ +#pragma once + +// system includes +#include + +// 3rdparty lib includes +#include + +// local includes +#include "changevaluedisplay.h" +#include "displaywithtitle.h" +#include "confirminterface.h" +#include "backinterface.h" +#include "errorhandlerinterface.h" +#include "widgets/label.h" + +namespace espgui { + +namespace detail { +template +class ChangeValueDisplayChrono : + public DisplayWithTitle, + public virtual AccessorInterface, + public virtual ConfirmInterface, + public virtual BackInterface, + public virtual ErrorHandlerInterface +{ + using Base = DisplayWithTitle; + +public: + void start() override; + void initScreen() override; + void update() override; + void redraw() override; + + void buttonPressed(Button button) override; + void buttonReleased(Button button) override; + +private: + T m_value; + bool m_pressed{}; + + Label m_valueLabel{26, 81}; // 188, 53 +}; + +template +void ChangeValueDisplayChrono::start() +{ + Base::start(); + + m_value = this->getValue(); + + m_pressed = false; +} + +template +void ChangeValueDisplayChrono::initScreen() +{ + Base::initScreen(); + + tft.drawRect(25, 75, 190, 65, TFT_WHITE); + m_valueLabel.start(); + + tft.setTextFont(4); + tft.setTextColor(TFT_WHITE); + tft.drawString("Change value and", 10, 160); + tft.drawString("press button to", 10, 185); + tft.drawString("confirm and go", 10, 210); + tft.drawString("back.", 10, 235); +} + +template +void ChangeValueDisplayChrono::update() +{ + Base::update(); + + if (m_pressed) + { + m_pressed = false; + if (auto result = this->setValue(m_value); result) + confirm(); + else + errorOccured(std::move(result).error()); + } +} + +template +void ChangeValueDisplayChrono::redraw() +{ + Base::redraw(); + + tft.setTextColor(TFT_WHITE, TFT_BLACK); + tft.setTextFont(4); + m_valueLabel.redraw(espchrono::toString(m_value)); +} + +template +void ChangeValueDisplayChrono::buttonPressed(Button button) +{ + //Base::buttonPressed(button); + + switch (button) + { + case Button::Left: this->back(); break; + case Button::Right: m_pressed = true; break; + default:; + } +} + +template +void ChangeValueDisplayChrono::buttonReleased(Button button) +{ + //Base::buttonPressed(button); + + // TODO stop auto scroll +} + +} // namespace detail + +template<> +class ChangeValueDisplay : public detail::ChangeValueDisplayChrono {}; +template<> +class ChangeValueDisplay : public detail::ChangeValueDisplayChrono {}; +template<> +class ChangeValueDisplay : public detail::ChangeValueDisplayChrono {}; +template<> +class ChangeValueDisplay : public detail::ChangeValueDisplayChrono {}; + +} // namespace espgui diff --git a/src/changevaluedisplay_ip_address_t.cpp b/src/changevaluedisplay_ip_address_t.cpp index dda9afe..6b00662 100644 --- a/src/changevaluedisplay_ip_address_t.cpp +++ b/src/changevaluedisplay_ip_address_t.cpp @@ -61,3 +61,10 @@ void espgui::ChangeValueDisplay::buttonPressed(Button default:; } } + +void espgui::ChangeValueDisplay::buttonReleased(Button button) +{ + //Base::buttonReleased(button); + + // TODO stop auto scroll +} diff --git a/src/changevaluedisplay_ip_address_t.h b/src/changevaluedisplay_ip_address_t.h index 6d4c107..6ad1168 100644 --- a/src/changevaluedisplay_ip_address_t.h +++ b/src/changevaluedisplay_ip_address_t.h @@ -33,6 +33,7 @@ public: void redraw() override; void buttonPressed(Button button) override; + void buttonReleased(Button button) override; wifi_stack::ip_address_t shownValue() const { return m_value; } void setShownValue(wifi_stack::ip_address_t value) { m_value = value; } diff --git a/src/changevaluedisplay_string.cpp b/src/changevaluedisplay_string.cpp index 9cfa512..82e9f5e 100644 --- a/src/changevaluedisplay_string.cpp +++ b/src/changevaluedisplay_string.cpp @@ -61,3 +61,10 @@ void espgui::ChangeValueDisplay::buttonPressed(Button button) default:; } } + +void espgui::ChangeValueDisplay::buttonReleased(Button button) +{ + //Base::buttonReleased(button); + + // TODO stop auto scroll +} diff --git a/src/changevaluedisplay_string.h b/src/changevaluedisplay_string.h index acd946a..803e40f 100644 --- a/src/changevaluedisplay_string.h +++ b/src/changevaluedisplay_string.h @@ -33,6 +33,7 @@ public: void redraw() override; void buttonPressed(Button button) override; + void buttonReleased(Button button) override; const std::string &shownValue() const { return m_value; } void setShownValue(std::string &&value) { m_value = std::move(value); } diff --git a/src/menudisplay.cpp b/src/menudisplay.cpp index 413b344..5c66d2b 100644 --- a/src/menudisplay.cpp +++ b/src/menudisplay.cpp @@ -184,4 +184,10 @@ void MenuDisplay::buttonPressed(Button button) case Button::Down: m_rotateOffset++; break; } } + +void MenuDisplay::buttonReleased(Button button) +{ + //Base::buttonPressed(button); + // TODO stop auto scroll +} } // namespace espgui diff --git a/src/menudisplay.h b/src/menudisplay.h index 84bd941..e85f50c 100644 --- a/src/menudisplay.h +++ b/src/menudisplay.h @@ -31,6 +31,7 @@ public: void stop() override; void buttonPressed(Button button) override; + void buttonReleased(Button button) override; MenuDisplay *asMenuDisplay() override { return this; } const MenuDisplay *asMenuDisplay() const override { return this; } diff --git a/src/textwithvaluehelper.h b/src/textwithvaluehelper.h index 85b2d68..56884f9 100644 --- a/src/textwithvaluehelper.h +++ b/src/textwithvaluehelper.h @@ -5,6 +5,7 @@ #include #include #include +#include // local includes #include "textinterface.h" @@ -22,6 +23,7 @@ struct TextWithValueHelper : public Taccessor, public virtual TextInterface using cpputils::toString; using espcpputils::toString; using wifi_stack::toString; + using espchrono::toString; return fmt::format("{} {}", Tprefix, richTextEscape(toString(Taccessor::getValue()))); }