Daniel Levine / CircularBufferSDCardLib

Dependencies:   sd-driver_compatible_with_MAX32630FTHR

Fork of CircularBufferSDCardLib by Daniel Levine

Files at this revision

API Documentation at this revision

Comitter:
DVLevine
Date:
Wed Apr 04 17:15:36 2018 -0400
Parent:
2:c2cfb0ebc3bd
Child:
4:fe6d2823b7cb
Commit message:
Corrected a lot of small errors. Stil some more left.

Changed in this revision

dataRecorder.cpp Show annotated file Show diff for this revision Revisions of this file
dataRecorder.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
sdCardReader.cpp Show annotated file Show diff for this revision Revisions of this file
sdCardReader.h Show annotated file Show diff for this revision Revisions of this file
--- a/dataRecorder.cpp	Wed Apr 04 16:17:34 2018 -0400
+++ b/dataRecorder.cpp	Wed Apr 04 17:15:36 2018 -0400
@@ -1,14 +1,15 @@
 #include "dataRecorder.h"
 
 /* CONSTRUCTOR*/
+DataRecorder::DataRecorder(){
 
-DataRecorder::DataRecorder(){
+  DataRecorder();
   //Initialize SDCard Reader Class
   m_saveBuddy = new SDCardReader();
 
   //Initialize data quantity as 0
   m_data_quantity = 0;
-};
+}
 
 
 /* PUBLIC METHODS */
@@ -27,8 +28,10 @@
     if (m_data_quantity<0){
     m_data_quantity=0;
   }
+    uint16_t poppedData;
     if(!m_buf_data.empty()){
-      return m_buf_data.pop();
+      m_buf_data.pop(poppedData);
+      return poppedData;
     }else{
       return (uint16_t)0;
     }
@@ -41,8 +44,10 @@
     m_time_quantity=0;
   }
 
-  if(!m_buf_time.empty()){
-    return m_buf_time.pop();
+  uint32_t poppedData;
+  if(!m_buf_timestamp.empty()){
+    m_buf_timestamp.pop(poppedData);
+    return poppedData;
   }else{
     return (uint16_t)0;
   }
@@ -68,15 +73,17 @@
 /** Save logged data to SD card **/
 void DataRecorder::saveLoggedData(string filename){
   //iterate over buffer and use the sd card commands
+  int numPoints = m_data_quantity; //add check for timestamps
+  
   int indexArr[m_data_quantity];
-  for (int i = indexArr.size-1; i >=0 ; i--){
+  for (int i = m_data_quantity; i >=0 ; i--){
     indexArr[i] = i;
   }
   
   uint32_t timeArr[m_time_quantity];
   uint16_t* allDataArr[m_data_quantity];
 
-  for (int i = 0; i < allDataArr.size; i++){
+  for (int i = 0; i < numPoints; i++){
     uint16_t dataEntry[1];
     dataEntry[1] = popLastDataPoint(); 
     allDataArr[i] = dataEntry;
--- a/dataRecorder.h	Wed Apr 04 16:17:34 2018 -0400
+++ b/dataRecorder.h	Wed Apr 04 17:15:36 2018 -0400
@@ -1,3 +1,6 @@
+#ifndef _DATARECORDER_H_
+#define _DATARECORDER_H_
+
 #include "mbed.h"
 #include "platform/CircularBuffer.h"
 #include "sdCardReader.h"
@@ -16,11 +19,11 @@
 
 class DataRecorder{
   public:
-    DataRecorder();
-
+  DataRecorder();
     /** Get Information **/
     // gets the number of values stored in the circular buffer
-    int getQuantityStored();
+    int getDataQuantity();
+    int getTimeStampQuantity();
     
     // pops the last value off of the circular buffer 
     uint16_t popLastDataPoint();
@@ -45,8 +48,8 @@
     // sd card
 
     /* Buffers for Data Storage */
-    CircularBuffer<uint16_t, BUF_SIZE> buf_data;
-    CircularBuffer<uint32_t, BUF_SIZE> buf_timestamp;
+    CircularBuffer<uint16_t, BUF_SIZE> m_buf_data;
+    CircularBuffer<uint32_t, BUF_SIZE> m_buf_timestamp;
 
     // Count for buffers
     int m_data_quantity;
@@ -82,3 +85,6 @@
     const uint8_t separator = ' ';*/
     
 };
+
+
+#endif
--- a/main.cpp	Wed Apr 04 16:17:34 2018 -0400
+++ b/main.cpp	Wed Apr 04 17:15:36 2018 -0400
@@ -1,17 +1,12 @@
 #include "mbed.h"
-#include "sdCardReader.h"
 #include "dataRecorder.h"
 
-
-static const char *sd_file_path = "/sd/out.txt";
-
 DataRecorder* boba = new DataRecorder();
-static SDCardReader soba;// = new SDCardReader();
 
 //For SDCard 
-// Set up the button to trigger an erase
-InterruptIn irq(BUTTON1);      
-DigitalOut led1(LED1);
+// Set up the button
+InterruptIn irq(PF_2);      
+DigitalOut led1(PE_0);
 
 // main() runs in its own thread in the OS
 int main() {
@@ -22,13 +17,25 @@
      uint16_t c = 1040;
      uint16_t d = 8;
      uint16_t e = 980;
-     
+
+     uint32_t ta = 2121;
+     uint32_t tb = 8181;
+     uint32_t tc = 6262;
+     uint32_t td = 3535;
+     uint32_t te = 1212;
    
-    boba->LogDistancePoint(a);
-    boba->LogDistancePoint(b);
-    boba->LogDistancePoint(c);
-    boba->LogDistancePoint(d);
-    boba->LogDistancePoint(e);
+    boba->logDistancePoint(a);
+    boba->logDistancePoint(b);
+    boba->logDistancePoint(c);
+    boba->logDistancePoint(d);
+    boba->logDistancePoint(e);
+
+    boba->logTimeStamp(a);
+    boba->logTimeStamp(b);
+    boba->logTimeStamp(c);
+    boba->logTimeStamp(d);
+    boba->logTimeStamp(e);
+    
     
     //printf("ERE IS %i \n",ere);
 
--- a/sdCardReader.cpp	Wed Apr 04 16:17:34 2018 -0400
+++ b/sdCardReader.cpp	Wed Apr 04 17:15:36 2018 -0400
@@ -6,14 +6,14 @@
 void SDCardReader::mountFileSystem(){
     printf("Mounting the filesystem... ");
     fflush(stdout);
-    int err = m_fs.mount(&this);
+    int err = m_fs->mount(&this);
     printf("%s\n", (err ? "Fail :(" : "OK"));
     if (err) {
         // Reformat if we can't mount the filesystem
         // this should only happen on the first boot
         printf("No filesystem found, formatting... ");
         fflush(stdout);
-        err = m_fs.reformat(&this);
+        err = m_fs->reformat(&this);
         printf("%s\n", (err ? "Fail :(" : "OK"));
         if (err) {
             error("error: %s (%d)\n", strerror(-err), err);
@@ -24,7 +24,7 @@
 void SDCardReader::unmountFileSystem(){
   printf("Unmounting... ");
   fflush(stdout);
-  err = m_fs.unmount();
+  err = m_fs->unmount();
   printf("%s\n", (err < 0 ? "Fail :(" : "OK"));
   if (err < 0) {
     error("error: %s (%d)\n", strerror(-err), err);
--- a/sdCardReader.h	Wed Apr 04 16:17:34 2018 -0400
+++ b/sdCardReader.h	Wed Apr 04 17:15:36 2018 -0400
@@ -12,9 +12,11 @@
 //#include "LittleFileSystem.h"
 #include "FATFileSystem.h"
 
-class SDCardReader : public SDBlockDevice{
+class SDCardReader:public SDBlockDevice{
     public:
-        SDCardReader(PinName a=MBED_CONF_SD_SPI_MOSI, PinName b=MBED_CONF_SD_SPI_MISO, PinName c=MBED_CONF_SD_SPI_CLK, PinName d=MBED_CONF_SD_SPI_CS):SDBlockDevice(a, b, c, d){};
+        SDCardReader(PinName a=MBED_CONF_SD_SPI_MOSI, PinName b=MBED_CONF_SD_SPI_MISO, PinName c=MBED_CONF_SD_SPI_CLK, PinName d=MBED_CONF_SD_SPI_CS):SDBlockDevice(a, b, c, d){
+    m_fs = new FATFileSystem("fs");
+  };
         	
   	FILE* openFile(string filename);
 	void closeFile(FILE* fileToClose);
@@ -33,5 +35,5 @@
 	void write_uint32_t(uint32_t data, bool endline, FILE* fileToUse);
 
 	// Define file system
-        FATFileSystem m_fs("fs");
+        FATFileSystem* m_fs;
 };