Skip to content

Commit b3a9861

Browse files
committed
Add backlight control functionality for E Ink display using the touch button
1 parent 792e930 commit b3a9861

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/graphics/Screen.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver)
533533
}
534534
}
535535

536+
#ifdef PIN_EINK_EN
537+
uint32_t backlight_peek_time = 0;
538+
#endif
539+
536540
void Screen::setup()
537541
{
538542

@@ -757,6 +761,18 @@ int32_t Screen::runOnce()
757761
enabled = false;
758762
return RUN_SAME;
759763
}
764+
#ifdef PIN_EINK_EN
765+
#ifndef BACKLIGHT_TIMEOUT_MS
766+
#define BACKLIGHT_TIMEOUT_MS 3000 // Turn off backlight after 3 seconds by default
767+
#endif
768+
// Turn off backlight after timeout
769+
if (uiconfig.screen_brightness > 0 && backlight_peek_time != 0 &&
770+
millis() - backlight_peek_time > BACKLIGHT_TIMEOUT_MS) {
771+
digitalWrite(PIN_EINK_EN, LOW);
772+
backlight_peek_time = 0;
773+
uiconfig.screen_brightness = 0;
774+
}
775+
#endif
760776

761777
if (displayHeight == 0) {
762778
displayHeight = dispdev->getHeight();
@@ -1771,6 +1787,16 @@ int Screen::handleInputEvent(const InputEvent *event)
17711787
showFrame(FrameDirection::PREVIOUS);
17721788
} else if (event->inputEvent == INPUT_BROKER_CANCEL) {
17731789
setOn(false);
1790+
#ifdef PIN_EINK_EN
1791+
} else if (event->inputEvent == INPUT_BROKER_BACKLIGHT) {
1792+
digitalWrite(PIN_EINK_EN, HIGH);
1793+
backlight_peek_time = millis();
1794+
uiconfig.screen_brightness = 1;
1795+
} else if (event->inputEvent == INPUT_BROKER_BACKLIGHT_TOGGLE) {
1796+
uiconfig.screen_brightness = 1 - uiconfig.screen_brightness;
1797+
digitalWrite(PIN_EINK_EN, uiconfig.screen_brightness == 0 ? LOW : HIGH);
1798+
backlight_peek_time = 0;
1799+
#endif
17741800
}
17751801
}
17761802
}

src/input/InputBroker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ enum input_broker_event {
2121
INPUT_BROKER_RIGHT = 20,
2222
INPUT_BROKER_CANCEL = 24,
2323
INPUT_BROKER_BACK = 27,
24+
INPUT_BROKER_BACKLIGHT = 28,
25+
INPUT_BROKER_BACKLIGHT_TOGGLE = 29,
2426
INPUT_BROKER_USER_PRESS,
2527
INPUT_BROKER_ALT_PRESS,
2628
INPUT_BROKER_ALT_LONG,

src/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,10 @@ void setup()
10521052
BaseType_t higherWake = 0;
10531053
mainDelay.interruptFromISR(&higherWake);
10541054
};
1055+
#if defined(TTGO_T_ECHO) && defined(PIN_EINK_EN)
1056+
touchConfig.singlePress = INPUT_BROKER_BACKLIGHT;
1057+
touchConfig.longPress = INPUT_BROKER_BACKLIGHT_TOGGLE;
1058+
#else
10551059
touchConfig.singlePress = INPUT_BROKER_NONE;
10561060
touchConfig.longPress = INPUT_BROKER_BACK;
10571061
#if defined(TTGO_T_ECHO_PLUS) && defined(PIN_EINK_EN)
@@ -1072,8 +1076,8 @@ void setup()
10721076
touchBacklightActive = false;
10731077
};
10741078
#endif
1075-
TouchButtonThread->initButton(touchConfig);
10761079
#endif
1080+
TouchButtonThread->initButton(touchConfig);
10771081

10781082
#if defined(CANCEL_BUTTON_PIN)
10791083
// Buttons. Moved here cause we need NodeDB to be initialized

0 commit comments

Comments
 (0)