gps: move detection into LocationProvider, remove the legacy constructor

This commit is contained in:
Florent committed 2026-11-08 08:47:34 -04:00
1 parent 839bb165fc
commit 38fa18efb7
3 files changed
+18 -37

No files matched your search

@@ -696,31 +696,12 @@ bool EnvironmentSensorManager::setSettingValue(const char* name, const char* val
#if ENV_INCLUDE_GPS
void EnvironmentSensorManager::initBasicGPS() {
start_gps();
#ifndef PIN_GPS_EN
MESH_DEBUG_PRINTLN("No GPS wake/reset pin found for this board. Continuing on...");
#endif
#ifdef ENV_SKIP_GPS_DETECT
gps_detected = true;
#else
gps_detected = _location->detect(5000);
#endif
if (gps_detected) {
MESH_DEBUG_PRINTLN("GPS detected");
#if defined(PERSISTANT_GPS)
return;
#else
if (_location->keepEnabledAfterDetection()) {
return;
}
#endif
} else {
MESH_DEBUG_PRINTLN("No GPS detected");
}
stop_gps();
gps_detected = _location->autoDetect();
MESH_DEBUG_PRINTLN("%s", gps_detected ? "GPS detected" : "No GPS detected");
}
void EnvironmentSensorManager::start_gps() {
+16
View File
@@ -61,6 +61,22 @@ public:
virtual void drain() { }
virtual bool detect(uint32_t timeout_ms) { return false; }
virtual bool keepEnabledAfterDetection() const { return false; }
// Power on, detect, then leave the GPS on or off as the board wants.
// Returns true if a GPS is present.
virtual bool autoDetect() {
setGpsOn(true);
#ifdef ENV_SKIP_GPS_DETECT
bool found = true;
#else
bool found = detect(5000);
#endif
#ifdef PERSISTANT_GPS
if (found) return true;
#endif
if (found && keepEnabledAfterDetection()) return true;
setGpsOn(false);
return found;
}
virtual void setGpsPeriod(uint32_t seconds) { }
virtual uint32_t getGpsPeriod() const { return 0; }
virtual uint32_t getLastFixAge() const { // in seconds, UINT32_MAX if never
@@ -24,7 +24,6 @@ class MicroNMEALocationProvider : public LocationProvider {
MicroNMEA nmea;
mesh::RTCClock* _clock;
NmeaGpsDriver* _driver;
bool _ownsDriver = false;
unsigned long next_check = 0;
long time_valid = 0;
unsigned long _last_time_sync = 0;
@@ -118,21 +117,6 @@ public:
MicroNMEALocationProvider(NmeaGpsDriver& driver, mesh::RTCClock* clock = nullptr)
: nmea(_nmeaBuffer, sizeof(_nmeaBuffer)), _clock(clock), _driver(&driver) {}
// Temporary migration adapter for targets and downstream boards. New code
// should inject a GpsDriver; this constructor will be removed once targets
// have been migrated.
MicroNMEALocationProvider(UART_TYPE& serial, mesh::RTCClock* clock = nullptr,
int pin_reset = GPS_RESET, int pin_en = GPS_EN,
RefCountedDigitalPin* peripher_power = nullptr)
: nmea(_nmeaBuffer, sizeof(_nmeaBuffer)), _clock(clock),
_driver(new NmeaGpsDriver(serial, PIN_GPS_TX, PIN_GPS_RX, pin_reset, pin_en,
peripher_power)),
_ownsDriver(true) {}
~MicroNMEALocationProvider() override {
if (_ownsDriver) delete _driver;
}
void begin() override {
_begin_calls++;
const bool wasActive = _driver->isActive();