gps: add GpsDriver, handle the hardware and software switches in the drivers

This commit is contained in:
Florent committed 2026-11-08 08:47:34 -04:00
1 parent 978b6e01be
commit 81afafcb35
28 files changed
+892 -468

No files matched your search

+4 -3
View File
@@ -26,9 +26,10 @@ VolatileRTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#if ENV_INCLUDE_GPS
#include <helpers/sensors/MicroNMEALocationProvider.h>
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
#include <helpers/sensors/RakLocationProvider.h>
RakGpsDriver gps_driver;
RakLocationProvider location(gps_driver, &rtc_clock);
EnvironmentSensorManager sensors(location);
#else
EnvironmentSensorManager sensors;
#endif
+2 -3
View File
@@ -13,7 +13,8 @@ VolatileRTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#ifdef ENV_INCLUDE_GPS
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
NmeaGpsDriver gps_driver(Serial1);
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(gps_driver, &rtc_clock);
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
#else
EnvironmentSensorManager sensors = EnvironmentSensorManager();
@@ -36,5 +37,3 @@ mesh::LocalIdentity radio_new_identity() {
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity
}
+4 -4
View File
@@ -25,9 +25,10 @@ VolatileRTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#if ENV_INCLUDE_GPS
#include <helpers/sensors/MicroNMEALocationProvider.h>
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
#include <helpers/sensors/RakLocationProvider.h>
RakGpsDriver gps_driver;
RakLocationProvider location(gps_driver, &rtc_clock);
EnvironmentSensorManager sensors(location);
#else
EnvironmentSensorManager sensors;
#endif
@@ -41,4 +42,3 @@ mesh::LocalIdentity radio_new_identity() {
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity
}
+4 -3
View File
@@ -25,9 +25,10 @@ VolatileRTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#if ENV_INCLUDE_GPS
#include <helpers/sensors/MicroNMEALocationProvider.h>
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
#include <helpers/sensors/RakLocationProvider.h>
RakGpsDriver gps_driver;
RakLocationProvider location(gps_driver, &rtc_clock);
EnvironmentSensorManager sensors(location);
#else
EnvironmentSensorManager sensors;
#endif
+1
View File
@@ -106,6 +106,7 @@ build_flags = ${t1000-e.build_flags}
; -D BLE_DEBUG_LOGGING=1
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
; -D GPS_NMEA_DEBUG
-D OFFLINE_QUEUE_SIZE=256
-D DISPLAY_CLASS=NullDisplayDriver
-D PIN_BUZZER=25
+7 -17
View File
@@ -1,8 +1,8 @@
#include <Arduino.h>
#include "t1000e_sensors.h"
#include "target.h"
#include <helpers/sensors/AirohaGpsDriver.h>
#include <helpers/sensors/MicroNMEALocationProvider.h>
#include <helpers/sensors/AirohaSleep.h>
T1000eBoard board;
@@ -11,8 +11,9 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU
WRAPPER_CLASS radio_driver(radio, board);
VolatileRTCClock rtc_clock;
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
T1000SensorManager sensors = T1000SensorManager(nmea);
AirohaGpsDriver gps_driver(Serial1);
MicroNMEALocationProvider nmea(gps_driver, &rtc_clock);
T1000SensorManager sensors(nmea, gps_driver);
#ifdef DISPLAY_CLASS
NullDisplayDriver display;
@@ -82,28 +83,17 @@ mesh::LocalIdentity radio_new_identity() {
void T1000SensorManager::start_gps() {
gps_active = true;
digitalWrite(GPS_EN, HIGH);
delay(10);
digitalWrite(GPS_RTC_INT, HIGH);
delay(5);
digitalWrite(GPS_RTC_INT, LOW);
_nmea->begin();
}
void T1000SensorManager::stop_gps() {
gps_active = false;
digitalWrite(GPS_VRTC_EN, HIGH); // keep GPS RTC alive for faster fix on wake
digitalWrite(GPS_RTC_INT, LOW); // make sure this is LOW so we can pulse it to wake
airohaEnterSleep(_nmea); // send command to put the GPS into RTC backup sleep
digitalWrite(GPS_EN, LOW);
_nmea->stop();
}
bool T1000SensorManager::begin() {
// init GPS
Serial1.begin(115200);
digitalWrite(GPS_RESET, HIGH);
delay(10);
digitalWrite(GPS_RESET, LOW);
_gps_driver->initialize();
return true;
}
+5 -1
View File
@@ -12,15 +12,19 @@
#include "NullDisplayDriver.h"
#endif
class AirohaGpsDriver;
class T1000SensorManager: public SensorManager {
bool gps_active = false;
LocationProvider * _nmea;
AirohaGpsDriver* _gps_driver;
void start_gps();
void sleep_gps();
void stop_gps();
public:
T1000SensorManager(LocationProvider &nmea): _nmea(&nmea) { }
T1000SensorManager(LocationProvider &nmea, AirohaGpsDriver& gps_driver)
: _nmea(&nmea), _gps_driver(&gps_driver) { }
bool begin() override;
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override;
void loop() override;
+8 -51
View File
@@ -2,6 +2,7 @@
#include "target.h"
#include <helpers/ArduinoHelpers.h>
#include <helpers/sensors/MicroNMEALocationProvider.h>
#include <helpers/sensors/NmeaGpsDriver.h>
ThinkNodeM1Board board;
@@ -11,7 +12,8 @@ WRAPPER_CLASS radio_driver(radio, board);
VolatileRTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
NmeaGpsDriver gps_driver(Serial1);
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(gps_driver, &rtc_clock);
ThinkNodeM1SensorManager sensors = ThinkNodeM1SensorManager(nmea);
#ifdef DISPLAY_CLASS
@@ -31,34 +33,15 @@ mesh::LocalIdentity radio_new_identity() {
}
void ThinkNodeM1SensorManager::start_gps() {
if (!gps_active) {
gps_active = true;
_location->begin();
}
_location->setGpsOn(true);
}
void ThinkNodeM1SensorManager::stop_gps() {
if (gps_active) {
gps_active = false;
_location->stop();
}
_location->setGpsOn(false);
}
bool ThinkNodeM1SensorManager::begin() {
Serial1.begin(9600);
// Initialize GPS switch pin
pinMode(PIN_GPS_SWITCH, INPUT);
last_gps_switch_state = digitalRead(PIN_GPS_SWITCH);
// Initialize GPS power pin
pinMode(GPS_EN, OUTPUT);
// Check initial switch state to determine if GPS should be active
if (last_gps_switch_state == HIGH) { // Switch is HIGH when ON
start_gps();
}
start_gps();
return true;
}
@@ -71,36 +54,11 @@ bool ThinkNodeM1SensorManager::querySensors(uint8_t requester_permissions, Cayen
void ThinkNodeM1SensorManager::loop() {
static long next_gps_update = 0;
static long last_switch_check = 0;
// Check GPS switch state every second
if (millis() - last_switch_check > 1000) {
bool current_switch_state = digitalRead(PIN_GPS_SWITCH);
// Detect switch state change
if (current_switch_state != last_gps_switch_state) {
last_gps_switch_state = current_switch_state;
if (current_switch_state == HIGH) { // Switch is ON
MESH_DEBUG_PRINTLN("GPS switch ON");
start_gps();
} else { // Switch is OFF
MESH_DEBUG_PRINTLN("GPS switch OFF");
stop_gps();
}
}
last_switch_check = millis();
}
if (!gps_active) {
return; // GPS is not active, skip further processing
}
_location->loop();
if (millis() > next_gps_update) {
if (_location->isValid()) {
if (_location->isEnabled() && _location->isValid()) {
node_lat = ((double)_location->getLatitude())/1000000.;
node_lon = ((double)_location->getLongitude())/1000000.;
node_altitude = ((double)_location->getAltitude()) / 1000.0;
@@ -120,7 +78,7 @@ const char* ThinkNodeM1SensorManager::getSettingName(int i) const {
const char* ThinkNodeM1SensorManager::getSettingValue(int i) const {
if (i == 0) {
return gps_active ? "1" : "0";
return _location->isGpsOn() ? "1" : "0";
}
return NULL;
}
@@ -136,4 +94,3 @@ bool ThinkNodeM1SensorManager::setSettingValue(const char* name, const char* val
}
return false; // not supported
}
-3
View File
@@ -14,8 +14,6 @@
#endif
class ThinkNodeM1SensorManager : public SensorManager {
bool gps_active = false;
bool last_gps_switch_state = false;
LocationProvider* _location;
void start_gps();
@@ -45,4 +43,3 @@ extern ThinkNodeM1SensorManager sensors;
bool radio_init();
mesh::LocalIdentity radio_new_identity();
+2
View File
@@ -146,3 +146,5 @@ extern const int SCK;
#define PIN_GPS_PPS (36)
#define PIN_GPS_STANDBY (34)
#define PIN_GPS_SWITCH (33)
#define GPS_SWITCH_IS_HARDWARE (0)
#define GPS_SWITCH_TURNS_GPS_ON (1)
+2 -3
View File
@@ -17,7 +17,8 @@ ESP32RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#ifdef ENV_INCLUDE_GPS
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
NmeaGpsDriver gps_driver(Serial1);
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(gps_driver, &rtc_clock);
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
#else
EnvironmentSensorManager sensors = EnvironmentSensorManager();
@@ -46,5 +47,3 @@ mesh::LocalIdentity radio_new_identity() {
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity
}
+2 -1
View File
@@ -25,4 +25,5 @@
#define PIN_GPS_RESET (13)
#define PIN_GPS_RX (20)
#define PIN_GPS_TX (19)
#define PIN_GPS_SWITCH (10)
#define PIN_GPS_SWITCH (10)
#define GPS_SWITCH_IS_HARDWARE (1)