Smaller fixes and added change value display for chrono durations

This commit is contained in:
2022-01-11 22:41:50 +01:00
parent 65a8c98530
commit 91181efef8
11 changed files with 170 additions and 1 deletions

View File

@ -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

View File

@ -11,7 +11,7 @@ template<typename T>
class SetValueAction : public virtual ActionInterface
{
public:
SetValueAction(T value,AccessorInterface<T> &accessorInterface,
SetValueAction(T value, AccessorInterface<T> &accessorInterface,
ConfirmInterface &confirmInterface, ErrorHandlerInterface &errorHandlerInterface) :
m_value{value},
m_accessorInterface{accessorInterface},

View File

@ -1,5 +1,8 @@
#pragma once
// system includes
#include <type_traits>
// local includes
#include "displaywithtitle.h"
#include "textinterface.h"
@ -55,12 +58,15 @@ class ChangeValueDisplay :
{
using Base = ChangeValueDisplayInterface;
static_assert((std::is_integral_v<Tvalue> || std::is_floating_point_v<Tvalue>) && !std::is_same_v<Tvalue, bool>);
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<Tvalue>::buttonPressed(Button button)
}
}
template<typename Tvalue>
void ChangeValueDisplay<Tvalue>::buttonReleased(Button button)
{
//Base::buttonPressed(button);
// TODO stop auto scroll
}
} // namespace espgui

View File

@ -0,0 +1,129 @@
#pragma once
// system includes
#include <string>
// 3rdparty lib includes
#include <espchrono.h>
// 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<typename T>
class ChangeValueDisplayChrono :
public DisplayWithTitle,
public virtual AccessorInterface<T>,
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<typename T>
void ChangeValueDisplayChrono<T>::start()
{
Base::start();
m_value = this->getValue();
m_pressed = false;
}
template<typename T>
void ChangeValueDisplayChrono<T>::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<typename T>
void ChangeValueDisplayChrono<T>::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<typename T>
void ChangeValueDisplayChrono<T>::redraw()
{
Base::redraw();
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setTextFont(4);
m_valueLabel.redraw(espchrono::toString(m_value));
}
template<typename T>
void ChangeValueDisplayChrono<T>::buttonPressed(Button button)
{
//Base::buttonPressed(button);
switch (button)
{
case Button::Left: this->back(); break;
case Button::Right: m_pressed = true; break;
default:;
}
}
template<typename T>
void ChangeValueDisplayChrono<T>::buttonReleased(Button button)
{
//Base::buttonPressed(button);
// TODO stop auto scroll
}
} // namespace detail
template<>
class ChangeValueDisplay<espchrono::hours32> : public detail::ChangeValueDisplayChrono<espchrono::hours32> {};
template<>
class ChangeValueDisplay<espchrono::minutes32> : public detail::ChangeValueDisplayChrono<espchrono::minutes32> {};
template<>
class ChangeValueDisplay<espchrono::seconds32> : public detail::ChangeValueDisplayChrono<espchrono::seconds32> {};
template<>
class ChangeValueDisplay<espchrono::milliseconds32> : public detail::ChangeValueDisplayChrono<espchrono::milliseconds32> {};
} // namespace espgui

View File

@ -61,3 +61,10 @@ void espgui::ChangeValueDisplay<wifi_stack::ip_address_t>::buttonPressed(Button
default:;
}
}
void espgui::ChangeValueDisplay<wifi_stack::ip_address_t>::buttonReleased(Button button)
{
//Base::buttonReleased(button);
// TODO stop auto scroll
}

View File

@ -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; }

View File

@ -61,3 +61,10 @@ void espgui::ChangeValueDisplay<std::string>::buttonPressed(Button button)
default:;
}
}
void espgui::ChangeValueDisplay<std::string>::buttonReleased(Button button)
{
//Base::buttonReleased(button);
// TODO stop auto scroll
}

View File

@ -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); }

View File

@ -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

View File

@ -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; }

View File

@ -5,6 +5,7 @@
#include <strutils.h>
#include <espstrutils.h>
#include <espwifiutils.h>
#include <espchrono.h>
// 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())));
}