add configurable GPS update interval

Make GPS update interval configurable via settings instead of using hardcoded 1 second value. The interval is persisted from preferences and can be adjusted at runtime through the sensor manager settings interface
This commit is contained in:
csrutil
2025-11-29 17:20:02 +08:00
parent c641beabd3
commit 88fb173297
3 changed files with 14 additions and 1 deletions

View File

@@ -809,6 +809,9 @@ void MyMesh::begin(bool has_display) {
#if ENV_INCLUDE_GPS == 1
sensors.setSettingValue("gps", _prefs.gps_enabled ? "1" : "0");
char interval_str[12]; // Max: 24 hours = 86400 seconds (5 digits + null)
sprintf(interval_str, "%u", _prefs.gps_interval);
sensors.setSettingValue("gps_interval", interval_str);
#endif
}

View File

@@ -521,6 +521,15 @@ bool EnvironmentSensorManager::setSettingValue(const char* name, const char* val
}
return true;
}
if (strcmp(name, "gps_interval") == 0) {
uint32_t interval_seconds = atoi(value);
if (interval_seconds > 0) {
gps_update_interval_ms = interval_seconds * 1000;
} else {
gps_update_interval_ms = 1000; // Default to 1 second if 0
}
return true;
}
#endif
return false; // not supported
}
@@ -708,7 +717,7 @@ void EnvironmentSensorManager::loop() {
}
#endif
}
next_gps_update = millis() + 1000;
next_gps_update = millis() + gps_update_interval_ms;
}
#endif
}

View File

@@ -25,6 +25,7 @@ protected:
bool gps_detected = false;
bool gps_active = false;
uint32_t gps_update_interval_ms = 1000; // Default 1 second
#if ENV_INCLUDE_GPS
LocationProvider* _location;