#include "csvs.h"
uint32_t stamp = 1745107200;
uint16_t newline = 1;
float avg = 0.0;
bool begin = true;
char buff [4092];
char output [4092];
void processFile(const char * fileName) {
//Serial.println("Processing File...");
char * fpn;
char thisline [32];
uint32_t count = 0;
uint16_t line = 0;
float linef = 0.0;
float carryf = 0.0;
uint32_t timeset = 0;
strcpy(buff, fileName);
fpn = strtok (buff, ",\n");
while (fpn != NULL)
{
if (count > 1 && count % 2 == 1) {
if (begin) {
sprintf(output, "0 time,temp\n1 %lu000,%s\n", stamp, fpn);
begin = false;
}
avg += atof(fpn);
if (++line % 6 == 0) {
stamp += 3600;
carryf = avg / 6.0;
newline ++;
sprintf(thisline, "%d %lu000,%.2f\n", newline, stamp, carryf);
strcat(output, thisline);
thisline[0] = 0;
avg = 0.0;
}
}
count++;
fpn = strtok (NULL, ",\n");
}
buff[0] = '\0';
//output[0] = 0;
}
void setup() {
Serial.begin(115200);
Serial.println("Hello, ESP32!");
uint32_t timeset = millis();
processFile(CSV_FILE0);
processFile(CSV_FILE1);
processFile(CSV_FILE2);
processFile(CSV_FILE3);
processFile(CSV_FILE4);
processFile(CSV_FILE5);
processFile(CSV_FILE6);
Serial.print(output);
Serial.print("Lines = ");
Serial.println(newline);
Serial.println("Should be 169 Lines");
printf("Done in %lu ms",millis() - timeset);
}
void loop() {
delay(10); // this speeds up the simulation
}