Add inactivity counter reset to LVGL device drivers

This commit is contained in:
Raphael Coeffic
2022-06-13 22:43:45 +02:00
committed by Raphael Coeffic
parent 1b9cce9882
commit 3ae39a3050
6 changed files with 103 additions and 134 deletions
+14
View File
@@ -36,6 +36,14 @@ static lv_indev_drv_t rotaryDriver;
static lv_indev_t* rotaryDevice = nullptr;
static lv_indev_t* keyboardDevice = nullptr;
static void reset_inactivity()
{
inactivity.counter = 0;
if (g_eeGeneral.backlightMode & e_backlight_mode_keys) {
resetBacklightTimeout();
}
}
static lv_obj_t* get_focus_obj(lv_indev_t* indev)
{
lv_group_t * g = indev->group;
@@ -179,6 +187,9 @@ extern "C" void touchDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data)
copy_ts_to_indev_data(st, data);
}
// Reset inactivity counters
if (st.event != TE_NONE) { reset_inactivity(); }
backup_touch_data(data);
#endif
}
@@ -194,6 +205,9 @@ static void rotaryDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data)
data->enc_diff = (int16_t)diff;
data->state = LV_INDEV_STATE_RELEASED;
// Reset inactivity counters
if (diff != 0) { reset_inactivity(); }
}
#endif
+37 -65
View File
@@ -89,32 +89,6 @@ void ColorEditorContent::setRGB()
}
#if defined(HARDWARE_TOUCH)
bool ColorEditorContent::onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY)
{
if (touchState.event == TE_SLIDE_END) {
sliding = false;
colorPicking = false;
invalidate();
} else if (sliding) {
x -= SCREEN_LEFT_MARGIN;
x = max(x, 0);
x = min(x, MAX_HUE);
if (hue != x) {
hue = x;
setRGB();
}
} else if (colorPicking) {
s = min((x - SCREEN_LEFT_MARGIN) / 2, MAX_SATURATION);
s = max(s, 0);
v = min(MAX_BRIGHTNESS - ((y - GRID_TOP_MARGIN)), MAX_BRIGHTNESS);
v = max(v, 0);
setRGB();
}
return true;
}
bool ColorEditorContent::onTouchEnd(coord_t x, coord_t y)
{
sliding = false;
@@ -125,28 +99,30 @@ bool ColorEditorContent::onTouchEnd(coord_t x, coord_t y)
bool ColorEditorContent::onTouchStart(coord_t x, coord_t y)
{
if (! sliding && (y > HUE_BAR_TOP_MARGIN && y < HUE_BAR_TOP_MARGIN + HUE_BAR_HEIGHT))
{
if (!sliding &&
(y > HUE_BAR_TOP_MARGIN && y < HUE_BAR_TOP_MARGIN + HUE_BAR_HEIGHT)) {
hue = x - SCREEN_LEFT_MARGIN;
hue = max(hue, 0);
hue = min(hue, MAX_HUE);
sliding = true;
invalidate();
} else if (x >= SCREEN_LEFT_MARGIN && x <= SCREEN_LEFT_MARGIN + (MAX_SATURATION * 2) && y >= GRID_TOP_MARGIN && y <= GRID_TOP_MARGIN + MAX_BRIGHTNESS) {
} else if (x >= SCREEN_LEFT_MARGIN &&
x <= SCREEN_LEFT_MARGIN + (MAX_SATURATION * 2) &&
y >= GRID_TOP_MARGIN && y <= GRID_TOP_MARGIN + MAX_BRIGHTNESS) {
colorPicking = true;
v = min(MAX_BRIGHTNESS - (y - GRID_TOP_MARGIN), MAX_BRIGHTNESS);
s = min((x - SCREEN_LEFT_MARGIN) / 2, MAX_SATURATION);
setRGB();
}
return true;
}
#endif
#if defined(HARDWARE_KEYS)
void ColorEditorContent::onEvent(event_t event)
{
#if defined(HARDWARE_KEYS)
int oldSliderVal = hue;
if (event == EVT_ROTARY_LEFT) {
hue -= 2;
@@ -162,9 +138,8 @@ void ColorEditorContent::onEvent(event_t event)
if (hue != oldSliderVal) {
invalidate();
}
}
#endif
}
void ColorEditorContent::drawHueBar(BitmapBuffer *dc)
{
@@ -173,12 +148,16 @@ void ColorEditorContent::drawHueBar(BitmapBuffer *dc)
auto r = GET_RED(rgb);
auto g = GET_GREEN(rgb);
auto b = GET_BLUE(rgb);
dc->drawSolidVerticalLine(i + SCREEN_LEFT_MARGIN, HUE_BAR_TOP_MARGIN, HUE_BAR_HEIGHT, COLOR2FLAGS(RGB(r, g, b)));
dc->drawSolidVerticalLine(i + SCREEN_LEFT_MARGIN, HUE_BAR_TOP_MARGIN,
HUE_BAR_HEIGHT, COLOR2FLAGS(RGB(r, g, b)));
}
dc->drawFilledCircle(hue + SCREEN_LEFT_MARGIN, HUE_BAR_TOP_MARGIN + (HUE_BAR_HEIGHT / 2), 5, COLOR2FLAGS(WHITE));
dc->drawFilledCircle(hue + SCREEN_LEFT_MARGIN,
HUE_BAR_TOP_MARGIN + (HUE_BAR_HEIGHT / 2), 5,
COLOR2FLAGS(WHITE));
if (sliding) {
dc->drawText(hue + (SCREEN_LEFT_MARGIN / 2), 25, std::to_string(hue).c_str(), FONT(XXS) | COLOR2FLAGS(WHITE));
dc->drawText(hue + (SCREEN_LEFT_MARGIN / 2), 25,
std::to_string(hue).c_str(), FONT(XXS) | COLOR2FLAGS(WHITE));
}
}
@@ -187,20 +166,26 @@ void ColorEditorContent::drawGrid(BitmapBuffer *dc)
for (int s = 0; s <= MAX_SATURATION; s++) {
for (int v = MAX_BRIGHTNESS; v >= 0; v--) {
uint32_t rgbVal = HSVtoRGB(hue, s, v);
dc->drawPixel((s * 2) + SCREEN_LEFT_MARGIN , ((MAX_BRIGHTNESS - v)) + GRID_TOP_MARGIN, rgbVal);
dc->drawPixel((s * 2) + SCREEN_LEFT_MARGIN + 1, ((MAX_BRIGHTNESS - v)) + GRID_TOP_MARGIN, rgbVal);
dc->drawPixel((s * 2) + SCREEN_LEFT_MARGIN,
((MAX_BRIGHTNESS - v)) + GRID_TOP_MARGIN, rgbVal);
dc->drawPixel((s * 2) + SCREEN_LEFT_MARGIN + 1,
((MAX_BRIGHTNESS - v)) + GRID_TOP_MARGIN, rgbVal);
}
}
dc->drawFilledCircle((this->s * 2) + SCREEN_LEFT_MARGIN, (MAX_BRIGHTNESS - this->v) + GRID_TOP_MARGIN, 3, COLOR2FLAGS(WHITE));
dc->drawFilledCircle((this->s * 2) + SCREEN_LEFT_MARGIN,
(MAX_BRIGHTNESS - this->v) + GRID_TOP_MARGIN, 3,
COLOR2FLAGS(WHITE));
}
void ColorEditorContent::drawColorBox(BitmapBuffer *dc)
{
int32_t rgb = RGB(r,g,b);
int32_t rgb = RGB(r, g, b);
dc->drawSolidFilledRect(COLOR_BOX_LEFT, COLOR_BOX_TOP, COLOR_BOX_WIDTH, COLOR_BOX_HEIGHT, COLOR2FLAGS(rgb));
dc->drawSolidRect(COLOR_BOX_LEFT, COLOR_BOX_TOP, COLOR_BOX_WIDTH, COLOR_BOX_HEIGHT, 1, COLOR2FLAGS(BLACK));
dc->drawSolidFilledRect(COLOR_BOX_LEFT, COLOR_BOX_TOP, COLOR_BOX_WIDTH,
COLOR_BOX_HEIGHT, COLOR2FLAGS(rgb));
dc->drawSolidRect(COLOR_BOX_LEFT, COLOR_BOX_TOP, COLOR_BOX_WIDTH,
COLOR_BOX_HEIGHT, 1, COLOR2FLAGS(BLACK));
}
void ColorEditorContent::paint(BitmapBuffer *dc)
@@ -212,18 +197,17 @@ void ColorEditorContent::paint(BitmapBuffer *dc)
}
////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///// ColorEditorPopup
////////////////////////////////////////////////////////////////////////////////////////////////
ColorEditorPopup::ColorEditorPopup(Window *window, std::function<uint32_t ()> getValue, std::function<void (uint32_t value)> setValue) :
ModalWindow(window, true),
_getValue(getValue),
_setValue(setValue)
///////////////////////////////////////////////////////////////////////////
ColorEditorPopup::ColorEditorPopup(
Window *window, std::function<uint32_t()> getValue,
std::function<void(uint32_t value)> setValue) :
ModalWindow(window, true), _getValue(getValue), _setValue(setValue)
{
color = _getValue();
content = new ColorEditorContent(this, contentRect, color, [=] (uint32_t rgb) {
if (_setValue != nullptr)
_setValue(rgb);
content = new ColorEditorContent(this, contentRect, color, [=](uint32_t rgb) {
if (_setValue != nullptr) _setValue(rgb);
});
bringToTop();
@@ -232,17 +216,9 @@ ColorEditorPopup::ColorEditorPopup(Window *window, std::function<uint32_t ()> ge
}
#if defined(HARDWARE_TOUCH)
bool ColorEditorPopup::onTouchStart(coord_t x, coord_t y)
{
TRACE("ColorEditorPopup::onTouchStart");
// content->onTouchStart(x - content->rect.x + content->scrollPositionX, y - content->rect.y + content->scrollPositionY);
return true;
}
bool ColorEditorPopup::onTouchEnd(coord_t x, coord_t y)
{
TRACE("ColorEditorPopup::onTouchEnd");
// content->onTouchEnd(x - content->rect.x + content->scrollPositionX, y - content->rect.y + content->scrollPositionY);
if (!Window::onTouchEnd(x, y) && closeWhenClickOutside) {
onKeyPress();
deleteLater();
@@ -253,11 +229,7 @@ bool ColorEditorPopup::onTouchEnd(coord_t x, coord_t y)
void ColorEditorPopup::deleteLater(bool detach, bool trash)
{
if (_deleted)
return;
if (_deleted) return;
Layer::pop(this);
Window::deleteLater(detach, trash);
}
+34 -43
View File
@@ -31,68 +31,59 @@
class ColorEditorContent : public ModalWindowContent
{
friend class ColorEditorPopup;
public:
ColorEditorContent(ModalWindow *window, const rect_t rect, uint32_t color, std::function<void (uint32_t rgb)> setValue = nullptr);
public:
ColorEditorContent(ModalWindow *window, const rect_t rect, uint32_t color,
std::function<void(uint32_t rgb)> setValue = nullptr);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "ColorEditorContent";
}
std::string getName() const override { return "ColorEditorContent"; }
#endif
#if defined(HARDWARE_TOUCH)
bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY) override;
bool onTouchEnd(coord_t x, coord_t y) override;
bool onTouchStart(coord_t x, coord_t y) override;
bool onTouchEnd(coord_t x, coord_t y) override;
bool onTouchStart(coord_t x, coord_t y) override;
#endif
#if defined(HARDWARE_KEYS)
void onEvent(event_t event) override;
#endif
void onEvent(event_t event) override;
void paint(BitmapBuffer *dc) override;
void paint(BitmapBuffer *dc) override;
protected:
bool sliding = false;
bool colorPicking = false;
int r, g, b;
int hue = 0, s, v;
NumberEdit *rEdit;
NumberEdit *gEdit;
NumberEdit *bEdit;
protected:
bool sliding = false;
bool colorPicking = false;
int r, g, b;
int hue = 0, s, v;
NumberEdit *rEdit;
NumberEdit *gEdit;
NumberEdit *bEdit;
void drawHueBar(BitmapBuffer *dc);
void drawGrid(BitmapBuffer *dc);
void drawColorBox(BitmapBuffer *dc);
void setRGB();
std::function<void (uint32_t rgb)> setValue;
void drawHueBar(BitmapBuffer *dc);
void drawGrid(BitmapBuffer *dc);
void drawColorBox(BitmapBuffer *dc);
void setRGB();
std::function<void(uint32_t rgb)> setValue;
};
// a color editor popup
class ColorEditorPopup : public ModalWindow
{
public:
ColorEditorPopup(Window *window, std::function<uint32_t ()> getValue, std::function<void (uint32_t value)> setValue = nullptr);
void deleteLater(bool detach = true, bool trash = true) override;
public:
ColorEditorPopup(Window *window, std::function<uint32_t()> getValue,
std::function<void(uint32_t value)> setValue = nullptr);
void deleteLater(bool detach = true, bool trash = true) override;
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "ColorEditorPopup";
}
std::string getName() const override { return "ColorEditorPopup"; }
#endif
#if defined(HARDWARE_TOUCH)
bool onTouchStart(coord_t x, coord_t y) override;
bool onTouchEnd(coord_t x, coord_t y) override;
bool onTouchEnd(coord_t x, coord_t y) override;
#endif
protected:
uint32_t color;
ColorEditorContent *content;
std::function<uint32_t ()> _getValue;
std::function<void (uint32_t value)> _setValue;
protected:
uint32_t color;
ColorEditorContent *content;
std::function<uint32_t()> _getValue;
std::function<void(uint32_t value)> _setValue;
};
+8 -8
View File
@@ -154,10 +154,10 @@ void FullScreenDialog::runForever()
{
running = true;
MainWindow* mainWin = MainWindow::instance();
#if defined(HARDWARE_TOUCH)
mainWin->setTouchEnabled(true);
#endif
// MainWindow* mainWin = MainWindow::instance();
// #if defined(HARDWARE_TOUCH)
// mainWin->setTouchEnabled(true);
// #endif
// reset input devices to avoid
// RELEASED/CLICKED to be called in a loop
@@ -188,10 +188,10 @@ void FullScreenDialog::runForeverNoPwrCheck()
{
running = true;
MainWindow* mainWin = MainWindow::instance();
#if defined(HARDWARE_TOUCH)
mainWin->setTouchEnabled(true);
#endif
// MainWindow* mainWin = MainWindow::instance();
// #if defined(HARDWARE_TOUCH)
// mainWin->setTouchEnabled(true);
// #endif
while (running) {
resetBacklightTimeout();
run_ui_manually();
+9 -17
View File
@@ -564,23 +564,15 @@ void checkBacklight()
}
}
#if defined(HARDWARE_TOUCH)
if (MainWindow::instance()->touchEventOccured()) {
inactivity.counter = 0;
if (g_eeGeneral.backlightMode & e_backlight_mode_keys) {
resetBacklightTimeout();
}
}
#endif
if (requiredBacklightBright == BACKLIGHT_FORCED_ON) {
currentBacklightBright = g_eeGeneral.backlightBright;
BACKLIGHT_ENABLE();
}
else {
} else {
bool backlightOn = ((g_eeGeneral.backlightMode == e_backlight_mode_on) ||
(g_eeGeneral.backlightMode != e_backlight_mode_off && lightOffCounter) ||
(g_eeGeneral.backlightMode == e_backlight_mode_off && isFunctionActive(FUNCTION_BACKLIGHT)));
(g_eeGeneral.backlightMode != e_backlight_mode_off &&
lightOffCounter) ||
(g_eeGeneral.backlightMode == e_backlight_mode_off &&
isFunctionActive(FUNCTION_BACKLIGHT)));
if (flashCounter) {
backlightOn = !backlightOn;
@@ -589,12 +581,11 @@ void checkBacklight()
currentBacklightBright = requiredBacklightBright;
#if defined(COLORLCD)
// force backlight on for color lcd radios
if(currentBacklightBright > BACKLIGHT_LEVEL_MAX - BACKLIGHT_LEVEL_MIN)
if (currentBacklightBright > BACKLIGHT_LEVEL_MAX - BACKLIGHT_LEVEL_MIN)
currentBacklightBright = BACKLIGHT_LEVEL_MAX - BACKLIGHT_LEVEL_MIN;
#endif
BACKLIGHT_ENABLE();
}
else {
} else {
BACKLIGHT_DISABLE();
}
}
@@ -605,7 +596,8 @@ void resetBacklightTimeout()
{
uint16_t autoOff = g_eeGeneral.lightAutoOff;
#if defined(COLORLCD)
autoOff = std::max<uint16_t>(1, autoOff); // prevent the timeout from being 0 seconds on color lcd radios
// prevent the timeout from being 0 seconds on color lcd radios
autoOff = std::max<uint16_t>(1, autoOff);
#endif
lightOffCounter = (autoOff*250) << 1;
}