External memory log
Diff: MemLog.cpp
- Revision:
- 0:b631881feed3
diff -r 000000000000 -r b631881feed3 MemLog.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MemLog.cpp Mon May 30 08:10:08 2016 +0000 @@ -0,0 +1,39 @@ +/* Log system for internal memory flash +* Copyright (c) 2013 Oleg Evsegneev +* Released under the MIT License: http://mbed.org/license/mit +*/ + +#include "mbed.h" +#include "MemLog.h" + +MemLog::MemLog( short cols, short rows ): _local("local") { + _cols = cols; + _rows = rows; + _addr = 0; + _row = 0; +} + +void MemLog::log( float val ) { + if( _addr >= _rows*_cols ) + return; // can't write + _data[_addr++] = val; + if( ( _addr % _cols) == 0 ) + _row++; +} + +void MemLog::save() { + FILE *fp = fopen(LOG_FILE, "w"); + unsigned short addr = 0; + + for( short i=0; i<_row; i++){ + for( short k=0; k<_cols; k++){ + fprintf( fp, "%.4f", _data[addr++]); + if( k < _cols-1 ) + fprintf( fp, "\t"); + } + fprintf( fp, "\r\n"); + } + fclose(fp); + _addr = 0; + _row = 0; +}