24
24
*/
25
25
26
26
const int addr = 0x10 ;
27
- const int max_read = 250 ;
27
+ #define MAX_READ 250
28
28
29
29
#ifdef i2c_default
30
30
@@ -44,24 +44,24 @@ void pa1010d_parse_string(char output[], char protocol[]) {
44
44
int p = com_index - output ;
45
45
46
46
// Splits components of output sentence into array
47
- int no_of_fields = 14 ;
48
- int max_len = 15 ;
47
+ #define NO_OF_FIELDS 14
48
+ #define MAX_LEN 15
49
49
50
50
int n = 0 ;
51
51
int m = 0 ;
52
52
53
- char gps_data [no_of_fields ][ max_len ];
53
+ char gps_data [NO_OF_FIELDS ][ MAX_LEN ];
54
54
memset (gps_data , 0 , sizeof (gps_data ));
55
55
56
56
bool complete = false;
57
- while (output [p ] != '$' && n < max_len && complete == false) {
57
+ while (output [p ] != '$' && n < MAX_LEN && complete == false) {
58
58
if (output [p ] == ',' || output [p ] == '*' ) {
59
59
n += 1 ;
60
60
m = 0 ;
61
61
} else {
62
62
gps_data [n ][m ] = output [p ];
63
63
// Checks if sentence is complete
64
- if (m < no_of_fields ) {
64
+ if (m < NO_OF_FIELDS ) {
65
65
m ++ ;
66
66
} else {
67
67
complete = true;
@@ -92,15 +92,15 @@ void pa1010d_parse_string(char output[], char protocol[]) {
92
92
}
93
93
94
94
void pa1010d_read_raw (char numcommand []) {
95
- uint8_t buffer [max_read ];
95
+ uint8_t buffer [MAX_READ ];
96
96
97
97
int i = 0 ;
98
98
bool complete = false;
99
99
100
- i2c_read_blocking (i2c_default , addr , buffer , max_read , false);
100
+ i2c_read_blocking (i2c_default , addr , buffer , MAX_READ , false);
101
101
102
102
// Convert bytes to characters
103
- while (i < max_read && complete == false) {
103
+ while (i < MAX_READ && complete == false) {
104
104
numcommand [i ] = buffer [i ];
105
105
// Stop converting at end of message
106
106
if (buffer [i ] == 10 && buffer [i + 1 ] == 10 ) {
@@ -119,7 +119,7 @@ int main() {
119
119
puts ("Default I2C pins were not defined" );
120
120
#else
121
121
122
- char numcommand [max_read ];
122
+ char numcommand [MAX_READ ];
123
123
124
124
// Decide which protocols you would like to retrieve data from
125
125
char init_command [] = "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29\r\n" ;
@@ -140,7 +140,7 @@ int main() {
140
140
141
141
while (1 ) {
142
142
// Clear array
143
- memset (numcommand , 0 , max_read );
143
+ memset (numcommand , 0 , MAX_READ );
144
144
// Read and re-format
145
145
pa1010d_read_raw (numcommand );
146
146
pa1010d_parse_string (numcommand , "GNRMC" );
@@ -149,8 +149,7 @@ int main() {
149
149
sleep_ms (1000 );
150
150
151
151
// Clear terminal
152
- printf ("\e [1;1H\e [2J" );
152
+ printf ("\033 [1;1H\033 [2J" );
153
153
}
154
154
#endif
155
- return 0 ;
156
155
}
0 commit comments