diff --git a/variants/t114/target.cpp b/variants/t114/target.cpp index f59227f4..e8773dbb 100644 --- a/variants/t114/target.cpp +++ b/variants/t114/target.cpp @@ -87,6 +87,25 @@ void T114SensorManager::stop_gps() { bool T114SensorManager::begin() { Serial1.begin(9600); + + // Try to detect if GPS is physically connected to determine if we should expose the setting + pinMode(GPS_EN, OUTPUT); + digitalWrite(GPS_EN, HIGH); // Power on GPS + + // Give GPS a moment to power up and send data + delay(500); + + // We'll consider GPS detected if we see any data on Serial1 + gps_detected = (Serial1.available() > 0); + + if (gps_detected) { + MESH_DEBUG_PRINTLN("GPS detected"); + digitalWrite(GPS_EN, LOW); // Power off GPS until the setting is changed + } else { + MESH_DEBUG_PRINTLN("No GPS detected"); + digitalWrite(GPS_EN, LOW); + } + return true; } @@ -112,21 +131,23 @@ void T114SensorManager::loop() { } } -int T114SensorManager::getNumSettings() const { return 1; } // just one supported: "gps" (power switch) +int T114SensorManager::getNumSettings() const { + return gps_detected ? 1 : 0; // only show GPS setting if GPS is detected +} const char* T114SensorManager::getSettingName(int i) const { - return i == 0 ? "gps" : NULL; + return (gps_detected && i == 0) ? "gps" : NULL; } const char* T114SensorManager::getSettingValue(int i) const { - if (i == 0) { + if (gps_detected && i == 0) { return gps_active ? "1" : "0"; } return NULL; } bool T114SensorManager::setSettingValue(const char* name, const char* value) { - if (strcmp(name, "gps") == 0) { + if (gps_detected && strcmp(name, "gps") == 0) { if (strcmp(value, "0") == 0) { stop_gps(); } else { diff --git a/variants/t114/target.h b/variants/t114/target.h index 308fb7b9..38d0e02a 100644 --- a/variants/t114/target.h +++ b/variants/t114/target.h @@ -11,6 +11,7 @@ class T114SensorManager : public SensorManager { bool gps_active = false; + bool gps_detected = false; LocationProvider* _location; void start_gps();