diff --git a/src/input/ButtonThread.cpp b/src/input/ButtonThread.cpp index 29f56dba5f..251311df75 100644 --- a/src/input/ButtonThread.cpp +++ b/src/input/ButtonThread.cpp @@ -102,7 +102,9 @@ bool ButtonThread::initButton(const ButtonConfig &config) #endif userButton.setPressMs(_longPressTime); - if (screen) { + // The 20ms window a screen normally gets closes before a second click can land, so boards + // binding double or multi click need the full one. + if (screen && _doublePress == INPUT_BROKER_NONE && _triplePress == INPUT_BROKER_NONE) { userButton.setClickMs(20); } else { userButton.setClickMs(BUTTON_CLICK_MS); @@ -225,15 +227,8 @@ int32_t ButtonThread::runOnce() break; } - case BUTTON_EVENT_DOUBLE_PRESSED: { // not wired in if screen detected + case BUTTON_EVENT_DOUBLE_PRESSED: { // only on boards binding ButtonConfig::doublePress LOG_INFO("Double press"); -#if defined(ELECROW_ThinkNode_M8) - if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED) - config.device.buzzer_mode = meshtastic_Config_DeviceConfig_BuzzerMode_DISABLED; - else if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_DISABLED) - config.device.buzzer_mode = meshtastic_Config_DeviceConfig_BuzzerMode_ALL_ENABLED; - service->reloadConfig(SEGMENT_CONFIG); -#endif // Reset combination tracking waitingForLongPress = false; diff --git a/src/input/InputBroker.cpp b/src/input/InputBroker.cpp index 429ecd7eaa..7b0f830c59 100644 --- a/src/input/InputBroker.cpp +++ b/src/input/InputBroker.cpp @@ -382,7 +382,7 @@ void InputBroker::Init() userConfig.singlePress = INPUT_BROKER_SEND_PING; userConfig.longPress = INPUT_BROKER_SHUTDOWN; userConfig.longPressTime = 5000; - userConfig.doublePress = INPUT_BROKER_GPS_TOGGLE; + userConfig.doublePress = INPUT_BROKER_PRIVACY_TOGGLE; UserButtonThread->initButton(userConfig); } #else diff --git a/src/input/InputBroker.h b/src/input/InputBroker.h index 975c9d9f4a..e30e84ff7b 100644 --- a/src/input/InputBroker.h +++ b/src/input/InputBroker.h @@ -28,6 +28,7 @@ enum input_broker_event { INPUT_BROKER_FACTORY_RST = 0x9a, INPUT_BROKER_SHUTDOWN = 0x9b, INPUT_BROKER_GPS_TOGGLE = 0x9e, + INPUT_BROKER_PRIVACY_TOGGLE = 0x9f, // GPS and buzzer off together, and back on together INPUT_BROKER_SEND_PING = 0xaf, INPUT_BROKER_FN_F1 = 0xf1, INPUT_BROKER_FN_F2 = 0xf2, diff --git a/src/modules/SystemCommandsModule.cpp b/src/modules/SystemCommandsModule.cpp index 5c4babb19a..1b31942903 100644 --- a/src/modules/SystemCommandsModule.cpp +++ b/src/modules/SystemCommandsModule.cpp @@ -86,18 +86,30 @@ int SystemCommandsModule::handleInputEvent(const InputEvent *event) } switch (event->inputEvent) { - // GPS + // GPS, on its own or together with the buzzer case INPUT_BROKER_GPS_TOGGLE: + case INPUT_BROKER_PRIVACY_TOGGLE: #if !MESHTASTIC_EXCLUDE_GPS if (gps) { - if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED && - config.position.fixed_position == false) { + const bool wasEnabled = config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED; + // toggleGpsMode() only moves between ENABLED and DISABLED, so leave the buzzer alone otherwise. + const bool withBuzzer = event->inputEvent == INPUT_BROKER_PRIVACY_TOGGLE && + (wasEnabled || config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_DISABLED); + if (wasEnabled && config.position.fixed_position == false) { nodeDB->clearLocalPosition(); nodeDB->saveToDisk(); } + if (withBuzzer) // unmute first, so the confirmation beep is audible in both directions + config.device.buzzer_mode = meshtastic_Config_DeviceConfig_BuzzerMode_ALL_ENABLED; gps->toggleGpsMode(); - const char *msg = - (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED) ? "GPS Enabled" : "GPS Disabled"; + const bool nowEnabled = config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED; + if (withBuzzer) { + config.device.buzzer_mode = nowEnabled ? meshtastic_Config_DeviceConfig_BuzzerMode_ALL_ENABLED + : meshtastic_Config_DeviceConfig_BuzzerMode_DISABLED; + nodeDB->saveToDisk(SEGMENT_CONFIG); + } + const char *msg = withBuzzer ? (nowEnabled ? "GPS + Buzzer\nEnabled" : "GPS + Buzzer\nDisabled") + : (nowEnabled ? "GPS Enabled" : "GPS Disabled"); IF_SCREEN(screen->forceDisplay(); screen->showSimpleBanner(msg, 3000);) } #endif