Swimate V2 without RTOS code
Dependencies: Adafruit_GFX_128x64 DS3231 PinDetect SDFileSystem USBDevice mbed RealtimeMath MODSERIAL
log_data.cpp
- Committer:
- ellingjp
- Date:
- 2014-06-07
- Revision:
- 21:2fa676f214fe
- Parent:
- 15:002bac432234
- Child:
- 22:9350752f5414
File content as of revision 21:2fa676f214fe:
#include "mbed.h" #include "log_data.h" #include "SDFileSystem.h" #include "helper_3dmath.h" #include "debug.h" #include "SystemTime.h" #include "pins.h" // SD Card SDFileSystem sd(P0_21, P0_22, P1_15, P1_19, "sd"); // MOSI, MISO, SCLK, SSEL SPI1 // DS3231 rtc(I2C_SDA, I2C_SCL); // Logging vars FILE *accelFile; FILE *peakFile; /* Returns true if logging was successfully initialized, false otherwise */ bool log_init() { PC_PRINTLN("Initializing logging..."); accelFile = fopen(ACCEL_LOG, "a"); if (accelFile == NULL) { PC_PRINTLNF("SD card initialization error: Failed to open %s", ACCEL_LOG); DIE(SD_ERROR_RATE); return false; } peakFile = fopen(PEAK_LOG, "a"); if (peakFile == NULL) { PC_PRINTLNF("SD card initialization error: Failed to open %s", SPLIT_LOG); DIE(SD_ERROR_RATE); return false; } // fprintf(accelFile, "---- BEGIN NEW DATASET ----\n"); // fprintf(peakFile, "---- BEGIN NEW DATASET ----\n"); return true; } /* Returns true if data was successfully logged, false otherwise Used for logging acceleration data */ bool log_data(int time_ms, VectorInt16 *data) { if (accelFile != NULL) { // fprintf(accelFile, "%d, %d, %d, %d\n", time_ms, data->x, data->y, data->z); fwrite(&time_ms, sizeof(int), 1, accelFile); fwrite(data, sizeof(VectorInt16), 1, accelFile); return true; } return false; } /* Returns true if data was successfully logged, false otherwise Used for logging split times */ bool log_data(int time_ms, int split) { if (peakFile != NULL) { // fprintf(peakFile, "%d, %d\n", time_ms, split); fwrite( (void*) &time_ms, sizeof(int), 1, peakFile); fwrite( (void*) &split, sizeof(int), 1, peakFile); return true; } return false; } /* Returns true if logging was successfully closed, false otherwise */ bool log_close() { // if (accelFile != NULL && splitFile != NULL) // return ( (fclose(accelFile) == 0) && (fclose(splitFile) == 0) ); fclose(accelFile); fclose(peakFile); return true; }