gps: once command

This commit is contained in:
Florent committed 2026-11-08 08:47:35 -04:00
1 parent 38fa18efb7
commit c06def2f41
4 files changed
+64

No files matched your search

+27
View File
@@ -97,6 +97,33 @@ bool CommonGpsPrefs::handleCommand(const char* command, SensorManager& sensors,
}
return true;
}
if (memcmp(command, "gps once", 8) == 0) { // before "gps on"
LocationProvider* location = sensors.getLocationProvider();
if (location == nullptr) {
strcpy(reply, "gps provider not found");
return true;
}
if (location->hasHardwareEnableState() && !location->isHardwareEnabled()) {
strcpy(reply, "gps hw switch off");
return true;
}
if (strstr(command, " -s") != nullptr) location->syncTime();
const char* state = !location->isGpsOn() ? "turning on and acquiring"
: (location->getGpsPeriod() > 0 && !location->isActive()) ? "waking gps"
: "gps already on";
if (location->startOnce()) {
snprintf(reply, 160, "ok (%s)", state);
} else {
strcpy(reply, "gps once not supported");
}
return true;
}
if (memcmp(command, "gps on", 6) == 0) {
if (!setGpsEnabled(sensors, true)) {
strcpy(reply, "gps toggle not found");
+1
View File
@@ -86,6 +86,7 @@ public:
virtual bool hasHardwareEnableState() const { return false; }
virtual bool isHardwareEnabled() const { return true; }
virtual bool isGpsOn() const { return _gpsOn; }
virtual bool startOnce() { return false; }
virtual void setGpsOn(bool on) {
_gpsOn = on;
if (on) {
@@ -32,6 +32,7 @@ class MicroNMEALocationProvider : public LocationProvider {
unsigned long _acquisitionStarted = 0;
unsigned long _firstFixInWindow = 0;
bool _acquiringPeriodically = false;
unsigned long _onceDeadline = 0;
static const unsigned long TIME_SYNC_INTERVAL = 1800000;
uint32_t _uart_bytes = 0;
@@ -119,6 +120,7 @@ public:
void begin() override {
_begin_calls++;
_onceDeadline = 0;
const bool wasActive = _driver->isActive();
_driver->begin();
if (!wasActive) {
@@ -140,6 +142,7 @@ public:
void stop() override {
_stop_calls++;
_onceDeadline = 0;
_acquiringPeriodically = false;
_driver->stop();
nmea.clear();
@@ -172,6 +175,16 @@ public:
return _gpsPeriodSeconds;
}
bool startOnce() override {
if (_gpsOn) { // already on, acquire now
_nextAcquisition = millis();
return true;
}
setGpsOn(true);
_onceDeadline = millis() + GPS_PERIODIC_ACQUISITION_TIMEOUT_MS;
return true;
}
void syncTime() override {
nmea.clear();
LocationProvider::syncTime();
@@ -232,6 +245,21 @@ public:
void loop() override {
if (_driver->pollGpsSwitch()) _gpsOn = true;
if (_onceDeadline != 0) {
if (_firstFixInWindow != 0 && (long)(_onceDeadline - (millis() + GPS_FIX_SETTLE_MS)) > 0) {
_onceDeadline = millis() + GPS_FIX_SETTLE_MS;
}
if ((long)(millis() - _onceDeadline) >= 0) {
if (_driver->isActive()) {
setGpsOn(false);
} else { // do not stop twice
_gpsOn = false;
_onceDeadline = 0;
_acquiringPeriodically = false;
}
}
}
if (_gpsOn && _gpsPeriodSeconds > 0 && !_acquiringPeriodically &&
(long)(millis() - _nextAcquisition) >= 0) {
startPeriodicAcquisition();
@@ -190,6 +190,14 @@ public:
return _gpsPeriodSeconds;
}
bool isGpsOn() const override {
return _useI2c ? _gpsOn : _nmea.isGpsOn();
}
bool startOnce() override {
return _useI2c ? false : _nmea.startOnce(); // not supported on the RAK12500
}
void setGpsOn(bool on) override {
if (_useI2c) LocationProvider::setGpsOn(on);
else { _gpsOn = on; _nmea.setGpsOn(on); }