Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit b18ab97

Browse files
committed
Removing wire.begin from lib. Adding position accuracy function.
1 parent 3007665 commit b18ab97

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/SparkFun_Ublox_Arduino_Library.cpp

+29-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ void SFE_UBLOX_GPS::begin(TwoWire &wirePort)
4141

4242
//We expect caller to begin their I2C port, with the speed of their choice external to the library
4343
//But if they forget, we start the hardware here.
44-
_i2cPort->begin();
44+
45+
//We're moving away from the practice of starting Wire hardware in a library. This is to avoid cross platform issues.
46+
//ie, there are some platforms that don't handle multiple starts to the wire hardware. Also, every time you start the wire
47+
//hardware the clock speed reverts back to 100kHz regardless of previous Wire.setClocks().
48+
//_i2cPort->begin();
4549

4650
setI2CReadAddress(0x42); //By default, use 0x42
4751
}
@@ -475,6 +479,30 @@ boolean SFE_UBLOX_GPS::waitForResponse(uint16_t maxTime)
475479
}
476480

477481

482+
//Get the current 3D high precision positional accuracy - a fun thing to watch
483+
//Returns a float representing the 3D accuracy in millimeters
484+
uint32_t SFE_UBLOX_GPS::getPositionAccuracy(uint16_t maxWait)
485+
{
486+
packetCfg.cls = UBX_CLASS_NAV;
487+
packetCfg.id = UBX_NAV_HPPOSECEF;
488+
packetCfg.len = 0;
489+
490+
if(sendCommand(packetCfg, maxWait) == false)
491+
return(0); //If command send fails then bail
492+
493+
//We got a response, now parse the bits into the float variable
494+
uint32_t tempAccuracy = 0;
495+
tempAccuracy |= payloadCfg[24] << 8*0;
496+
tempAccuracy |= payloadCfg[25] << 8*1;
497+
tempAccuracy |= payloadCfg[26] << 8*2;
498+
tempAccuracy |= payloadCfg[27] << 8*3;
499+
500+
if(tempAccuracy % 10) >= 5) tempAccuracy += 5; //Round fraction of mm up to next mm if .5 or above
501+
tempAccuracy /= 10; //Convert 0.1mm units to mm
502+
503+
return(tempAccuracy);
504+
}
505+
478506
//Get the current TimeMode3 settings - these contain survey in statuses
479507
boolean SFE_UBLOX_GPS::getSurveyMode(uint16_t maxWait)
480508
{

src/SparkFun_Ublox_Arduino_Library.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,15 @@ const uint8_t UBX_CLASS_LOG = 0x21;
8585
const uint8_t UBX_CLASS_SEC = 0x27;
8686
const uint8_t UBX_CLASS_HNR = 0x28;
8787

88-
const uint8_t UBX_CFG_PRT = 0x00;
89-
const uint8_t UBX_CFG_RATE = 0x08;
88+
const uint8_t UBX_CFG_PRT = 0x00; //Used to configure port specifics
89+
const uint8_t UBX_CFG_RATE = 0x08; //Used to set port baud rates
9090

9191
const uint8_t UBX_CFG_TMODE3 = 0x71; //Used to enable Survey In Mode
9292
const uint8_t SVIN_MODE_DISABLE = 0x00;
9393
const uint8_t SVIN_MODE_ENABLE = 0x01;
9494

9595
const uint8_t UBX_NAV_SVIN = 0x3B; //Used for checking Survey In status
96+
const uint8_t UBX_NAV_HPPOSECEF = 0x13; //Find our positional accuracy (high precision)
9697

9798
//The following are used to enable RTCM messages
9899
const uint8_t UBX_CFG_MSG = 0x01;
@@ -132,7 +133,7 @@ class SFE_UBLOX_GPS
132133
SFE_UBLOX_GPS(void);
133134

134135
//By default use the default I2C address, and use Wire port
135-
void begin(TwoWire &wirePort);
136+
void begin(TwoWire &wirePort = Wire);
136137

137138
boolean isConnected(); //Returns turn if device answers on _gpsI2Caddress address
138139

@@ -167,6 +168,8 @@ class SFE_UBLOX_GPS
167168
boolean setRTCMport(uint8_t portID, boolean enableRTCM3, uint16_t maxWait = 250); //Enable/Disable RTCM3 (both input and output) for a given port
168169

169170
boolean getPortSettings(uint8_t portID, uint16_t maxWait = 250); //Returns the current protocol bits in the UBX-CFG-PRT command for a given port
171+
172+
uint32_t getPositionAccuracy(uint16_t maxWait = 500); //Returns the 3D accuracy of the current high-precision fix
170173

171174
struct svinStructure {
172175
boolean active;
@@ -176,7 +179,7 @@ class SFE_UBLOX_GPS
176179
} svin;
177180

178181
uint16_t rtcmFrameCounter = 0;
179-
182+
180183
private:
181184

182185
//Depending on the sentence type the processor will load characters into different arrays

0 commit comments

Comments
 (0)