Implemented buttonHeld; still needs some work
This commit is contained in:
@ -22,6 +22,7 @@ public:
|
|||||||
|
|
||||||
virtual void buttonPressed(Button button) = 0;
|
virtual void buttonPressed(Button button) = 0;
|
||||||
virtual void buttonReleased(Button button) = 0;
|
virtual void buttonReleased(Button button) = 0;
|
||||||
|
virtual void buttonHeld(Button button) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace espgui
|
} // namespace espgui
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
// local includes
|
// local includes
|
||||||
#include "tftinstance.h"
|
#include "tftinstance.h"
|
||||||
|
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
namespace espgui {
|
namespace espgui {
|
||||||
@ -15,6 +17,18 @@ void MenuDisplay::start()
|
|||||||
|
|
||||||
m_rotateOffset = 0;
|
m_rotateOffset = 0;
|
||||||
m_pressed = false;
|
m_pressed = false;
|
||||||
|
|
||||||
|
m_upScrolling = false;
|
||||||
|
m_upHoldingSince = std::nullopt;
|
||||||
|
|
||||||
|
m_downScrolling = false;
|
||||||
|
m_downHoldingSince = std::nullopt;
|
||||||
|
|
||||||
|
m_leftScrolling = false;
|
||||||
|
m_leftHoldingSince = std::nullopt;
|
||||||
|
|
||||||
|
m_rightScrolling = false;
|
||||||
|
m_rightHoldingSince = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuDisplay::initScreen()
|
void MenuDisplay::initScreen()
|
||||||
@ -37,6 +51,84 @@ void MenuDisplay::update()
|
|||||||
{
|
{
|
||||||
Base::update();
|
Base::update();
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto ago = espchrono::ago(*m_upHoldingSince);
|
||||||
|
if (m_upHoldingSince && (m_upScrolling || ago > getInitialScrollSpeed()))
|
||||||
|
{
|
||||||
|
if (ago > getScrollSpeed())
|
||||||
|
{
|
||||||
|
if (!m_upScrolling)
|
||||||
|
{
|
||||||
|
// gets executed one time
|
||||||
|
buttonHeld(espgui::Up);
|
||||||
|
}
|
||||||
|
m_upScrolling = true;
|
||||||
|
m_upHoldingSince = espchrono::millis_clock::now();
|
||||||
|
|
||||||
|
// do sth
|
||||||
|
m_rotateOffset--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto ago = espchrono::ago(*m_downHoldingSince);
|
||||||
|
if (m_downHoldingSince && (m_downScrolling || ago > getInitialScrollSpeed()))
|
||||||
|
{
|
||||||
|
if (ago > getScrollSpeed())
|
||||||
|
{
|
||||||
|
if (!m_downScrolling)
|
||||||
|
{
|
||||||
|
// gets executed one time
|
||||||
|
buttonHeld(espgui::Down);
|
||||||
|
}
|
||||||
|
m_downScrolling = true;
|
||||||
|
m_downHoldingSince = espchrono::millis_clock::now();
|
||||||
|
|
||||||
|
// do sth
|
||||||
|
m_rotateOffset++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto ago = espchrono::ago(*m_leftHoldingSince);
|
||||||
|
if (m_leftHoldingSince && (m_leftScrolling || ago > getInitialScrollSpeed()))
|
||||||
|
{
|
||||||
|
if (ago > getScrollSpeed())
|
||||||
|
{
|
||||||
|
if (!m_leftScrolling)
|
||||||
|
{
|
||||||
|
// gets executed one time
|
||||||
|
buttonHeld(espgui::Left);
|
||||||
|
}
|
||||||
|
m_leftScrolling = true;
|
||||||
|
m_leftHoldingSince = espchrono::millis_clock::now();
|
||||||
|
|
||||||
|
// do sth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto ago = espchrono::ago(*m_rightHoldingSince);
|
||||||
|
if (m_rightHoldingSince && (m_rightScrolling || ago > getInitialScrollSpeed()))
|
||||||
|
{
|
||||||
|
if (ago > getScrollSpeed())
|
||||||
|
{
|
||||||
|
if (!m_rightScrolling)
|
||||||
|
{
|
||||||
|
// gets executed one time
|
||||||
|
buttonHeld(espgui::Right);
|
||||||
|
}
|
||||||
|
m_rightScrolling = true;
|
||||||
|
m_rightHoldingSince = espchrono::millis_clock::now();
|
||||||
|
|
||||||
|
// do sth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_pressed)
|
if (!m_pressed)
|
||||||
{
|
{
|
||||||
const auto offset = m_rotateOffset;
|
const auto offset = m_rotateOffset;
|
||||||
@ -95,27 +187,6 @@ void MenuDisplay::redraw()
|
|||||||
{
|
{
|
||||||
Base::redraw();
|
Base::redraw();
|
||||||
|
|
||||||
// wait for holding since to be above initial scroll speed, then start scrolling in interval set by getScrollSpeed()
|
|
||||||
if (m_upHoldingSince && (espchrono::ago(*m_upHoldingSince) > getInitialScrollSpeed() || m_upScrolling))
|
|
||||||
{
|
|
||||||
if (espchrono::ago(*m_upHoldingSince) > getScrollSpeed())
|
|
||||||
{
|
|
||||||
m_upScrolling = true;
|
|
||||||
m_rotateOffset--;
|
|
||||||
m_upHoldingSince = espchrono::millis_clock::now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_downHoldingSince && (espchrono::ago(*m_downHoldingSince) > getInitialScrollSpeed() || m_downScrolling))
|
|
||||||
{
|
|
||||||
if (espchrono::ago(*m_downHoldingSince) > getScrollSpeed())
|
|
||||||
{
|
|
||||||
m_downScrolling = true;
|
|
||||||
m_rotateOffset++;
|
|
||||||
m_downHoldingSince = espchrono::millis_clock::now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tft.setTextFont(4);
|
tft.setTextFont(4);
|
||||||
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
|
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
|
||||||
|
|
||||||
@ -238,4 +309,9 @@ void MenuDisplay::buttonReleased(Button button)
|
|||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuDisplay::buttonHeld(Button button)
|
||||||
|
{
|
||||||
|
ESP_LOGI("Menudisplay", "buttonHeld %d", button);
|
||||||
|
}
|
||||||
} // namespace espgui
|
} // namespace espgui
|
||||||
|
@ -39,6 +39,7 @@ public:
|
|||||||
|
|
||||||
void buttonPressed(Button button) override;
|
void buttonPressed(Button button) override;
|
||||||
void buttonReleased(Button button) override;
|
void buttonReleased(Button button) override;
|
||||||
|
void buttonHeld(Button button) override;
|
||||||
|
|
||||||
MenuDisplay *asMenuDisplay() override { return this; }
|
MenuDisplay *asMenuDisplay() override { return this; }
|
||||||
const MenuDisplay *asMenuDisplay() const override { return this; }
|
const MenuDisplay *asMenuDisplay() const override { return this; }
|
||||||
@ -157,13 +158,13 @@ private:
|
|||||||
bool m_upScrolling;
|
bool m_upScrolling;
|
||||||
std::optional<espchrono::millis_clock::time_point> m_upHoldingSince;
|
std::optional<espchrono::millis_clock::time_point> m_upHoldingSince;
|
||||||
|
|
||||||
bool m_downScrolling{};
|
bool m_downScrolling;
|
||||||
std::optional<espchrono::millis_clock::time_point> m_downHoldingSince;
|
std::optional<espchrono::millis_clock::time_point> m_downHoldingSince;
|
||||||
|
|
||||||
bool m_leftScrolling{};
|
bool m_leftScrolling;
|
||||||
std::optional<espchrono::millis_clock::time_point> m_leftHoldingSince;
|
std::optional<espchrono::millis_clock::time_point> m_leftHoldingSince;
|
||||||
|
|
||||||
bool m_rightScrolling{};
|
bool m_rightScrolling;
|
||||||
std::optional<espchrono::millis_clock::time_point> m_rightHoldingSince;
|
std::optional<espchrono::millis_clock::time_point> m_rightHoldingSince;
|
||||||
};
|
};
|
||||||
} // namespace espgui
|
} // namespace espgui
|
||||||
|
Reference in New Issue
Block a user