Skip to content

Commit

Permalink
Added CS pin parameter to the constructor and changed the SD card flu…
Browse files Browse the repository at this point in the history
…sh interval to 512 bytes since the buffer for the SD library is 512 bytes
  • Loading branch information
infomaniac50 committed Mar 12, 2012
1 parent 53a20b0 commit 2f8f2fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
28 changes: 13 additions & 15 deletions Logger.cpp
Expand Up @@ -7,11 +7,9 @@
#include "Logger.h"
#include <LoggerSD.h>

#define CS 4


Logger::Logger(log_outputs output, data_formats format, boolean add_line_break)
Logger::Logger(log_outputs output, data_formats format, boolean add_line_break, uint chip_select)
{
_chip_select = chip_select;
_output = output;
_format = format;
_add_line_break = add_line_break;
Expand Down Expand Up @@ -44,7 +42,7 @@ int Logger::initSD()
pinMode(10, OUTPUT);
#endif

if (!SD.begin(CS)) {
if (!SD.begin(_chip_select)) {
return 1;
}

Expand Down Expand Up @@ -160,19 +158,19 @@ void Logger::logData(byte data)

checkAddLineBreak();

if (_output == SERIAL_OUTPUT)
{
Serial.flush();
}

if (_output == SD_OUTPUT)
sync_counter++;
if (sync_counter >= 512)
{
sync_counter++;
if (sync_counter >= 2048)
if (_output == SD_OUTPUT)
{
_file.flush();
sync_counter = 0;
_file.flush();
}

if (_output == SERIAL_OUTPUT)
{
Serial.flush();
}
sync_counter = 0;
}
}

Expand Down
1 change: 1 addition & 0 deletions Logger.h
Expand Up @@ -48,5 +48,6 @@ class Logger
log_outputs _output;
data_formats _format;
boolean _add_line_break;
uint _chip_select;
};
#endif

0 comments on commit 2f8f2fd

Please sign in to comment.