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

Pass by reference

parent 0d9e1e2b
...@@ -134,32 +134,36 @@ namespace csv_writer { ...@@ -134,32 +134,36 @@ 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) {
LedEffects::onBoardLEDOn();
File csv_file = openOrCreate();
char csv_line[42];
snprintf(csv_line, sizeof(csv_line), "%s;%d;%.1f;%.1f\r\n", timeStamp.c_str(), co2, temperature, humidity);
if (csv_file) {
size_t written_bytes = csv_file.print(csv_line);
csv_file.close();
if (written_bytes == 0) {
Serial.println(F("Nothing written. Disk full?"));
} else {
Serial.println(F("Wrote file content:"));
Serial.print(csv_line);
last_successful_write = ntp::getLocalTime();
}
updateFsInfo();
delay(50);
} else {
//NOTE: Can it ever happen that outfile is false?
Serial.println(F("Problem on create file!"));
}
LedEffects::onBoardLEDOff();
}
void logIfTimeHasCome(const String &timeStamp, const int16_t &co2, const float &temperature, const float &humidity) {
unsigned long now = seconds(); unsigned long now = seconds();
//TODO: Write average since last CSV write? //TODO: Write average since last CSV write?
if (now - last_written_at > config::csv_interval) { if (now - last_written_at > config::csv_interval) {
last_written_at = now; last_written_at = now;
LedEffects::onBoardLEDOn(); log(timeStamp, co2, temperature, humidity);
File csv_file = openOrCreate();
char csv_line[42];
snprintf(csv_line, sizeof(csv_line), "%s;%d;%.1f;%.1f\r\n", timeStamp.c_str(), co2, temp, hum);
if (csv_file) {
size_t written_bytes = csv_file.print(csv_line);
csv_file.close();
if (written_bytes == 0) {
Serial.println(F("Nothing written. Disk full?"));
} else {
Serial.println(F("Wrote file content:"));
Serial.print(csv_line);
last_successful_write = ntp::getLocalTime();
}
updateFsInfo();
delay(50);
} else {
//NOTE: Can it ever happen that outfile is false?
Serial.println(F("Problem on create file!"));
}
LedEffects::onBoardLEDOff();
} }
} }
} }
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
#include "led_effects.h" #include "led_effects.h"
#include "config.h" #include "config.h"
namespace config { namespace config {
extern uint16_t csv_interval; // [s] extern uint16_t csv_interval; // [s]
} }
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