@@ -2569,6 +2569,134 @@ uint8_t SFE_UBLOX_GPS::getPowerSaveMode(uint16_t maxWait)
2569
2569
return (payloadCfg[1 ]); // Return the low power mode
2570
2570
}
2571
2571
2572
+ // Powers off the GPS device for a given duration to reduce power consumption.
2573
+ // NOTE: Querying the device before the duration is complete, for example by "getLatitude()" will wake it up!
2574
+ // Returns true if command has not been not acknowledged.
2575
+ // Returns false if command has not been acknowledged or maxWait = 0.
2576
+ boolean SFE_UBLOX_GPS::powerOff (uint32_t durationInMs, uint16_t maxWait)
2577
+ {
2578
+ // use durationInMs = 0 for infinite duration
2579
+ if (_printDebug == true )
2580
+ {
2581
+ _debugSerial->print (F (" Powering off for " ));
2582
+ _debugSerial->print (durationInMs);
2583
+ _debugSerial->println (" ms" );
2584
+ }
2585
+
2586
+ // Power off device using UBX-RXM-PMREQ
2587
+ packetCfg.cls = UBX_CLASS_RXM; // 0x02
2588
+ packetCfg.id = UBX_RXM_PMREQ; // 0x41
2589
+ packetCfg.len = 8 ;
2590
+ packetCfg.startingSpot = 0 ;
2591
+
2592
+ // duration
2593
+ // big endian to little endian, switch byte order
2594
+ payloadCfg[0 ] = (durationInMs >> (8 *0 )) & 0xff ;
2595
+ payloadCfg[1 ] = (durationInMs >> (8 *1 )) & 0xff ;
2596
+ payloadCfg[2 ] = (durationInMs >> (8 *2 )) & 0xff ;
2597
+ payloadCfg[3 ] = (durationInMs >> (8 *3 )) & 0xff ;
2598
+
2599
+ if (maxWait != 0 )
2600
+ {
2601
+ // check for "not acknowledged" command
2602
+ return (sendCommand (&packetCfg, maxWait) != SFE_UBLOX_STATUS_COMMAND_NACK);
2603
+ }
2604
+ else
2605
+ {
2606
+ sendCommand (&packetCfg, maxWait);
2607
+ return false ; // can't tell if command not acknowledged if maxWait = 0
2608
+ }
2609
+ }
2610
+
2611
+ // Powers off the GPS device for a given duration to reduce power consumption.
2612
+ // While powered off it can be woken up by creating a falling or rising voltage edge on the specified pin.
2613
+ // NOTE: The GPS seems to be sensitve to signals on the pins while powered off. Works best when Microcontroller is in deepsleep.
2614
+ // NOTE: Querying the device before the duration is complete, for example by "getLatitude()" will wake it up!
2615
+ // Returns true if command has not been not acknowledged.
2616
+ // Returns false if command has not been acknowledged or maxWait = 0.
2617
+ boolean SFE_UBLOX_GPS::powerOffWithInterrupt (uint32_t durationInMs, uint8_t wakeupPin, boolean forceWhileUsb, uint16_t maxWait)
2618
+ {
2619
+ // use durationInMs = 0 for infinite duration
2620
+ if (_printDebug == true )
2621
+ {
2622
+ _debugSerial->print (F (" Powering off for " ));
2623
+ _debugSerial->print (durationInMs);
2624
+ _debugSerial->println (" ms" );
2625
+ }
2626
+
2627
+ // Power off device using UBX-RXM-PMREQ
2628
+ packetCfg.cls = UBX_CLASS_RXM; // 0x02
2629
+ packetCfg.id = UBX_RXM_PMREQ; // 0x41
2630
+ packetCfg.len = 16 ;
2631
+ packetCfg.startingSpot = 0 ;
2632
+
2633
+ payloadCfg[0 ] = 0x00 ; // message version
2634
+ // bytes 1-3 are reserved
2635
+
2636
+ // duration
2637
+ // big endian to little endian, switch byte order
2638
+ payloadCfg[4 ] = (durationInMs >> (8 *0 )) & 0xff ;
2639
+ payloadCfg[5 ] = (durationInMs >> (8 *1 )) & 0xff ;
2640
+ payloadCfg[6 ] = (durationInMs >> (8 *2 )) & 0xff ;
2641
+ payloadCfg[7 ] = (durationInMs >> (8 *3 )) & 0xff ;
2642
+
2643
+ // flags
2644
+ payloadCfg[8 ] = 0x00 ;
2645
+ payloadCfg[9 ] = 0x00 ;
2646
+ payloadCfg[10 ] = 0x00 ;
2647
+
2648
+ // disables USB interface when powering off, defaults to true
2649
+ if (forceWhileUsb)
2650
+ {
2651
+ payloadCfg[11 ] = 0x04 ;
2652
+ }
2653
+ else
2654
+ {
2655
+ payloadCfg[11 ] = 0x02 ;
2656
+ }
2657
+
2658
+ // wakeUpSources
2659
+ payloadCfg[12 ] = 0x00 ;
2660
+ payloadCfg[13 ] = 0x00 ;
2661
+ payloadCfg[14 ] = 0x00 ;
2662
+
2663
+ // wakeupPin mapping, defaults to EXINT0, limited to one pin for now
2664
+ // last byte of wakeUpSources
2665
+ uint8_t terminatingByte;
2666
+
2667
+ switch (wakeupPin)
2668
+ {
2669
+ case 0 : // UART RX
2670
+ terminatingByte = 0x08 ; // 0000 1000
2671
+ break ;
2672
+
2673
+ case 1 : // EXINT 0
2674
+ terminatingByte = 0x20 ; // 0010 0000
2675
+ break ;
2676
+
2677
+ case 2 : // EXINT 1
2678
+ terminatingByte = 0x40 ; // 0100 0000
2679
+ break ;
2680
+
2681
+ case 3 : // SPI CS
2682
+ terminatingByte = 0x80 ; // 1000 0000
2683
+ break ;
2684
+ }
2685
+
2686
+ payloadCfg[15 ] = terminatingByte;
2687
+
2688
+ if (maxWait != 0 )
2689
+ {
2690
+ // check for "not acknowledged" command
2691
+ return (sendCommand (&packetCfg, maxWait) != SFE_UBLOX_STATUS_COMMAND_NACK);
2692
+ }
2693
+ else
2694
+ {
2695
+ sendCommand (&packetCfg, maxWait);
2696
+ return false ; // can't tell if command not acknowledged if maxWait = 0
2697
+ }
2698
+ }
2699
+
2572
2700
// Change the dynamic platform model using UBX-CFG-NAV5
2573
2701
// Possible values are:
2574
2702
// PORTABLE,STATIONARY,PEDESTRIAN,AUTOMOTIVE,SEA,
0 commit comments