Skip to content

Commit 2d830ea

Browse files
committed
feat: implement main function for GPS data processing and output
1 parent 65c523f commit 2d830ea

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

uart/gps_uart/gps_uart.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include <string.h>
77
#include <stdbool.h>
88

9-
9+
// uart id and tx/rx pins could vary according to the microcontroller used
10+
// please refer to the datasheet
1011
#define UART_ID uart1
1112
#define BAUD_RATE 9600
1213
#define UART_TX_PIN 4
@@ -156,4 +157,35 @@ void process_gps_data(GPSData *gps_data)
156157
chars_read++;
157158
}
158159
}
159-
}
160+
}
161+
162+
int main()
163+
{
164+
stdio_init_all();
165+
166+
uart_gps_init();
167+
168+
// recommended cold start waiting time (could vary based on the gps module)
169+
sleep_ms(7 * 60 * 1000);
170+
171+
GPSData gps_data = {0};
172+
173+
while (1)
174+
{
175+
process_gps_data(&gps_data);
176+
177+
if (gps_data.is_valid)
178+
{
179+
printf("GPS Location:\n");
180+
printf("Latitude: %.6f\n", gps_data.latitude);
181+
printf("Longitude: %.6f\n", gps_data.longitude);
182+
gps_data.is_valid = false;
183+
}
184+
185+
// sufficient waiting time required between each gps reading and the next one
186+
sleep_ms(30 * 1000);
187+
tight_loop_contents();
188+
}
189+
190+
return 0;
191+
}

0 commit comments

Comments
 (0)