Skip to content

Commit e5de6e6

Browse files
authored
Merge pull request #820 from fdlamotte/gps_reset_fix
ESM: delegate gps management to LocationProvider
2 parents cd7e7d9 + c83abbe commit e5de6e6

File tree

2 files changed

+38
-58
lines changed

2 files changed

+38
-58
lines changed

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -437,21 +437,8 @@ 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();
441+
_location->reset();
455442

456443
#ifndef PIN_GPS_EN
457444
MESH_DEBUG_PRINTLN("No GPS wake/reset pin found for this board. Continuing on...");
@@ -472,16 +459,12 @@ void EnvironmentSensorManager::initBasicGPS() {
472459
} else {
473460
MESH_DEBUG_PRINTLN("No GPS detected");
474461
}
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
462+
_location->stop();
482463
gps_active = false; //Set GPS visibility off until setting is changed
483464
}
484465

466+
// gps code for rak might be moved to MicroNMEALoactionProvider
467+
// or make a new location provider ...
485468
#ifdef RAK_WISBLOCK_GPS
486469
void EnvironmentSensorManager::rakGPSInit(){
487470

@@ -561,27 +544,13 @@ void EnvironmentSensorManager::start_gps() {
561544
digitalWrite(gpsResetPin, HIGH);
562545
return;
563546
#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
575547

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
548+
_location->begin();
549+
_location->reset();
583550

551+
#ifndef PIN_GPS_RESET
584552
MESH_DEBUG_PRINTLN("Start GPS is N/A on this board. Actual GPS state unchanged");
553+
#endif
585554
}
586555

587556
void EnvironmentSensorManager::stop_gps() {
@@ -591,17 +560,12 @@ void EnvironmentSensorManager::stop_gps() {
591560
digitalWrite(gpsResetPin, LOW);
592561
return;
593562
#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
603563

564+
_location->stop();
565+
566+
#ifndef PIN_GPS_EN
604567
MESH_DEBUG_PRINTLN("Stop GPS is N/A on this board. Actual GPS state unchanged");
568+
#endif
605569
}
606570

607571
void EnvironmentSensorManager::loop() {

src/helpers/sensors/MicroNMEALocationProvider.h

Lines changed: 25 additions & 9 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,25 +56,25 @@ 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 {
5268
if (_pin_reset != -1) {
5369
digitalWrite(_pin_reset, GPS_RESET_FORCE);
54-
delay(100);
70+
delay(10);
5571
digitalWrite(_pin_reset, !GPS_RESET_FORCE);
5672
}
5773
}
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

@@ -107,4 +123,4 @@ public :
107123
}
108124
}
109125
}
110-
};
126+
};

0 commit comments

Comments
 (0)