Skip to content

Changes by PaulZC #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions examples/Example22_PowerOff/Example22_PowerOff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ SFE_UBLOX_GPS myGPS;
// define a digital pin capable of driving HIGH and LOW
#define WAKEUP_PIN 5

// interrupt pin mapping
#define GPS_RX 0
#define GPS_INT0 1
#define GPS_INT1 2
#define GPS_SPI_CS 3

// Possible GNSS interrupt pins for powerOffWithInterrupt are:
// VAL_RXM_PMREQ_WAKEUPSOURCE_UARTRX = uartrx
// VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0 = extint0 (default)
// VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT1 = extint1
// VAL_RXM_PMREQ_WAKEUPSOURCE_SPICS = spics
// These values can be or'd (|) together to enable interrupts on multiple pins

void wakeUp() {

Expand All @@ -55,13 +55,16 @@ void wakeUp() {
void setup() {

pinMode(WAKEUP_PIN, OUTPUT);
digitalWrite(WAKEUP_PIN, LOW);

Serial.begin(115200);
while (!Serial); //Wait for user to open terminal
Serial.println("SparkFun Ublox Example");

Wire.begin();

//myGPS.enableDebugging(); // Enable debug messages

if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
{
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
Expand All @@ -72,7 +75,7 @@ void setup() {
Serial.println("-- Powering off module for 20s --");

myGPS.powerOff(20000);
// myGPS.powerOffWithInterrupt(20000, GPS_INT0);
//myGPS.powerOffWithInterrupt(20000, VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0);

delay(10000);

Expand Down
4 changes: 2 additions & 2 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ setDynamicModel KEYWORD2
getDynamicModel KEYWORD2
powerSaveMode KEYWORD2
getPowerSaveMode KEYWORD2
powerOff KEYWORD2
powerOffWithInterrupt KEYWORD2
powerOff KEYWORD2
powerOffWithInterrupt KEYWORD2

configureMessage KEYWORD2
enableMessage KEYWORD2
Expand Down
59 changes: 27 additions & 32 deletions src/SparkFun_Ublox_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,11 @@ boolean SFE_UBLOX_GPS::powerOff(uint32_t durationInMs, uint16_t maxWait)
payloadCfg[2] = (durationInMs >> (8*2)) & 0xff;
payloadCfg[3] = (durationInMs >> (8*3)) & 0xff;

payloadCfg[4] = 0x02; //Flags : set the backup bit
payloadCfg[5] = 0x00; //Flags
payloadCfg[6] = 0x00; //Flags
payloadCfg[7] = 0x00; //Flags

if (maxWait != 0)
{
// check for "not acknowledged" command
Expand All @@ -2614,7 +2619,7 @@ boolean SFE_UBLOX_GPS::powerOff(uint32_t durationInMs, uint16_t maxWait)
// NOTE: Querying the device before the duration is complete, for example by "getLatitude()" will wake it up!
// Returns true if command has not been not acknowledged.
// Returns false if command has not been acknowledged or maxWait = 0.
boolean SFE_UBLOX_GPS::powerOffWithInterrupt(uint32_t durationInMs, uint8_t wakeupPin, boolean forceWhileUsb, uint16_t maxWait)
boolean SFE_UBLOX_GPS::powerOffWithInterrupt(uint32_t durationInMs, uint32_t wakeupSources, boolean forceWhileUsb, uint16_t maxWait)
{
// use durationInMs = 0 for infinite duration
if (_printDebug == true)
Expand All @@ -2631,7 +2636,11 @@ boolean SFE_UBLOX_GPS::powerOffWithInterrupt(uint32_t durationInMs, uint8_t wake
packetCfg.startingSpot = 0;

payloadCfg[0] = 0x00; // message version
// bytes 1-3 are reserved

// bytes 1-3 are reserved - and must be set to zero
payloadCfg[1] = 0x00;
payloadCfg[2] = 0x00;
payloadCfg[3] = 0x00;

// duration
// big endian to little endian, switch byte order
Expand All @@ -2641,49 +2650,35 @@ boolean SFE_UBLOX_GPS::powerOffWithInterrupt(uint32_t durationInMs, uint8_t wake
payloadCfg[7] = (durationInMs >> (8*3)) & 0xff;

// flags
payloadCfg[8] = 0x00;
payloadCfg[9] = 0x00;
payloadCfg[10] = 0x00;

// disables USB interface when powering off, defaults to true
if (forceWhileUsb)
{
payloadCfg[11] = 0x04;
payloadCfg[8] = 0x06; // force | backup
}
else
{
payloadCfg[11] = 0x02;
payloadCfg[8] = 0x02; // backup only (leave the force bit clear - module will stay on if USB is connected)
}

// wakeUpSources
payloadCfg[12] = 0x00;
payloadCfg[13] = 0x00;
payloadCfg[14] = 0x00;

// wakeupPin mapping, defaults to EXINT0, limited to one pin for now
// last byte of wakeUpSources
uint8_t terminatingByte;

switch (wakeupPin)
{
case 0: // UART RX
terminatingByte = 0x08; // 0000 1000
break;
payloadCfg[9] = 0x00;
payloadCfg[10] = 0x00;
payloadCfg[11] = 0x00;

case 1: // EXINT 0
terminatingByte = 0x20; // 0010 0000
break;
// wakeUpSources

case 2: // EXINT 1
terminatingByte = 0x40; // 0100 0000
break;
// wakeupPin mapping, defaults to VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0

case 3: // SPI CS
terminatingByte = 0x80; // 1000 0000
break;
}
// Possible values are:
// VAL_RXM_PMREQ_WAKEUPSOURCE_UARTRX
// VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0
// VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT1
// VAL_RXM_PMREQ_WAKEUPSOURCE_SPICS

payloadCfg[15] = terminatingByte;
payloadCfg[12] = (wakeupSources >> (8*0)) & 0xff;
payloadCfg[13] = (wakeupSources >> (8*1)) & 0xff;
payloadCfg[14] = (wakeupSources >> (8*2)) & 0xff;
payloadCfg[15] = (wakeupSources >> (8*3)) & 0xff;

if (maxWait != 0)
{
Expand Down
8 changes: 7 additions & 1 deletion src/SparkFun_Ublox_Arduino_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ const uint32_t VAL_CFG_SUBSEC_ANTCONF = 0x00000400; // antConf - antenna config
const uint32_t VAL_CFG_SUBSEC_LOGCONF = 0x00000800; // logConf - logging configuration
const uint32_t VAL_CFG_SUBSEC_FTSCONF = 0x00001000; // ftsConf - FTS configuration (FTS products only)

// Bitfield wakeupSources for UBX_RXM_PMREQ
const uint32_t VAL_RXM_PMREQ_WAKEUPSOURCE_UARTRX = 0x00000008; // uartrx
const uint32_t VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0 = 0x00000020; // extint0
const uint32_t VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT1 = 0x00000040; // extint1
const uint32_t VAL_RXM_PMREQ_WAKEUPSOURCE_SPICS = 0x00000080; // spics

enum dynModel // Possible values for the dynamic platform model, which provide more accuract position output for the situation. Description extracted from ZED-F9P Integration Manual
{
DYN_MODEL_PORTABLE = 0, //Applications with low acceleration, e.g. portable devices. Suitable for most situations.
Expand Down Expand Up @@ -642,7 +648,7 @@ class SFE_UBLOX_GPS
boolean powerSaveMode(bool power_save = true, uint16_t maxWait = 1100);
uint8_t getPowerSaveMode(uint16_t maxWait = 1100); // Returns 255 if the sendCommand fails
boolean powerOff(uint32_t durationInMs, uint16_t maxWait = 1100);
boolean powerOffWithInterrupt(uint32_t durationInMs, uint8_t wakeupPin = 1, boolean forceWhileUsb = true, uint16_t maxWait = 1100);
boolean powerOffWithInterrupt(uint32_t durationInMs, uint32_t wakeupSources = VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0, boolean forceWhileUsb = true, uint16_t maxWait = 1100);

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