diff --git a/G26-Telemetria.ino b/G26-Telemetria.ino index 23bde5a..4ddb9ae 100644 --- a/G26-Telemetria.ino +++ b/G26-Telemetria.ino @@ -6,9 +6,15 @@ #include "include/data_processor.hpp" -// --- CONFIGURACIÓN SD (VSPI) --- -#define SD_CS_PIN 5 -#define SPI_CLOCK SD_SCK_MHZ(20) +// --- CONFIGURACIÓN SD (HSPI, pines de la PCB validados por esquemático) --- +#define SD_CS 25 +#define SD_MOSI 26 +#define SD_SCK 27 +#define SD_MISO 14 + +SPIClass spiSD(HSPI); +#define SD_CONFIG SdSpiConfig(SD_CS, DEDICATED_SPI, SD_SCK_MHZ(1), &spiSD) + SdFat sd; SdFile logFile; @@ -22,38 +28,44 @@ void setup() { Serial.println("\n--- G26 TELEMETRY: INICIO DE SISTEMA ---"); // 1. INICIALIZACIÓN SD - if (!sd.begin(SD_CS_PIN, SPI_CLOCK)) { + spiSD.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS); + + if (!sd.begin(SD_CONFIG)) { Serial.println("[FALLO] SD no detectada. El sistema continuará sin Datalogging."); } else { - if (logFile.open("G26.csv", O_RDWR | O_CREAT | O_APPEND)) { + char filename[24]; + int session = 1; + bool opened = false; - // Si el archivo es nuevo (tamaño 0), escribimos la cabecera - if (logFile.fileSize() == 0) { - logFile.println("Time,ECT"); - logFile.sync(); + while (!opened && session < 100000) { + snprintf(filename, sizeof(filename), "G26-%d.csv", session); + if (logFile.open(filename, O_RDWR | O_CREAT | O_EXCL)) { + opened = true; + Serial.printf("[OK] Nueva sesion: %s\n", filename); + } else { + session++; + } } - // El archivo se queda abierto y listo. - Serial.println("[OK] Archivo abierto"); - - } else { - Serial.println("[ERROR] No se pudo abrir el archivo G26.csv"); - } + if (opened) { + logFile.println("Time,ECT,RPM,TPS,VBATT"); + logFile.sync(); + } else { + Serial.println("[ERROR] No se pudo abrir archivo de sesion"); + } } // 2. VINCULACIÓN - // Le damos al procesador acceso a la SD para que guarde cuando lleguen datos processor.setLogSystem(&sd, &logFile); can_interface.set_data_proccessor(&processor); // 3. INICIO CAN can_interface.start(); - can_interface.start_listening_task(); // Escucha en Core 1 (Background) - + can_interface.start_listening_task(); + Serial.println("[OK] Sistema ONLINE."); } void loop() { - - delay(100); -} + delay(100); +} \ No newline at end of file diff --git a/include/can.hpp b/include/can.hpp index 7a03905..94467b2 100644 --- a/include/can.hpp +++ b/include/can.hpp @@ -1,8 +1,8 @@ #ifndef CAN_HPP #define CAN_HPP -#define RX_PIN 13 -#define TX_PIN 38 +#define RX_PIN 23 +#define TX_PIN 22 #define POLLING_RATE_MS 1000 #define TRANSMIT_RATE_MS 1000 diff --git a/include/data_processor.hpp b/include/data_processor.hpp index 33b4992..f5c05d3 100644 --- a/include/data_processor.hpp +++ b/include/data_processor.hpp @@ -9,7 +9,11 @@ public: // Estructura de datos struct CarState { - int ect = 0; // Temperatura (IMPORTANTE POR AHORA). Luego habría que añadir aquí todas las variables que se vallan a guardar. + int ect = 0; + int rpm = 0; + int tps = 0; + double vbatt = 0; + }; // Configuración SD diff --git a/index.html b/index.html deleted file mode 100644 index 886c04d..0000000 --- a/index.html +++ /dev/null @@ -1,254 +0,0 @@ - - -
- -