Skip to content

Commit 075caef

Browse files
committed
Add backlight control functionality for E Ink display using the touch button
1 parent 17b075a commit 075caef

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/graphics/Screen.cpp

Lines changed: 26 additions & 3 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();
@@ -1429,9 +1445,6 @@ int Screen::handleStatusUpdate(const meshtastic::Status *arg)
14291445
}
14301446
nodeDB->updateGUI = false;
14311447
break;
1432-
case STATUS_TYPE_POWER:
1433-
forceDisplay(true);
1434-
break;
14351448
}
14361449

14371450
return 0;
@@ -1766,6 +1779,16 @@ int Screen::handleInputEvent(const InputEvent *event)
17661779
showFrame(FrameDirection::PREVIOUS);
17671780
} else if (event->inputEvent == INPUT_BROKER_CANCEL) {
17681781
setOn(false);
1782+
#ifdef PIN_EINK_EN
1783+
} else if (event->inputEvent == INPUT_BROKER_BACKLIGHT) {
1784+
digitalWrite(PIN_EINK_EN, HIGH);
1785+
backlight_peek_time = millis();
1786+
uiconfig.screen_brightness = 1;
1787+
} else if (event->inputEvent == INPUT_BROKER_BACKLIGHT_TOGGLE) {
1788+
uiconfig.screen_brightness = 1 - uiconfig.screen_brightness;
1789+
digitalWrite(PIN_EINK_EN, uiconfig.screen_brightness == 0 ? LOW : HIGH);
1790+
backlight_peek_time = 0;
1791+
#endif
17691792
}
17701793
}
17711794
}

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,8 +1044,13 @@ void setup()
10441044
BaseType_t higherWake = 0;
10451045
mainDelay.interruptFromISR(&higherWake);
10461046
};
1047+
#ifdef PIN_EINK_EN
1048+
touchConfig.singlePress = INPUT_BROKER_BACKLIGHT;
1049+
touchConfig.longPress = INPUT_BROKER_BACKLIGHT_TOGGLE;
1050+
#else
10471051
touchConfig.singlePress = INPUT_BROKER_NONE;
10481052
touchConfig.longPress = INPUT_BROKER_BACK;
1053+
#endif
10491054
TouchButtonThread->initButton(touchConfig);
10501055
#endif
10511056

0 commit comments

Comments
 (0)