Skip to content

Commit c1915a1

Browse files
committed
ESM: delegate gps management to LocationProvider
1 parent ea13fa8 commit c1915a1

File tree

2 files changed

+34
-56
lines changed

2 files changed

+34
-56
lines changed

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -437,21 +437,7 @@ void EnvironmentSensorManager::initBasicGPS() {
437437
#endif
438438

439439
// Try to detect if GPS is physically connected to determine if we should expose the setting
440-
#ifdef PIN_GPS_EN
441-
pinMode(PIN_GPS_EN, OUTPUT);
442-
#ifdef PIN_GPS_EN_ACTIVE
443-
digitalWrite(PIN_GPS_EN, PIN_GPS_EN_ACTIVE); // Power on GPS
444-
#else
445-
digitalWrite(PIN_GPS_EN, HIGH); // Power on GPS
446-
#endif
447-
#endif
448-
449-
#ifdef PIN_GPS_RESET
450-
pinMode(PIN_GPS_RESET, OUTPUT);
451-
digitalWrite(PIN_GPS_RESET, PIN_GPS_RESET_ACTIVE); // assert for 10ms
452-
delay(10);
453-
digitalWrite(PIN_GPS_RESET, !PIN_GPS_RESET_ACTIVE);
454-
#endif
440+
_location->begin();
455441

456442
#ifndef PIN_GPS_EN
457443
MESH_DEBUG_PRINTLN("No GPS wake/reset pin found for this board. Continuing on...");
@@ -472,16 +458,12 @@ void EnvironmentSensorManager::initBasicGPS() {
472458
} else {
473459
MESH_DEBUG_PRINTLN("No GPS detected");
474460
}
475-
#ifdef PIN_GPS_EN
476-
#ifdef PIN_GPS_EN_ACTIVE
477-
digitalWrite(PIN_GPS_EN, !PIN_GPS_EN_ACTIVE);
478-
#else
479-
digitalWrite(PIN_GPS_EN, LOW); // Power off GPS until the setting is changed
480-
#endif
481-
#endif
461+
_location->stop();
482462
gps_active = false; //Set GPS visibility off until setting is changed
483463
}
484464

465+
// gps code for rak might be moved to MicroNMEALoactionProvider
466+
// or make a new location provider ...
485467
#ifdef RAK_WISBLOCK_GPS
486468
void EnvironmentSensorManager::rakGPSInit(){
487469

@@ -561,27 +543,12 @@ void EnvironmentSensorManager::start_gps() {
561543
digitalWrite(gpsResetPin, HIGH);
562544
return;
563545
#endif
564-
#ifdef PIN_GPS_EN
565-
pinMode(PIN_GPS_EN, OUTPUT);
566-
#ifdef PIN_GPS_EN_ACTIVE
567-
digitalWrite(PIN_GPS_EN, PIN_GPS_EN_ACTIVE);
568-
#else
569-
digitalWrite(PIN_GPS_EN, HIGH);
570-
#endif
571-
#ifndef PIN_GPS_RESET
572-
return;
573-
#endif
574-
#endif
575546

576-
#ifdef PIN_GPS_RESET
577-
pinMode(PIN_GPS_RESET, OUTPUT);
578-
digitalWrite(PIN_GPS_RESET, PIN_GPS_RESET_ACTIVE); // assert for 10ms
579-
delay(10);
580-
digitalWrite(PIN_GPS_RESET, !PIN_GPS_RESET_ACTIVE);
581-
return;
582-
#endif
547+
_location->begin();
583548

549+
#ifndef PIN_GPS_RESET
584550
MESH_DEBUG_PRINTLN("Start GPS is N/A on this board. Actual GPS state unchanged");
551+
#endif
585552
}
586553

587554
void EnvironmentSensorManager::stop_gps() {
@@ -591,17 +558,12 @@ void EnvironmentSensorManager::stop_gps() {
591558
digitalWrite(gpsResetPin, LOW);
592559
return;
593560
#endif
594-
#ifdef PIN_GPS_EN
595-
pinMode(PIN_GPS_EN, OUTPUT);
596-
#ifdef PIN_GPS_EN_ACTIVE
597-
digitalWrite(PIN_GPS_EN, !PIN_GPS_EN_ACTIVE);
598-
#else
599-
digitalWrite(PIN_GPS_EN, LOW);
600-
#endif
601-
return;
602-
#endif
603561

562+
_location->stop();
563+
564+
#ifndef PIN_GPS_EN
604565
MESH_DEBUG_PRINTLN("Stop GPS is N/A on this board. Actual GPS state unchanged");
566+
#endif
605567
}
606568

607569
void EnvironmentSensorManager::loop() {

src/helpers/sensors/MicroNMEALocationProvider.h

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,31 @@
55
#include <RTClib.h>
66

77
#ifndef GPS_EN
8-
#define GPS_EN (-1)
8+
#ifdef PIN_GPS_EN
9+
#define GPS_EN PIN_GPS_EN
10+
#else
11+
#define GPS_EN (-1)
12+
#endif
13+
#endif
14+
15+
#ifndef PIN_GPS_EN_ACTIVE
16+
#define PIN_GPS_EN_ACTIVE HIGH
917
#endif
1018

1119
#ifndef GPS_RESET
12-
#define GPS_RESET (-1)
20+
#ifdef PIN_GPS_RESET
21+
#define GPS_RESET PIN_GPS_RESET
22+
#else
23+
#define GPS_RESET (-1)
24+
#endif
1325
#endif
1426

1527
#ifndef GPS_RESET_FORCE
16-
#define GPS_RESET_FORCE LOW
28+
#ifdef PIN_GPS_RESET_ACTIVE
29+
#define GPS_RESET_FORCE PIN_GPS_RESET_ACTIVE
30+
#else
31+
#define GPS_RESET_FORCE LOW
32+
#endif
1733
#endif
1834

1935
class MicroNMEALocationProvider : public LocationProvider {
@@ -40,12 +56,12 @@ public :
4056
}
4157

4258
void begin() override {
59+
if (_pin_en != -1) {
60+
digitalWrite(_pin_en, PIN_GPS_EN_ACTIVE);
61+
}
4362
if (_pin_reset != -1) {
4463
digitalWrite(_pin_reset, !GPS_RESET_FORCE);
4564
}
46-
if (_pin_en != -1) {
47-
digitalWrite(_pin_en, HIGH);
48-
}
4965
}
5066

5167
void reset() override {
@@ -58,7 +74,7 @@ public :
5874

5975
void stop() override {
6076
if (_pin_en != -1) {
61-
digitalWrite(_pin_en, LOW);
77+
digitalWrite(_pin_en, !PIN_GPS_EN_ACTIVE);
6278
}
6379
}
6480

0 commit comments

Comments
 (0)