@@ -2569,6 +2569,129 @@ 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
+ payloadCfg[4 ] = 0x02 ; // Flags : set the backup bit
2600
+ payloadCfg[5 ] = 0x00 ; // Flags
2601
+ payloadCfg[6 ] = 0x00 ; // Flags
2602
+ payloadCfg[7 ] = 0x00 ; // Flags
2603
+
2604
+ if (maxWait != 0 )
2605
+ {
2606
+ // check for "not acknowledged" command
2607
+ return (sendCommand (&packetCfg, maxWait) != SFE_UBLOX_STATUS_COMMAND_NACK);
2608
+ }
2609
+ else
2610
+ {
2611
+ sendCommand (&packetCfg, maxWait);
2612
+ return false ; // can't tell if command not acknowledged if maxWait = 0
2613
+ }
2614
+ }
2615
+
2616
+ // Powers off the GPS device for a given duration to reduce power consumption.
2617
+ // While powered off it can be woken up by creating a falling or rising voltage edge on the specified pin.
2618
+ // NOTE: The GPS seems to be sensitve to signals on the pins while powered off. Works best when Microcontroller is in deepsleep.
2619
+ // NOTE: Querying the device before the duration is complete, for example by "getLatitude()" will wake it up!
2620
+ // Returns true if command has not been not acknowledged.
2621
+ // Returns false if command has not been acknowledged or maxWait = 0.
2622
+ boolean SFE_UBLOX_GPS::powerOffWithInterrupt (uint32_t durationInMs, uint32_t wakeupSources, boolean forceWhileUsb, uint16_t maxWait)
2623
+ {
2624
+ // use durationInMs = 0 for infinite duration
2625
+ if (_printDebug == true )
2626
+ {
2627
+ _debugSerial->print (F (" Powering off for " ));
2628
+ _debugSerial->print (durationInMs);
2629
+ _debugSerial->println (" ms" );
2630
+ }
2631
+
2632
+ // Power off device using UBX-RXM-PMREQ
2633
+ packetCfg.cls = UBX_CLASS_RXM; // 0x02
2634
+ packetCfg.id = UBX_RXM_PMREQ; // 0x41
2635
+ packetCfg.len = 16 ;
2636
+ packetCfg.startingSpot = 0 ;
2637
+
2638
+ payloadCfg[0 ] = 0x00 ; // message version
2639
+
2640
+ // bytes 1-3 are reserved - and must be set to zero
2641
+ payloadCfg[1 ] = 0x00 ;
2642
+ payloadCfg[2 ] = 0x00 ;
2643
+ payloadCfg[3 ] = 0x00 ;
2644
+
2645
+ // duration
2646
+ // big endian to little endian, switch byte order
2647
+ payloadCfg[4 ] = (durationInMs >> (8 *0 )) & 0xff ;
2648
+ payloadCfg[5 ] = (durationInMs >> (8 *1 )) & 0xff ;
2649
+ payloadCfg[6 ] = (durationInMs >> (8 *2 )) & 0xff ;
2650
+ payloadCfg[7 ] = (durationInMs >> (8 *3 )) & 0xff ;
2651
+
2652
+ // flags
2653
+
2654
+ // disables USB interface when powering off, defaults to true
2655
+ if (forceWhileUsb)
2656
+ {
2657
+ payloadCfg[8 ] = 0x06 ; // force | backup
2658
+ }
2659
+ else
2660
+ {
2661
+ payloadCfg[8 ] = 0x02 ; // backup only (leave the force bit clear - module will stay on if USB is connected)
2662
+ }
2663
+
2664
+ payloadCfg[9 ] = 0x00 ;
2665
+ payloadCfg[10 ] = 0x00 ;
2666
+ payloadCfg[11 ] = 0x00 ;
2667
+
2668
+ // wakeUpSources
2669
+
2670
+ // wakeupPin mapping, defaults to VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0
2671
+
2672
+ // Possible values are:
2673
+ // VAL_RXM_PMREQ_WAKEUPSOURCE_UARTRX
2674
+ // VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0
2675
+ // VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT1
2676
+ // VAL_RXM_PMREQ_WAKEUPSOURCE_SPICS
2677
+
2678
+ payloadCfg[12 ] = (wakeupSources >> (8 *0 )) & 0xff ;
2679
+ payloadCfg[13 ] = (wakeupSources >> (8 *1 )) & 0xff ;
2680
+ payloadCfg[14 ] = (wakeupSources >> (8 *2 )) & 0xff ;
2681
+ payloadCfg[15 ] = (wakeupSources >> (8 *3 )) & 0xff ;
2682
+
2683
+ if (maxWait != 0 )
2684
+ {
2685
+ // check for "not acknowledged" command
2686
+ return (sendCommand (&packetCfg, maxWait) != SFE_UBLOX_STATUS_COMMAND_NACK);
2687
+ }
2688
+ else
2689
+ {
2690
+ sendCommand (&packetCfg, maxWait);
2691
+ return false ; // can't tell if command not acknowledged if maxWait = 0
2692
+ }
2693
+ }
2694
+
2572
2695
// Change the dynamic platform model using UBX-CFG-NAV5
2573
2696
// Possible values are:
2574
2697
// PORTABLE,STATIONARY,PEDESTRIAN,AUTOMOTIVE,SEA,
0 commit comments