From 817be373044f03aaf74d0060c25988a94b0fe86d Mon Sep 17 00:00:00 2001 From: Guo-Rong <5484552+gkoh@users.noreply.github.com> Date: Sat, 4 Jan 2025 16:13:10 +1030 Subject: [PATCH] Add screen lock mechanism for touch screens (M5 Core2). (#155) On PWR button double-click, lock or unlock the screen. This is implemented as a modal message box that just blocks all touch input. --- README.md | 5 +++++ include/FurbleUI.h | 1 + src/FurbleUI.cpp | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 07b8932..0cdbb63 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,11 @@ During shutter control: * press and hold 'Shutter Lock' to lock shutter open * press and hold 'Shutter Lock' again to release +To activate screen lock: +* double click the PWR button + * a message box will open +* double click the PWR button to unlock + ### Menu Map * Connect (if connections are saved) diff --git a/include/FurbleUI.h b/include/FurbleUI.h index e041c86..1552105 100644 --- a/include/FurbleUI.h +++ b/include/FurbleUI.h @@ -63,6 +63,7 @@ class UI { lv_obj_t *batteryIcon; lv_obj_t *reconnectIcon; lv_obj_t *gpsData; + bool screenLocked; } status_t; class Intervalometer { diff --git a/src/FurbleUI.cpp b/src/FurbleUI.cpp index 9d31ec5..57649eb 100644 --- a/src/FurbleUI.cpp +++ b/src/FurbleUI.cpp @@ -155,6 +155,7 @@ UI::UI(const interval_t &interval) : m_GPS {GPS::getInstance()}, m_Intervalomete #else m_Status.batteryIcon = addIcon(LV_SYMBOL_BATTERY_3); #endif + m_Status.screenLocked = false; m_GPS.setIcon(m_Status.gpsIcon); @@ -193,6 +194,16 @@ UI::UI(const interval_t &interval) : m_GPS {GPS::getInstance()}, m_Intervalomete } else { lv_obj_add_flag(status->gpsIcon, LV_OBJ_FLAG_HIDDEN); } + + static lv_obj_t *lockMsgBox = NULL; + if (status->screenLocked && (lockMsgBox == NULL)) { + lockMsgBox = lv_msgbox_create(NULL); + lv_msgbox_add_title(lockMsgBox, "Screen Locked"); + lv_msgbox_add_text(lockMsgBox, "Double-click PWR button to unlock."); + } else if (!status->screenLocked && (lockMsgBox != NULL)) { + lv_msgbox_close_async(lockMsgBox); + lockMsgBox = NULL; + } }, 250, &m_Status); @@ -1780,6 +1791,14 @@ void UI::task(void) { // fake PMIC button as actual button m_PMICClicked = true; } + + // toggle screen lock on power button double click for touch screens + if (M5.Touch.isEnabled()) { + if (M5.BtnPWR.wasDoubleClicked()) { + m_Status.screenLocked = !m_Status.screenLocked; + } + } + m_Mutex.lock(); lv_task_handler(); m_Mutex.unlock();