Testing
Dependencies: mbed FatFileSystemCpp
main.cpp@0:1855e9b8c2a2, 2020-04-24 (annotated)
- Committer:
- Richard_Xiong
- Date:
- Fri Apr 24 01:49:33 2020 +0000
- Revision:
- 0:1855e9b8c2a2
USBTesting
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Richard_Xiong | 0:1855e9b8c2a2 | 1 | #include "mbed.h" |
Richard_Xiong | 0:1855e9b8c2a2 | 2 | #include "MSCFileSystem.h" |
Richard_Xiong | 0:1855e9b8c2a2 | 3 | #define FSNAME "msc" |
Richard_Xiong | 0:1855e9b8c2a2 | 4 | |
Richard_Xiong | 0:1855e9b8c2a2 | 5 | Serial pc(USBTX,USBRX); |
Richard_Xiong | 0:1855e9b8c2a2 | 6 | MSCFileSystem msc(FSNAME); |
Richard_Xiong | 0:1855e9b8c2a2 | 7 | |
Richard_Xiong | 0:1855e9b8c2a2 | 8 | int main() |
Richard_Xiong | 0:1855e9b8c2a2 | 9 | { |
Richard_Xiong | 0:1855e9b8c2a2 | 10 | |
Richard_Xiong | 0:1855e9b8c2a2 | 11 | |
Richard_Xiong | 0:1855e9b8c2a2 | 12 | float buf_distance[2], buf_calories[2]; |
Richard_Xiong | 0:1855e9b8c2a2 | 13 | int buf_steps[2],buf_flights[2]; |
Richard_Xiong | 0:1855e9b8c2a2 | 14 | char buf_date[100]; |
Richard_Xiong | 0:1855e9b8c2a2 | 15 | char buffer[100]; |
Richard_Xiong | 0:1855e9b8c2a2 | 16 | |
Richard_Xiong | 0:1855e9b8c2a2 | 17 | |
Richard_Xiong | 0:1855e9b8c2a2 | 18 | |
Richard_Xiong | 0:1855e9b8c2a2 | 19 | while (1) { |
Richard_Xiong | 0:1855e9b8c2a2 | 20 | |
Richard_Xiong | 0:1855e9b8c2a2 | 21 | if (pc.readable()) { |
Richard_Xiong | 0:1855e9b8c2a2 | 22 | if (pc.getc() =='!') { |
Richard_Xiong | 0:1855e9b8c2a2 | 23 | if(pc.getc() == 'p') { |
Richard_Xiong | 0:1855e9b8c2a2 | 24 | FILE *fp = fopen( "/msc/data.txt", "r"); |
Richard_Xiong | 0:1855e9b8c2a2 | 25 | if(fp == NULL) { |
Richard_Xiong | 0:1855e9b8c2a2 | 26 | error("Could not open file for write\n"); |
Richard_Xiong | 0:1855e9b8c2a2 | 27 | } |
Richard_Xiong | 0:1855e9b8c2a2 | 28 | for (int i = 0; i<7; i++) { |
Richard_Xiong | 0:1855e9b8c2a2 | 29 | |
Richard_Xiong | 0:1855e9b8c2a2 | 30 | fscanf(fp,"%s\t%d\t%d\t%f\t%f\n\r", &buf_date[0], &buf_steps[0], &buf_flights[0], &buf_calories[0], &buf_distance[0]); |
Richard_Xiong | 0:1855e9b8c2a2 | 31 | |
Richard_Xiong | 0:1855e9b8c2a2 | 32 | sprintf(buffer,"%s\t%d\t%d\t%f\t%f\n\r", buf_date, buf_steps[0], buf_flights[0], buf_calories[0], buf_distance[0]); |
Richard_Xiong | 0:1855e9b8c2a2 | 33 | |
Richard_Xiong | 0:1855e9b8c2a2 | 34 | pc.printf("%s",buffer); |
Richard_Xiong | 0:1855e9b8c2a2 | 35 | |
Richard_Xiong | 0:1855e9b8c2a2 | 36 | } |
Richard_Xiong | 0:1855e9b8c2a2 | 37 | fclose(fp); |
Richard_Xiong | 0:1855e9b8c2a2 | 38 | |
Richard_Xiong | 0:1855e9b8c2a2 | 39 | } |
Richard_Xiong | 0:1855e9b8c2a2 | 40 | } |
Richard_Xiong | 0:1855e9b8c2a2 | 41 | } |
Richard_Xiong | 0:1855e9b8c2a2 | 42 | } |
Richard_Xiong | 0:1855e9b8c2a2 | 43 | } |