Skip to content

Commit fa8c31b

Browse files
author
Scott Powell
committed
* fix for RAK12500 GPS (I2C)
1 parent 34b9a1c commit fa8c31b

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,41 @@ static bool serialGPSFlag = false;
9898
static SFE_UBLOX_GNSS ublox_GNSS;
9999
#endif
100100

101+
class RAK12500LocationProvider : public LocationProvider {
102+
long _lat = 0;
103+
long _lng = 0;
104+
long _alt = 0;
105+
int _sats = 0;
106+
long _epoch = 0;
107+
bool _fix = false;
108+
public:
109+
long getLatitude() override { return _lat; }
110+
long getLongitude() override { return _lng; }
111+
long getAltitude() override { return _alt; }
112+
long satellitesCount() override { return _sats; }
113+
bool isValid() override { return _fix; }
114+
long getTimestamp() override { return _epoch; }
115+
void sendSentence(const char * sentence) override { }
116+
void reset() override { }
117+
void begin() override { }
118+
void stop() override { }
119+
void loop() override {
120+
if (ublox_GNSS.getGnssFixOk(8)) {
121+
_fix = true;
122+
_lat = ublox_GNSS.getLatitude(2) / 10;
123+
_lng = ublox_GNSS.getLongitude(2) / 10;
124+
_alt = ublox_GNSS.getAltitude(2);
125+
_sats = ublox_GNSS.getSIV(2);
126+
} else {
127+
_fix = false;
128+
}
129+
_epoch = ublox_GNSS.getUnixEpoch(2);
130+
}
131+
bool isEnabled() override { return true; }
132+
};
133+
134+
static RAK12500LocationProvider RAK12500_provider;
135+
101136
bool EnvironmentSensorManager::begin() {
102137
#if ENV_INCLUDE_GPS
103138
#ifdef RAK_WISBLOCK_GPS
@@ -521,12 +556,22 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){
521556
//Try to init RAK12500 on I2C
522557
if (ublox_GNSS.begin(Wire) == true){
523558
MESH_DEBUG_PRINTLN("RAK12500 GPS init correctly with pin %i",ioPin);
524-
ublox_GNSS.setI2COutput(COM_TYPE_NMEA);
559+
ublox_GNSS.setI2COutput(COM_TYPE_UBX);
560+
ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_GPS);
561+
ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_GALILEO);
562+
ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_GLONASS);
563+
ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_SBAS);
564+
ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_BEIDOU);
565+
ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_IMES);
566+
ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_QZSS);
567+
ublox_GNSS.setMeasurementRate(1000);
525568
ublox_GNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT);
526569
gpsResetPin = ioPin;
527570
i2cGPSFlag = true;
528571
gps_active = true;
529572
gps_detected = true;
573+
574+
_location = &RAK12500_provider;
530575
return true;
531576
}
532577
else if(Serial1){
@@ -583,14 +628,7 @@ void EnvironmentSensorManager::loop() {
583628
if (millis() > next_gps_update) {
584629
if(gps_active){
585630
#ifdef RAK_WISBLOCK_GPS
586-
if(i2cGPSFlag){
587-
node_lat = ((double)ublox_GNSS.getLatitude())/10000000.;
588-
node_lon = ((double)ublox_GNSS.getLongitude())/10000000.;
589-
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
590-
node_altitude = ((double)ublox_GNSS.getAltitude()) / 1000.0;
591-
MESH_DEBUG_PRINTLN("lat %f lon %f alt %f", node_lat, node_lon, node_altitude);
592-
}
593-
else if (serialGPSFlag && _location->isValid()) {
631+
if ((i2cGPSFlag || serialGPSFlag) && _location->isValid()) {
594632
node_lat = ((double)_location->getLatitude())/1000000.;
595633
node_lon = ((double)_location->getLongitude())/1000000.;
596634
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);

0 commit comments

Comments
 (0)