A set of data recording functions to locally store data in a circular buffer, with functions for offloading to an SD Card when convenient. dataRecorderr.h shows accessible functions to the main program - all direct SD operations are abstracted away by the library. When using this library, #include dataRecorder.h
Dependencies: sd-driver_compatible_with_MAX32630FTHR
Fork of CircularBufferSDCardLib by
Diff: dataRecorder.cpp
- Revision:
- 0:ebe71c7e7854
- Child:
- 1:45627bbdeb69
diff -r 000000000000 -r ebe71c7e7854 dataRecorder.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dataRecorder.cpp Tue Apr 03 21:50:25 2018 +0000 @@ -0,0 +1,103 @@ + +#include "dataRecorder.h" + +DataRecorder::DataRecorder(){ + uint32_t bytes_written = 0; + blockDistance_Index = 0; + //uint8_t separator = ' '; +}; + + +//private buffer load in method +void DataRecorder::pushEleToBuffer(uint16_t inputVal){ + buf_distance.push(inputVal); + // while (!buf.full()) { + // buf.push(inputVal); + // } + +} + +uint8_t* DataRecorder::getDistanceBlock(){ + return blockDistance; +} + +int DataRecorder::getDistanceDataLength(){ + return blockDistance_Index; +}; + + +//writes input value to buffer +void DataRecorder::LogDistancePoint(uint16_t value){ + buf_distance.push(value); + savePoint(value); +} + +void DataRecorder::savePoint(uint16_t value){ + string yo = SSTR(value); + int n = yo.length(); + // declaring character array + char char_array[n+1]; + + // copying the contents of the + // string to char array + strcpy(char_array, yo.c_str()); + + + int counter = 0; + + for (int i=blockDistance_Index; i<blockDistance_Index+n; i++){ + blockDistance[i] = char_array[counter]; + //printf("%i\n",i); + //printf("%c\n",blockDistance[i]); + counter++; + } + + blockDistance_Index = blockDistance_Index+n; + + //add separator + blockDistance[blockDistance_Index] = ' '; + blockDistance_Index++; + + //buf.push(char_array[i]); + //buf_distance +} + + +//saves buffer to sd card and clears it +int WriteDataAndClearBuffer(); + + + + + +/* + + uint32_t bytes_written = 0; + + while (!buf.full()) { + buf.push(data_stream[bytes_written++]); + } + + printf("Circular buffer is full: \"%s\" or empty: \"%s\" \n", + (buf.full()? "true":"false"), + (buf.empty()? "true":"false") ); + printf ("Bytes written %d \n", bytes_written); + + // If buffer is full, contents will be over-written + buf.push(data_stream[bytes_written++]); + + char data; + printf ("Buffer contents: "); + while (!buf.empty()) { + buf.pop(data); + printf("%c", data); + } + printf("\n"); + + printf("Circular buffer is full: \"%s\" or empty: \"%s\" \n", + (buf.full()? "true":"false"), + (buf.empty()? "true":"false") ); + + return 0; + + */ \ No newline at end of file