don't expose GPD setting unless GPS is connected.

This commit is contained in:
JQ 2025-05-11 09:32:34 -07:00
parent b92e2abe75
commit e88a710d0f
2 changed files with 26 additions and 4 deletions

View file

@ -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 {

View file

@ -11,6 +11,7 @@
class T114SensorManager : public SensorManager {
bool gps_active = false;
bool gps_detected = false;
LocationProvider* _location;
void start_gps();