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