Created firmware main
This commit is contained in:
92
src/main.cpp
Normal file
92
src/main.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <AsyncTCP.h>
|
||||
#include "logger.cpp"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <SPIFFS.h>
|
||||
#include "esp32-hal-cpu.h"
|
||||
//#include <DNSServer.h>
|
||||
|
||||
#include "header.hpp"
|
||||
#include "Helpers.hpp"
|
||||
#include "Config.hpp"
|
||||
#include "ESP32_WIFI.hpp"
|
||||
#include "Server.hpp"
|
||||
|
||||
#include "ChronoAPI.hpp"
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Leer valor de tiempo. Solicitarle 4 bytes dedatos al detector
|
||||
if (!sendLock)
|
||||
{
|
||||
sendLock = true;
|
||||
|
||||
Wire.requestFrom(0x26, (int)sizeof(long));
|
||||
int b = 0;
|
||||
while (Wire.available())
|
||||
{
|
||||
ChronoMillisecondsBuffer.buffer[b] = Wire.read();
|
||||
b++;
|
||||
}
|
||||
|
||||
sendLock = false;
|
||||
|
||||
if (lastMs == ChronoMillisecondsBuffer.data)
|
||||
{
|
||||
if (!logged)
|
||||
{
|
||||
Logger::Log(Logger::DEBUG, "Mesaure finished: " + String(ChronoMillisecondsBuffer.data) + " ms");
|
||||
}
|
||||
logged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
logged = false;
|
||||
}
|
||||
lastMs = ChronoMillisecondsBuffer.data;
|
||||
}else{
|
||||
Logger::Log("Send is disabled"); // Indicar en el log fin del setup
|
||||
}
|
||||
|
||||
delay(20);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Logger::MinLevel = Logger::TRACE;
|
||||
// Iniciar puerto serie para depuración
|
||||
Serial.begin(115200);
|
||||
delay(500);
|
||||
// Configurar la frecuencia de la CPU
|
||||
setCpuFrequencyMhz(240);
|
||||
Logger::Log("Iniciando...");
|
||||
Logger::Log("Iniciando bus I2C");
|
||||
if (!Wire.begin(22, 23, 1)) // Iniciar bus I2C
|
||||
{
|
||||
Logger::Log(Logger::ERROR, "No se inició el bus I2C.");
|
||||
while (true)
|
||||
;
|
||||
}
|
||||
Logger::Log("Iniciando SPIFFS");
|
||||
lastSendWS = 0;
|
||||
if (!SPIFFS.begin()) // Iniciar SPIFFS (Sistema de archivos), o detenerse con error
|
||||
{
|
||||
Logger::Log(Logger::ERROR, "No se inició SPIFS.");
|
||||
while (true)
|
||||
;
|
||||
}
|
||||
|
||||
Config::Read(); // Leer o crear una nueva configuración
|
||||
Config::Save(); // Guardar la Configuración
|
||||
WiFi.disconnect(true); // Configuracion del punto de acceso WIFI
|
||||
delay(1000); // Pausar un segundo
|
||||
WiFi.onEvent(WiFiStationDisconnected, SYSTEM_EVENT_STA_DISCONNECTED);
|
||||
configWiFi(); // Configurar wifi
|
||||
InitServer(); // Levantar servidor
|
||||
ConfigureAPI();
|
||||
Logger::Log("Info: Setup completado"); // Indicar en el log fin del setup
|
||||
}
|
||||
Reference in New Issue
Block a user