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

Commit 427f295

Browse files
authored
Merge pull request #99 from sparkfun/getPowerSaveMode
Added getPowerSaveMode
2 parents e6a0ae6 + d558a7d commit 427f295

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

examples/Example18_PowerSaveMode/Example18_PowerSaveMode.ino

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
Power Save Mode
33
By: Paul Clark (PaulZC)
4-
Date: December 18th, 2019
4+
Date: April 22nd, 2020
55
66
Based extensively on Example3_GetPosition
77
By: Nathan Seidle
@@ -82,7 +82,7 @@ void loop()
8282
// Put the GNSS into power save mode
8383
// (If you want to disable power save mode, call myGPS.powerSaveMode(false) instead)
8484
// This will fail on the ZED (protocol version >= 27) as UBX-CFG-RXM is not supported
85-
if (myGPS.powerSaveMode())
85+
if (myGPS.powerSaveMode()) // Defaults to true
8686
Serial.println(F("Power Save Mode enabled."));
8787
else
8888
Serial.println(F("***!!! Power Save Mode FAILED !!!***"));
@@ -95,6 +95,34 @@ void loop()
9595
else
9696
Serial.println(F("***!!! Power Save Disable FAILED !!!***"));
9797
}
98+
99+
// Read and print the new low power mode
100+
uint8_t lowPowerMode = myGPS.getPowerSaveMode();
101+
if (lowPowerMode == 255)
102+
{
103+
Serial.println(F("***!!! getPowerSaveMode FAILED !!!***"));
104+
}
105+
else
106+
{
107+
Serial.print(F("The low power mode is: "));
108+
Serial.print(lowPowerMode);
109+
if (lowPowerMode == 0)
110+
{
111+
Serial.println(F(" (Continuous)"));
112+
}
113+
else if (lowPowerMode == 1)
114+
{
115+
Serial.println(F(" (Power Save)"));
116+
}
117+
else if (lowPowerMode == 4)
118+
{
119+
Serial.println(F(" (Continuous)"));
120+
}
121+
else
122+
{
123+
Serial.println(F(" (Unknown!)"));
124+
}
125+
}
98126
}
99127

100128
//Query module every 10 seconds so it is easier to monitor the current draw
@@ -132,4 +160,4 @@ void loop()
132160

133161
Serial.println();
134162
}
135-
}
163+
}

keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ getGeofenceState KEYWORD2
136136
setDynamicModel KEYWORD2
137137
getDynamicModel KEYWORD2
138138
powerSaveMode KEYWORD2
139+
getPowerSaveMode KEYWORD2
139140

140141
configureMessage KEYWORD2
141142
enableMessage KEYWORD2

src/SparkFun_Ublox_Arduino_Library.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,42 @@ boolean SFE_UBLOX_GPS::powerSaveMode(bool power_save, uint16_t maxWait)
25102510
return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
25112511
}
25122512

2513+
// Get Power Save Mode
2514+
// Returns the current Low Power Mode using UBX-CFG-RXM
2515+
// Returns 255 if the sendCommand fails
2516+
uint8_t SFE_UBLOX_GPS::getPowerSaveMode(uint16_t maxWait)
2517+
{
2518+
// Let's begin by checking the Protocol Version as UBX_CFG_RXM is not supported on the ZED (protocol >= 27)
2519+
uint8_t protVer = getProtocolVersionHigh(maxWait);
2520+
/*
2521+
if (_printDebug == true)
2522+
{
2523+
_debugSerial->print(F("Protocol version is "));
2524+
_debugSerial->println(protVer);
2525+
}
2526+
*/
2527+
if (protVer >= 27)
2528+
{
2529+
if (_printDebug == true)
2530+
{
2531+
_debugSerial->println(F("powerSaveMode (UBX-CFG-RXM) is not supported by this protocol version"));
2532+
}
2533+
return (255);
2534+
}
2535+
2536+
// Now let's read the power setting using UBX-CFG-RXM
2537+
packetCfg.cls = UBX_CLASS_CFG;
2538+
packetCfg.id = UBX_CFG_RXM;
2539+
packetCfg.len = 0;
2540+
packetCfg.startingSpot = 0;
2541+
2542+
//Ask module for the current power management settings. Loads into payloadCfg.
2543+
if (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
2544+
return (255);
2545+
2546+
return (payloadCfg[1]); // Return the low power mode
2547+
}
2548+
25132549
//Change the dynamic platform model using UBX-CFG-NAV5
25142550
//Possible values are:
25152551
//PORTABLE,STATIONARY,PEDESTRIAN,AUTOMOTIVE,SEA,

src/SparkFun_Ublox_Arduino_Library.h

+1
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ class SFE_UBLOX_GPS
614614
geofenceParams currentGeofenceParams; // Global to store the geofence parameters
615615

616616
boolean powerSaveMode(bool power_save = true, uint16_t maxWait = 1100);
617+
uint8_t getPowerSaveMode(uint16_t maxWait = 1100); // Returns 255 if the sendCommand fails
617618

618619
//Change the dynamic platform model using UBX-CFG-NAV5
619620
boolean setDynamicModel(dynModel newDynamicModel = DYN_MODEL_PORTABLE, uint16_t maxWait = 1100);

0 commit comments

Comments
 (0)