Commit 2e99fa40 authored by Eric Duminil's avatar Eric Duminil
Browse files

Pass by reference

parent 0d9e1e2b
...@@ -134,15 +134,11 @@ namespace csv_writer { ...@@ -134,15 +134,11 @@ namespace csv_writer {
return csv_file; return csv_file;
} }
void logIfTimeHasCome(const String &timeStamp, int16_t co2, float temp, float hum) { void log(const String &timeStamp, const int16_t &co2, const float &temperature, const float &humidity) {
unsigned long now = seconds();
//TODO: Write average since last CSV write?
if (now - last_written_at > config::csv_interval) {
last_written_at = now;
LedEffects::onBoardLEDOn(); LedEffects::onBoardLEDOn();
File csv_file = openOrCreate(); File csv_file = openOrCreate();
char csv_line[42]; char csv_line[42];
snprintf(csv_line, sizeof(csv_line), "%s;%d;%.1f;%.1f\r\n", timeStamp.c_str(), co2, temp, hum); snprintf(csv_line, sizeof(csv_line), "%s;%d;%.1f;%.1f\r\n", timeStamp.c_str(), co2, temperature, humidity);
if (csv_file) { if (csv_file) {
size_t written_bytes = csv_file.print(csv_line); size_t written_bytes = csv_file.print(csv_line);
csv_file.close(); csv_file.close();
...@@ -161,5 +157,13 @@ namespace csv_writer { ...@@ -161,5 +157,13 @@ namespace csv_writer {
} }
LedEffects::onBoardLEDOff(); LedEffects::onBoardLEDOff();
} }
void logIfTimeHasCome(const String &timeStamp, const int16_t &co2, const float &temperature, const float &humidity) {
unsigned long now = seconds();
//TODO: Write average since last CSV write?
if (now - last_written_at > config::csv_interval) {
last_written_at = now;
log(timeStamp, co2, temperature, humidity);
}
} }
} }
...@@ -19,7 +19,7 @@ namespace config { ...@@ -19,7 +19,7 @@ namespace config {
namespace csv_writer { namespace csv_writer {
extern String last_successful_write; extern String last_successful_write;
void initialize(); void initialize();
void logIfTimeHasCome(const String &timeStamp, int16_t co2, float temp, float hum); void logIfTimeHasCome(const String &timeStamp, const int16_t &co2, const float &temperature, const float &humidity);
int getAvailableSpace(); int getAvailableSpace();
extern const String filename; extern const String filename;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment