From f4af02544ec1f220dd89541e5cb0985a5d147b6d Mon Sep 17 00:00:00 2001 From: whywilson Date: Mon, 28 Jul 2025 08:27:29 +0800 Subject: [PATCH] Add osk_found On-Screen Keyboard found as the global variable. --- src/input/RotaryEncoderInterruptImpl1.cpp | 2 ++ src/input/UpDownInterruptImpl1.cpp | 2 ++ src/main.cpp | 6 ++++++ src/main.h | 1 + src/modules/CannedMessageModule.cpp | 24 +++-------------------- 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/input/RotaryEncoderInterruptImpl1.cpp b/src/input/RotaryEncoderInterruptImpl1.cpp index 4f19c8b0b..f17b02483 100644 --- a/src/input/RotaryEncoderInterruptImpl1.cpp +++ b/src/input/RotaryEncoderInterruptImpl1.cpp @@ -1,5 +1,6 @@ #include "RotaryEncoderInterruptImpl1.h" #include "InputBroker.h" +extern bool osk_found; RotaryEncoderInterruptImpl1 *rotaryEncoderInterruptImpl1; @@ -25,6 +26,7 @@ bool RotaryEncoderInterruptImpl1::init() RotaryEncoderInterruptImpl1::handleIntA, RotaryEncoderInterruptImpl1::handleIntB, RotaryEncoderInterruptImpl1::handleIntPressed); inputBroker->registerSource(this); + osk_found = true; return true; } diff --git a/src/input/UpDownInterruptImpl1.cpp b/src/input/UpDownInterruptImpl1.cpp index 66623e607..7e71e6428 100644 --- a/src/input/UpDownInterruptImpl1.cpp +++ b/src/input/UpDownInterruptImpl1.cpp @@ -1,5 +1,6 @@ #include "UpDownInterruptImpl1.h" #include "InputBroker.h" +extern bool osk_found; UpDownInterruptImpl1 *upDownInterruptImpl1; @@ -28,6 +29,7 @@ bool UpDownInterruptImpl1::init() eventDownLong, UpDownInterruptImpl1::handleIntDown, UpDownInterruptImpl1::handleIntUp, UpDownInterruptImpl1::handleIntPressed); inputBroker->registerSource(this); + osk_found = true; return true; } diff --git a/src/main.cpp b/src/main.cpp index 1868d98c7..72ce52fcd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -187,6 +187,8 @@ ScanI2C::DeviceAddress cardkb_found = ScanI2C::ADDRESS_NONE; uint8_t kb_model; // global bool to record that a kb is present bool kb_found = false; +// global bool to record that on-screen keyboard (OSK) is present +bool osk_found = false; // The I2C address of the RTC Module (if found) ScanI2C::DeviceAddress rtc_found = ScanI2C::ADDRESS_NONE; @@ -1390,6 +1392,10 @@ void setup() #endif #endif +#if defined(HAS_TRACKBALL) || (defined(INPUTDRIVER_ENCODER_TYPE) && INPUTDRIVER_ENCODER_TYPE == 2) + osk_found = true; +#endif + #if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_WEBSERVER // Start web server thread. webServerThread = new WebServerThread(); diff --git a/src/main.h b/src/main.h index 7105bd62b..15ac16533 100644 --- a/src/main.h +++ b/src/main.h @@ -32,6 +32,7 @@ extern ScanI2C::DeviceAddress screen_found; extern ScanI2C::DeviceAddress cardkb_found; extern uint8_t kb_model; extern bool kb_found; +extern bool osk_found; extern ScanI2C::DeviceAddress rtc_found; extern ScanI2C::DeviceAddress accelerometer_found; extern ScanI2C::FoundDevice rgb_found; diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 7cafbc8a7..7ab52d7c5 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -42,6 +42,7 @@ extern ScanI2C::DeviceAddress cardkb_found; extern bool graphics::isMuted; +extern bool osk_found; static const char *cannedMessagesConfigFile = "/prefs/cannedConf.proto"; @@ -125,20 +126,11 @@ int CannedMessageModule::splitConfiguredMessages() int tempCount = 0; // Insert at position 0 (top) tempMessages[tempCount++] = "[Select Destination]"; - #if defined(USE_VIRTUAL_KEYBOARD) // Add a "Free Text" entry at the top if using a touch screen virtual keyboard tempMessages[tempCount++] = "[-- Free Text --]"; #else - // For devices with encoder input or trackball, also add Free Text option -#if HAS_TRACKBALL - extern TrackballInterruptImpl1 *trackballInterruptImpl1; - if (trackballInterruptImpl1) { -#else - extern RotaryEncoderInterruptImpl1 *rotaryEncoderInterruptImpl1; - extern UpDownInterruptImpl1 *upDownInterruptImpl1; - if (rotaryEncoderInterruptImpl1 || upDownInterruptImpl1) { -#endif + if (osk_found && screen) { tempMessages[tempCount++] = "[-- Free Text --]"; } #endif @@ -610,18 +602,9 @@ bool CannedMessageModule::handleMessageSelectorInput(const InputEvent *event, bo } #else if (strcmp(current, "[-- Free Text --]") == 0) { -#if HAS_TRACKBALL - extern TrackballInterruptImpl1 *trackballInterruptImpl1; - if (trackballInterruptImpl1 && screen) { -#else - extern RotaryEncoderInterruptImpl1 *rotaryEncoderInterruptImpl1; - extern UpDownInterruptImpl1 *upDownInterruptImpl1; - if ((rotaryEncoderInterruptImpl1 || upDownInterruptImpl1) && screen) { -#endif + if (osk_found && screen) { screen->showTextInput("Free Text", "", 300000, [this](const std::string &text) { - LOG_INFO("Free text submitted: '%s'", text.c_str()); if (!text.empty()) { - LOG_INFO("Storing message for delayed sending: '%s'", text.c_str()); this->freetext = text.c_str(); this->payload = CANNED_MESSAGE_RUN_STATE_FREETEXT; runState = CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE; @@ -633,7 +616,6 @@ bool CannedMessageModule::handleMessageSelectorInput(const InputEvent *event, bo screen->forceDisplay(); setIntervalFromNow(500); - LOG_INFO("Free text callback completed safely"); return; } else { // Don't delete virtual keyboard immediately - it might still be executing