Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: GPS TextLCD mbed
Fork of GPS_classroom by
Diff: main.cpp
- Revision:
- 2:8c0dcaa10883
- Parent:
- 1:326b1e0bbe56
- Child:
- 3:37086b58ab05
diff -r 326b1e0bbe56 -r 8c0dcaa10883 main.cpp
--- a/main.cpp Mon May 04 04:43:11 2015 +0000
+++ b/main.cpp Sat May 23 04:27:29 2015 +0000
@@ -4,25 +4,69 @@
GPS gps(PA_11,PA_12);
I2C i2c_lcd(D14,D15);
TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2);
+Serial esp(D8,D2);
+uint8_t buffer[0x100];
+uint16_t buffer_head;
+uint16_t buffer_tail;
+
+void rxcallback(void) {
+ uint8_t chr;
+ while (esp.readable()) {
+ chr = esp.getc();
+ pc.putc(chr);
+ buffer[buffer_head++] = chr;
+ if (buffer_head == BUFFER_SIZE)
+ {
+ buffer_head = 0;
+ }
+ }
+}
+void flush_fifo(void)
+{
+ while (esp.readable())
+ {
+ (void)esp.getc();
+ }
+ buffer_head = 0;
+ buffer_tail = 0;
+}
+int find_response(const char *resp) {
+ /* Give some delay for buffer to fill up */
+ wait_ms(10);
+ int timeout = 0xFFFFFF;
+ int len = strlen(resp);
+ do
+ {
+ if (buffer_head > (buffer_tail + len))
+ {
+ if (!memcmp(&buffer[buffer_tail], resp, len))
+ {
+ flush_fifo();
+ return 0;
+ }
+ buffer_tail++;
+ }
+ }while(timeout--);
+ flush_fifo();
+ return 1;
+}
+
int main()
{
lcd.setMode(TextLCD::DispOn);
lcd.setBacklight(TextLCD::LightOff);
lcd.setCursor(TextLCD::CurOff_BlkOff);
+ esp.attach(&rxcallback, Serial::RxIrq);
lcd.setAddress(0,0);
lcd.printf("Initial GPS...\n");
-
+ esp.printf("AT+RST\r\n");
+
while(1){
if(gps.sample())
{
lcd.setAddress(0,1);
lcd.printf("%6.3f,%7.3f",gps.latitude,gps.longitude);
}
- else
- {
- lcd.setAddress(0,1);
- lcd.printf("GPS invalid");
- }
wait(0.5);
}
}
