Enregistrement des infos du GPS sur la carte SD
Dependencies: SDFileSystem mbed
main.cpp@0:2a7418242b56, 2016-04-23 (annotated)
- Committer:
- maxlh23
- Date:
- Sat Apr 23 07:21:51 2016 +0000
- Revision:
- 0:2a7418242b56
Enregistrement des infos du GPS sur la carte SD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maxlh23 | 0:2a7418242b56 | 1 | #include "mbed.h" |
maxlh23 | 0:2a7418242b56 | 2 | #include "SDFileSystem.h" |
maxlh23 | 0:2a7418242b56 | 3 | |
maxlh23 | 0:2a7418242b56 | 4 | SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "card"); // the pinout on the mbed Cool Components workshop board |
maxlh23 | 0:2a7418242b56 | 5 | Serial pc(USBTX, USBRX); // tx, rx |
maxlh23 | 0:2a7418242b56 | 6 | Serial gps(D1, D0); // tx, rx |
maxlh23 | 0:2a7418242b56 | 7 | DigitalOut led1(LED1); |
maxlh23 | 0:2a7418242b56 | 8 | InterruptIn button(PTA4); |
maxlh23 | 0:2a7418242b56 | 9 | |
maxlh23 | 0:2a7418242b56 | 10 | FILE *fp; |
maxlh23 | 0:2a7418242b56 | 11 | int run =1; |
maxlh23 | 0:2a7418242b56 | 12 | |
maxlh23 | 0:2a7418242b56 | 13 | void callback() { |
maxlh23 | 0:2a7418242b56 | 14 | char s = gps.getc(); |
maxlh23 | 0:2a7418242b56 | 15 | fprintf(fp, &s); |
maxlh23 | 0:2a7418242b56 | 16 | //pc.printf(&s); a enlever si on veut voir les infos du gps en continu sur le terminal |
maxlh23 | 0:2a7418242b56 | 17 | } |
maxlh23 | 0:2a7418242b56 | 18 | void stop() { |
maxlh23 | 0:2a7418242b56 | 19 | run =0; |
maxlh23 | 0:2a7418242b56 | 20 | } |
maxlh23 | 0:2a7418242b56 | 21 | int main() { |
maxlh23 | 0:2a7418242b56 | 22 | |
maxlh23 | 0:2a7418242b56 | 23 | pc.printf("Initialized recording\n"); |
maxlh23 | 0:2a7418242b56 | 24 | gps.baud(9600); |
maxlh23 | 0:2a7418242b56 | 25 | pc.baud(9600); |
maxlh23 | 0:2a7418242b56 | 26 | mkdir("/card/gps_tracking", 0777); |
maxlh23 | 0:2a7418242b56 | 27 | |
maxlh23 | 0:2a7418242b56 | 28 | fp = fopen("/card/gps_tracking/sdfile.txt", "w"); |
maxlh23 | 0:2a7418242b56 | 29 | if(fp == NULL) { |
maxlh23 | 0:2a7418242b56 | 30 | error("Could not open file for write\n"); |
maxlh23 | 0:2a7418242b56 | 31 | } |
maxlh23 | 0:2a7418242b56 | 32 | gps.attach(&callback); |
maxlh23 | 0:2a7418242b56 | 33 | pc.attach(&stop); |
maxlh23 | 0:2a7418242b56 | 34 | button.rise(&stop); |
maxlh23 | 0:2a7418242b56 | 35 | |
maxlh23 | 0:2a7418242b56 | 36 | while(run==1) { |
maxlh23 | 0:2a7418242b56 | 37 | led1 = !led1; |
maxlh23 | 0:2a7418242b56 | 38 | wait(0.5); |
maxlh23 | 0:2a7418242b56 | 39 | } |
maxlh23 | 0:2a7418242b56 | 40 | fclose(fp); |
maxlh23 | 0:2a7418242b56 | 41 | |
maxlh23 | 0:2a7418242b56 | 42 | pc.printf("Recording finished.\n"); |
maxlh23 | 0:2a7418242b56 | 43 | } |