16
16
17
17
#include < SparkFun_u-blox_SARA-R5_Arduino_Library.h>
18
18
19
- static boolean parseGPRMCString (char *rmcString, PositionData *pos, ClockData *clk, SpeedData *spd);
20
-
21
19
SARA_R5::SARA_R5 (int powerPin, int resetPin, uint8_t maxInitDepth)
22
20
{
23
21
#ifdef SARA_R5_SOFTWARE_SERIAL_ENABLED
@@ -27,6 +25,7 @@ SARA_R5::SARA_R5(int powerPin, int resetPin, uint8_t maxInitDepth)
27
25
_baud = 0 ;
28
26
_resetPin = resetPin;
29
27
_powerPin = powerPin;
28
+ _invertPowerPin = false ;
30
29
_maxInitDepth = maxInitDepth;
31
30
_socketReadCallback = NULL ;
32
31
_socketCloseCallback = NULL ;
@@ -1993,14 +1992,26 @@ SARA_R5_error_t SARA_R5::init(unsigned long baud,
1993
1992
return SARA_R5_ERROR_SUCCESS;
1994
1993
}
1995
1994
1995
+ void SARA_R5::invertPowerPin (boolean invert)
1996
+ {
1997
+ _invertPowerPin = invert;
1998
+ }
1999
+
1996
2000
void SARA_R5::powerOn (void )
1997
2001
{
1998
2002
if (_powerPin >= 0 )
1999
2003
{
2004
+ if (_invertPowerPin) // Set the pin state before making it an output
2005
+ digitalWrite (_powerPin, HIGH);
2006
+ else
2007
+ digitalWrite (_powerPin, LOW);
2000
2008
pinMode (_powerPin, OUTPUT);
2001
- digitalWrite (_powerPin, LOW);
2009
+ if (_invertPowerPin) // Set the pin state
2010
+ digitalWrite (_powerPin, HIGH);
2011
+ else
2012
+ digitalWrite (_powerPin, LOW);
2002
2013
delay (SARA_R5_POWER_PULSE_PERIOD);
2003
- pinMode (_powerPin, INPUT); // Return to high-impedance, rely on SARA module internal pull-up
2014
+ pinMode (_powerPin, INPUT); // Return to high-impedance, rely on (e.g.) SARA module internal pull-up
2004
2015
delay (2000 ); // Wait before sending AT commands to module. 100 is too short.
2005
2016
if (_printDebug == true ) _debugPort->println (F (" Power cycle complete." ));
2006
2017
}
@@ -2595,7 +2606,7 @@ void SARA_R5::pruneBacklog()
2595
2606
// GPS Helper Functions:
2596
2607
2597
2608
// Read a source string until a delimiter is hit, store the result in destination
2598
- static char *readDataUntil (char *destination, unsigned int destSize,
2609
+ char *SARA_R5:: readDataUntil (char *destination, unsigned int destSize,
2599
2610
char *source, char delimiter)
2600
2611
{
2601
2612
@@ -2614,15 +2625,19 @@ static char *readDataUntil(char *destination, unsigned int destSize,
2614
2625
return strEnd;
2615
2626
}
2616
2627
2617
- #define TEMP_NMEA_DATA_SIZE 16
2618
-
2619
- static boolean parseGPRMCString (char *rmcString, PositionData *pos,
2628
+ boolean SARA_R5::parseGPRMCString (char *rmcString, PositionData *pos,
2620
2629
ClockData *clk, SpeedData *spd)
2621
2630
{
2622
2631
char *ptr, *search;
2623
2632
unsigned long tTemp;
2624
2633
char tempData[TEMP_NMEA_DATA_SIZE];
2625
2634
2635
+ if (_printDebug == true )
2636
+ {
2637
+ _debugPort->println (F (" parseGPRMCString: rmcString: " ));
2638
+ _debugPort->println (rmcString);
2639
+ }
2640
+
2626
2641
// Fast-forward test to first value:
2627
2642
ptr = strchr (rmcString, ' ,' );
2628
2643
ptr++; // Move ptr past first comma
@@ -2670,7 +2685,7 @@ static boolean parseGPRMCString(char *rmcString, PositionData *pos,
2670
2685
{
2671
2686
pos->lat = atof (tempData); // Extract ddmm.mmmmm as float
2672
2687
unsigned long lat_deg = pos->lat / 100 ; // Extract the degrees
2673
- pos->lat -= (float )lat_deg * 60 .0 ; // Subtract the degrees leaving only the minutes
2688
+ pos->lat -= (float )lat_deg * 100 .0 ; // Subtract the degrees leaving only the minutes
2674
2689
pos->lat /= 60.0 ; // Convert minutes into degrees
2675
2690
pos->lat += (float )lat_deg; // Finally add the degrees back on again
2676
2691
}
@@ -2679,6 +2694,7 @@ static boolean parseGPRMCString(char *rmcString, PositionData *pos,
2679
2694
pos->lat = 0.0 ;
2680
2695
}
2681
2696
ptr = search + 1 ;
2697
+
2682
2698
// Find latitude hemishpere
2683
2699
search = readDataUntil (tempData, TEMP_NMEA_DATA_SIZE, ptr, ' ,' );
2684
2700
if ((search != NULL ) && (search == ptr + 1 ))
@@ -2694,7 +2710,7 @@ static boolean parseGPRMCString(char *rmcString, PositionData *pos,
2694
2710
{
2695
2711
pos->lon = atof (tempData); // Extract dddmm.mmmmm as float
2696
2712
unsigned long lon_deg = pos->lon / 100 ; // Extract the degrees
2697
- pos->lon -= (float )lon_deg * 60 .0 ; // Subtract the degrees leaving only the minutes
2713
+ pos->lon -= (float )lon_deg * 100 .0 ; // Subtract the degrees leaving only the minutes
2698
2714
pos->lon /= 60.0 ; // Convert minutes into degrees
2699
2715
pos->lon += (float )lon_deg; // Finally add the degrees back on again
2700
2716
}
@@ -2703,7 +2719,8 @@ static boolean parseGPRMCString(char *rmcString, PositionData *pos,
2703
2719
pos->lon = 0.0 ;
2704
2720
}
2705
2721
ptr = search + 1 ;
2706
- // Find latitude hemishpere
2722
+
2723
+ // Find longitude hemishpere
2707
2724
search = readDataUntil (tempData, TEMP_NMEA_DATA_SIZE, ptr, ' ,' );
2708
2725
if ((search != NULL ) && (search == ptr + 1 ))
2709
2726
{
@@ -2724,6 +2741,7 @@ static boolean parseGPRMCString(char *rmcString, PositionData *pos,
2724
2741
spd->speed = 0.0 ;
2725
2742
}
2726
2743
ptr = search + 1 ;
2744
+
2727
2745
// Find course over ground
2728
2746
search = readDataUntil (tempData, TEMP_NMEA_DATA_SIZE, ptr, ' ,' );
2729
2747
if ((search != NULL ) && (search != ptr))
@@ -2766,6 +2784,7 @@ static boolean parseGPRMCString(char *rmcString, PositionData *pos,
2766
2784
spd->magVar = 0.0 ;
2767
2785
}
2768
2786
ptr = search + 1 ;
2787
+
2769
2788
// Find magnetic variation direction
2770
2789
search = readDataUntil (tempData, TEMP_NMEA_DATA_SIZE, ptr, ' ,' );
2771
2790
if ((search != NULL ) && (search == ptr + 1 ))
0 commit comments