A system to help you ride your bike better than you do right now.
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed LSM9DS1_Library_cal
main.cpp@0:134f49df01f8, 2016-12-02 (annotated)
- Committer:
- kswanson31
- Date:
- Fri Dec 02 22:15:09 2016 +0000
- Revision:
- 0:134f49df01f8
- Child:
- 1:9d3f2e86392e
initial commit with sd functions started
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kswanson31 | 0:134f49df01f8 | 1 | #include "mbed.h" |
kswanson31 | 0:134f49df01f8 | 2 | #include "SDFileSystem.h" |
kswanson31 | 0:134f49df01f8 | 3 | #include "uLCD_4GDL.h" |
kswanson31 | 0:134f49df01f8 | 4 | |
kswanson31 | 0:134f49df01f8 | 5 | DigitalOut myled(LED1); |
kswanson31 | 0:134f49df01f8 | 6 | |
kswanson31 | 0:134f49df01f8 | 7 | SDFileSystem sd(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); //mosi -> DI, miso <- DO, slck -> sclck, CS -> CS |
kswanson31 | 0:134f49df01f8 | 8 | uLCD_4DGL lcd(PinName tx, PinName rx, PinName rst); |
kswanson31 | 0:134f49df01f8 | 9 | |
kswanson31 | 0:134f49df01f8 | 10 | float distance; |
kswanson31 | 0:134f49df01f8 | 11 | float speed; |
kswanson31 | 0:134f49df01f8 | 12 | float maxSpeed; |
kswanson31 | 0:134f49df01f8 | 13 | |
kswanson31 | 0:134f49df01f8 | 14 | int main() { |
kswanson31 | 0:134f49df01f8 | 15 | |
kswanson31 | 0:134f49df01f8 | 16 | // open the file for reading and appending records |
kswanson31 | 0:134f49df01f8 | 17 | FILE *fp = fopen("/sd/records/best-of.txt", "a+"); |
kswanson31 | 0:134f49df01f8 | 18 | |
kswanson31 | 0:134f49df01f8 | 19 | // recall last trip |
kswanson31 | 0:134f49df01f8 | 20 | recall_trip(&fp); |
kswanson31 | 0:134f49df01f8 | 21 | wait(10); |
kswanson31 | 0:134f49df01f8 | 22 | lcd.cls(); |
kswanson31 | 0:134f49df01f8 | 23 | |
kswanson31 | 0:134f49df01f8 | 24 | // normal operation loop here |
kswanson31 | 0:134f49df01f8 | 25 | // check current speed |
kswanson31 | 0:134f49df01f8 | 26 | // check curret distance |
kswanson31 | 0:134f49df01f8 | 27 | // check time so far |
kswanson31 | 0:134f49df01f8 | 28 | // display this on the screen |
kswanson31 | 0:134f49df01f8 | 29 | // check if braking, turning left or right |
kswanson31 | 0:134f49df01f8 | 30 | // show that on the screen |
kswanson31 | 0:134f49df01f8 | 31 | |
kswanson31 | 0:134f49df01f8 | 32 | // store this trip |
kswanson31 | 0:134f49df01f8 | 33 | lcd.cls(); |
kswanson31 | 0:134f49df01f8 | 34 | store_trip(&fp); |
kswanson31 | 0:134f49df01f8 | 35 | |
kswanson31 | 0:134f49df01f8 | 36 | // close the file at the end of the program |
kswanson31 | 0:134f49df01f8 | 37 | fclose(fp); |
kswanson31 | 0:134f49df01f8 | 38 | // end everything |
kswanson31 | 0:134f49df01f8 | 39 | } |
kswanson31 | 0:134f49df01f8 | 40 | |
kswanson31 | 0:134f49df01f8 | 41 | void store_trip(FILE * fp) { |
kswanson31 | 0:134f49df01f8 | 42 | // write trip results to the SD card |
kswanson31 | 0:134f49df01f8 | 43 | } |
kswanson31 | 0:134f49df01f8 | 44 | |
kswanson31 | 0:134f49df01f8 | 45 | void recall_trip(FILE * fp) { |
kswanson31 | 0:134f49df01f8 | 46 | // display the most recent trip made on the screen |
kswanson31 | 0:134f49df01f8 | 47 | // display the most impressive trip (longest distance, best speed, least time) |
kswanson31 | 0:134f49df01f8 | 48 | |
kswanson31 | 0:134f49df01f8 | 49 | int lineCount; |
kswanson31 | 0:134f49df01f8 | 50 | std::ifstream file("/sd/records/best-of.txt"); |
kswanson31 | 0:134f49df01f8 | 51 | char str[12]; |
kswanson31 | 0:134f49df01f8 | 52 | char split; |
kswanson31 | 0:134f49df01f8 | 53 | |
kswanson31 | 0:134f49df01f8 | 54 | if(fp == NULL) { |
kswanson31 | 0:134f49df01f8 | 55 | lcd.locate(0, 1); |
kswanson31 | 0:134f49df01f8 | 56 | lcd.printf("Could not open file for write\n"); |
kswanson31 | 0:134f49df01f8 | 57 | } else { |
kswanson31 | 0:134f49df01f8 | 58 | lcd.locate(0, 1); |
kswanson31 | 0:134f49df01f8 | 59 | while (std::getline(file, str)) { |
kswanson31 | 0:134f49df01f8 | 60 | |
kswanson31 | 0:134f49df01f8 | 61 | } |
kswanson31 | 0:134f49df01f8 | 62 | } |
kswanson31 | 0:134f49df01f8 | 63 | } |