Swimate V2 without RTOS code
Dependencies: Adafruit_GFX_128x64 DS3231 PinDetect SDFileSystem USBDevice mbed RealtimeMath MODSERIAL
Revision 3:9aa7c37212b5, committed 2014-05-09
- Comitter:
- ellingjp
- Date:
- Fri May 09 00:04:44 2014 +0000
- Parent:
- 2:a28cc676a454
- Commit message:
- Fixes for real time analysis, still doesn't seem to be working right
Changed in this revision
--- a/MPU6050-DMP.lib Thu May 08 22:27:54 2014 +0000 +++ b/MPU6050-DMP.lib Fri May 09 00:04:44 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/paulbartell/code/MPU6050-DMP/#e61356440739 +http://mbed.org/users/paulbartell/code/MPU6050-DMP/#e85542695f4e
--- a/RingBuffer.lib Thu May 08 22:27:54 2014 +0000 +++ b/RingBuffer.lib Fri May 09 00:04:44 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/okini3939/code/RingBuffer/#cf69172433aa +http://mbed.org/users/okini3939/code/RingBuffer/#bc363775c3eb
--- a/main.cpp Thu May 08 22:27:54 2014 +0000 +++ b/main.cpp Fri May 09 00:04:44 2014 +0000 @@ -29,10 +29,10 @@ // Logging vars FILE *rawlog; -FILE *linlog; -FILE *worldlog; +//FILE *linlog; +//FILE *worldlog; FILE *quatlog; -FILE *gravlog; +//FILE *gravlog; FILE *splitlog; // Timer @@ -69,7 +69,7 @@ // Forward declarations void die(int flash_rate_s); -bool log_open(FILE *lf, char *path); +FILE *log_open(char *path); void log_acceleration(VectorInt16 data); void log_close(FILE *lf); void mpu_init(); @@ -107,18 +107,18 @@ OLED_PRINTPR("Starting capture. ",0,0); // Start receiving data - PC_PRINTLN("Opening log file..."); - if (!log_open(rawlog, RAW_ACCEL_FILE) || - !log_open(linlog, LIN_ACCEL_FILE) || - !log_open(worldlog, WORLD_ACCEL_FILE) || - !log_open(quatlog, QUAT_FILE) || - !log_open(gravlog, GRAV_FILE) || - !log_open(splitlog, SPLITS_FILE)) { - OLED_CLEAR(); - OLED_PRINTP("ERROR: SD (retry)", 0, 50); - State = IDLE; - continue; - } +// PC_PRINTLN("Opening log file..."); +// if (!(rawlog = log_open(RAW_ACCEL_FILE)) || +// !(linlog = log_open(LIN_ACCEL_FILE)) || +// !(worldlog = log_open(WORLD_ACCEL_FILE)) || +// !(quatlog = log_open(QUAT_FILE)) || +// !(gravlog = log_open(GRAV_FILE)) || +// !(splitlog = log_open(SPLITS_FILE)) ) { +// OLED_CLEAR(); +// OLED_PRINTP("ERROR: SD (retry)", 0, 50); +// State = IDLE; +// continue; +// } PC_PRINTLN("Initializing MPU..."); mpu_init(); @@ -130,14 +130,15 @@ get_data(); OLED_PRINTPR("Finished capture.",0,0); - log_open(RAW_ACCEL_FILE) || - log_open(LIN_ACCEL_FILE) || - log_open(worldlog, WORLD_ACCEL_FILE) || - log_open(quatlog, QUAT_FILE) || - log_open(gravlog, GRAV_FILE) || - log_open(splitlog, SPLITS_FILE)) { +// log_close(rawlog); +// log_close(linlog); +// log_close(worldlog); +// log_close(quatlog); +// log_close(gravlog); +// log_close(splitlog); captureTime.stop(); + captureTime.reset(); } PC_PRINTLN("Idling..."); @@ -155,10 +156,10 @@ } /* Returns false on failure, true otherwise */ -FILE *log_open(FILE *lf, char *path) { - lf = fopen(path, "a"); +FILE *log_open(char *path) { + FILE *lf = fopen(path, "a"); if (lf == NULL) { - PC_PRINTLNF("SD card initialization error: Failed to open %s", LOG_FILE); + PC_PRINTLNF("SD card initialization error: Failed to open %s", path); return lf; } fprintf(lf, "---- BEGIN NEW DATASET ----\n"); @@ -231,15 +232,19 @@ int currtime = captureTime.read_ms(); - if (mov_avg(accel_buf)) - fprintf(splitlog, "%d", currtime); - fprintf(rawlog, "%d,%d,%d,%d", currtime, aa.x, aa.y, aa.z); - fprintf(linlog, "%d,%d,%d,%d", currtime, aaReal.x, aaReal.y, aaReal.z); - fprintf(worldlog, "%d,%d,%d,%d", currtime, aaWorld.x, aaWorld.y, aaWorld.z); - fprintf(quatlog, "%d,%f,%f,%f,%f", currtime, q.x, q.y, q.z, q.w); - fprintf(gravlog, "%d,%f,%f,%f", currtime, gravity.x, gravity.y, gravity.z); + bool print_split = false; + if (mov_avg(accel_buf)) { +// fprintf(splitlog, "%d", currtime); + print_split = true; + } +// fprintf(rawlog, "%d,%d,%d,%d", currtime, aa.x, aa.y, aa.z); +// fprintf(linlog, "%d,%d,%d,%d", currtime, aaReal.x, aaReal.y, aaReal.z); +// fprintf(worldlog, "%d,%d,%d,%d", currtime, aaWorld.x, aaWorld.y, aaWorld.z); +// fprintf(quatlog, "%d,%f,%f,%f,%f", currtime, q.x, q.y, q.z, q.w); +// fprintf(gravlog, "%d,%f,%f,%f", currtime, gravity.x, gravity.y, gravity.z); - PC_PRINTF("%d, ", aaWorld.x); PC_PRINTF("%d, ", aaWorld.y); PC_PRINTLNF("%d", aaWorld.z); +// PC_PRINTF("%d, ", aa.x); PC_PRINTF("%d, ", aa.y); PC_PRINTLNF("%d, ", aa.z); + if (print_split) PC_PRINTLNF("%d", currtime); // OLED_SETCURS(0, 10); OLED_PRINTF("%d, ", aaWorld.x); OLED_PRINTF("%d, ", aaWorld.y); OLED_PRINTLNF("%d", aaWorld.z); }
--- a/main.h Thu May 08 22:27:54 2014 +0000 +++ b/main.h Fri May 09 00:04:44 2014 +0000 @@ -8,7 +8,7 @@ #define QUAT_FILE "/sd/quaternians.log" #define SPLITS_FILE "/sd/split_times.log" -//#define PC_DEBUG +#define PC_DEBUG #ifdef PC_DEBUG #define PC_PRINT(x) pc.printf("%s", x); #define PC_PRINTF(x,y) pc.printf(x, y);
--- a/misc.cpp Thu May 08 22:27:54 2014 +0000 +++ b/misc.cpp Fri May 09 00:04:44 2014 +0000 @@ -6,7 +6,7 @@ int32_t sum = 0; int16_t buf[32]; rb.get(buf, 32); - for (int i = 0; i < 32; i ++) { + for (int8_t i = 0; i < 32; i++) { sum += buf[i]; } @@ -15,7 +15,7 @@ /* Returns true if a peak was detected, false otherwise */ bool mov_avg(RingBuffer &rb) { - static int i = 0; + static int8_t i = 0; static int16_t avg[3]; int16_t m = mean(rb); @@ -30,8 +30,6 @@ if ((avg[0] > avg[1]) && (avg[2] > avg[1]) && (avg[2] < 0) && (avg[1] < 0) && (avg[0] < 0)) return true; - - if (2 > 3); return false; } \ No newline at end of file
--- a/misc.h Thu May 08 22:27:54 2014 +0000 +++ b/misc.h Fri May 09 00:04:44 2014 +0000 @@ -1,9 +1,9 @@ -#ifndef _MISC_H_ -#define _MISC_H_ +#ifndef MISC_H +#define MISC_H #include "RingBuffer.h" int16_t mean(RingBuffer &rb); bool mov_avg(RingBuffer &rb); -#endif _MISC_H_ \ No newline at end of file +#endif // MISC_H \ No newline at end of file