Files
esp-gui-lib/src/changevaluedisplay_ip_address_t.cpp
T

114 lines
2.5 KiB
C++
Raw Normal View History

2021-12-30 05:56:46 +01:00
#include "changevaluedisplay_ip_address_t.h"
// local includes
#include "tftinstance.h"
2022-03-02 06:25:57 +01:00
namespace espgui {
void ChangeValueDisplay<wifi_stack::ip_address_t>::start()
2021-12-30 05:56:46 +01:00
{
Base::start();
m_value = this->getValue();
2022-03-02 06:25:57 +01:00
m_currentIndex = 0;
2021-12-30 05:56:46 +01:00
}
2022-03-02 06:25:57 +01:00
void ChangeValueDisplay<wifi_stack::ip_address_t>::initScreen()
2021-12-30 05:56:46 +01:00
{
Base::initScreen();
tft.setTextColor(TFT_WHITE);
2022-03-02 06:25:57 +01:00
tft.drawString("Change IP", 0, 50);
for(int i = 0; i <= 3; i++)
{
drawRect(i, 3, TFT_WHITE);
drawRect(i, 4, TFT_WHITE);
}
for (auto &label : m_labels)
label.start();
drawRect(m_currentIndex, 1, TFT_YELLOW);
drawRect(m_currentIndex, 2, TFT_YELLOW);
m_lastIndex = m_currentIndex;
2021-12-30 05:56:46 +01:00
}
2022-03-02 06:25:57 +01:00
void ChangeValueDisplay<wifi_stack::ip_address_t>::update()
2021-12-30 05:56:46 +01:00
{
Base::update();
2022-03-02 06:25:57 +01:00
// TODO auto scroll
2021-12-30 05:56:46 +01:00
}
2022-03-02 06:25:57 +01:00
void ChangeValueDisplay<wifi_stack::ip_address_t>::redraw()
2021-12-30 05:56:46 +01:00
{
Base::redraw();
tft.setTextColor(TFT_WHITE, TFT_BLACK);
2022-03-02 06:25:57 +01:00
if (m_lastIndex != m_currentIndex)
{
drawRect(m_lastIndex, 1, TFT_BLACK);
drawRect(m_lastIndex, 2, TFT_BLACK);
drawRect(m_currentIndex, 1, TFT_YELLOW);
drawRect(m_currentIndex, 2, TFT_YELLOW);
m_lastIndex = m_currentIndex;
}
2021-12-30 05:56:46 +01:00
tft.setTextFont(4);
2022-03-02 06:25:57 +01:00
for (auto i = 0; i < 4; i++)
m_labels[i].redraw(std::to_string(m_value.bytes()[i]));
2021-12-30 05:56:46 +01:00
}
2022-03-02 06:25:57 +01:00
void ChangeValueDisplay<wifi_stack::ip_address_t>::buttonPressed(Button button)
2021-12-30 05:56:46 +01:00
{
//Base::buttonPressed(button);
switch (button)
{
2022-03-02 06:25:57 +01:00
case Button::Left:
if (m_currentIndex > 0)
m_currentIndex--;
else
back();
break;
case Button::Right:
if (m_currentIndex < 3)
m_currentIndex++;
else
{
if (auto result = this->setValue(m_value); result)
confirm();
else
errorOccured(std::move(result).error());
}
break;
case Button::Up:
m_value.bytes()[m_currentIndex]++;
break;
case Button::Down:
m_value.bytes()[m_currentIndex]--;
break;
2021-12-30 05:56:46 +01:00
default:;
}
}
2022-03-02 06:25:57 +01:00
void ChangeValueDisplay<wifi_stack::ip_address_t>::buttonReleased(Button button)
{
//Base::buttonReleased(button);
// TODO stop auto scroll
}
2022-03-02 06:25:57 +01:00
void ChangeValueDisplay<wifi_stack::ip_address_t>::drawRect(int index, int offset, uint32_t color) const
{
tft.drawRect(m_labels[index].x()-offset, m_labels[index].y()-offset, boxWidth+(offset*2), boxHeight+(offset*2), color);
}
} // namespace espgui