added some improved classes from my custom backend and introduced DAOs
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
const uint32_t DEVICE_ID = getChipID();
|
||||
const char ALL_VEHICLES[] = "Todo tipo de vehiculos";
|
||||
const char ELECTRIC_VEHICLES[] = "Solo vehiculos electricos/hibridos";
|
||||
const char* currentMessage = nullptr;
|
||||
const char *currentMessage = nullptr;
|
||||
|
||||
TaskTimer matrixTimer{0, 25};
|
||||
TaskTimer globalTimer{0, 60000};
|
||||
@@ -29,7 +29,7 @@ void setup()
|
||||
GPS_Init();
|
||||
Serial.println("Sensor GPS inicializado");
|
||||
MQ7_Init();
|
||||
Serial.println("Sensor MQ7 inicializado");
|
||||
Serial.println("Sensor MQ7 inicializado");
|
||||
MAX7219_Init();
|
||||
Serial.println("Display inicializado");
|
||||
|
||||
@@ -40,8 +40,10 @@ void loop()
|
||||
{
|
||||
uint32_t now = millis();
|
||||
|
||||
if (now - matrixTimer.lastRun >= matrixTimer.interval) {
|
||||
if (MAX7219_Animate()) {
|
||||
if (now - matrixTimer.lastRun >= matrixTimer.interval)
|
||||
{
|
||||
if (MAX7219_Animate())
|
||||
{
|
||||
MAX7219_ResetAnimation();
|
||||
}
|
||||
matrixTimer.lastRun = now;
|
||||
@@ -52,10 +54,10 @@ void loop()
|
||||
readBME280();
|
||||
readGPS();
|
||||
readMQ7();
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#ifdef DEBUG
|
||||
printAllData();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
globalTimer.lastRun = now;
|
||||
}
|
||||
@@ -69,11 +71,15 @@ void readMQ7()
|
||||
|
||||
AirQualityStatus newStatus = (mq7Data.co >= CO_THRESHOLD) ? BAD : GOOD;
|
||||
|
||||
if (newStatus != currentAirStatus) {
|
||||
if (newStatus != currentAirStatus)
|
||||
{
|
||||
currentAirStatus = newStatus;
|
||||
if (currentAirStatus == BAD) {
|
||||
if (currentAirStatus == BAD)
|
||||
{
|
||||
writeMatrix(ELECTRIC_VEHICLES);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
writeMatrix(ALL_VEHICLES);
|
||||
}
|
||||
}
|
||||
@@ -89,15 +95,16 @@ void readGPS()
|
||||
gpsData = GPS_Read();
|
||||
}
|
||||
|
||||
void writeMatrix(const char* message)
|
||||
void writeMatrix(const char *message)
|
||||
{
|
||||
if (currentMessage == message) return;
|
||||
if (currentMessage == message)
|
||||
return;
|
||||
currentMessage = message;
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
Serial.println("Escribiendo en el display...");
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
MAX7219_DisplayText(message, PA_LEFT, 50, 0);
|
||||
}
|
||||
|
||||
@@ -105,17 +112,28 @@ void printAllData()
|
||||
{
|
||||
Serial.println("---------------------");
|
||||
|
||||
Serial.print("ID: "); Serial.println(DEVICE_ID, HEX);
|
||||
Serial.print("ID: ");
|
||||
Serial.println(DEVICE_ID, HEX);
|
||||
|
||||
Serial.print("Presión: "); Serial.print(bme280Data.pressure / 100); Serial.println(" hPa");
|
||||
Serial.print("Temperatura: "); Serial.print(bme280Data.temperature); Serial.println(" °C");
|
||||
Serial.print("Humedad: "); Serial.print(bme280Data.humidity); Serial.println(" %");
|
||||
Serial.print("Presión: ");
|
||||
Serial.print(bme280Data.pressure / 100);
|
||||
Serial.println(" hPa");
|
||||
Serial.print("Temperatura: ");
|
||||
Serial.print(bme280Data.temperature);
|
||||
Serial.println(" °C");
|
||||
Serial.print("Humedad: ");
|
||||
Serial.print(bme280Data.humidity);
|
||||
Serial.println(" %");
|
||||
|
||||
Serial.print("Latitud: "); Serial.println(gpsData.lat);
|
||||
Serial.print("Longitud: "); Serial.println(gpsData.lon);
|
||||
Serial.print("Latitud: ");
|
||||
Serial.println(gpsData.lat);
|
||||
Serial.print("Longitud: ");
|
||||
Serial.println(gpsData.lon);
|
||||
|
||||
Serial.print("CO: "); Serial.println(mq7Data.co);
|
||||
Serial.print("D0: "); Serial.println(mq7Data.threshold);
|
||||
Serial.print("CO: ");
|
||||
Serial.println(mq7Data.co);
|
||||
Serial.print("D0: ");
|
||||
Serial.println(mq7Data.threshold);
|
||||
}
|
||||
|
||||
uint32_t getChipID()
|
||||
@@ -125,8 +143,9 @@ uint32_t getChipID()
|
||||
{
|
||||
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
Serial.print("Chip ID: "); Serial.println(chipId, HEX);
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
Serial.print("Chip ID: ");
|
||||
Serial.println(chipId, HEX);
|
||||
#endif
|
||||
return chipId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user