浏览代码

falta terminar de programar la ui cuando no esta grabando datos

dacowars 1 月之前
父节点
当前提交
5b569e9027
共有 1 个文件被更改,包括 130 次插入25 次删除
  1. 130 25
      main/main.ino

+ 130 - 25
main/main.ino

@@ -68,8 +68,8 @@ SemaphoreHandle_t buttonSemaphore; // Semáforo para la tarea del botón
 
 bool grabando = false; //inicia apagado
 TaskHandle_t medicionesHandle = NULL; //para suspend/resume
-int pantallaEstado_grab = 0; //maquina de estados cuando se graba ruta
-int pantallaEstado_menu = 0; //maquina de estados cuando no se esta grabando ruta
+int pantallaEstado_grab = -1; //maquina de estados cuando se graba ruta
+int pantallaEstado_menu = -1; //maquina de estados cuando no se esta grabando ruta
 float distancia_total = 0.0;
 volatile unsigned long ignore_isr_until = 0; //para debounce
 
@@ -121,17 +121,14 @@ void OLED_test() {  //pantallazo a blanco y luego iniciando
 
 void SD_test(){
 if (!SD.begin()) {
-    Serial.println("SD Card Mount Failed");
     OLED_print("SD Card", "Error\nInserte");
     while (!SD.begin());
     OLED_print("SD Card", "Insertada");
   } else {
     OLED_print("SD Card", "Correcto");
-    Serial.println("SD Card initialized.");
   }
   uint8_t cardType = SD.cardType();
   if (cardType == CARD_NONE) {
-    Serial.println("No SD card attached");
     OLED_print("SD Card", "No detectada");
     while (cardType == CARD_NONE) {
       delay(1000);
@@ -140,25 +137,6 @@ if (!SD.begin()) {
     OLED_print("SD Card", "Detectada");
   }
   uint8_t cardSize = SD.cardSize() / (1024 * 1024);
-  Serial.printf("SD Card Size: %uMB\n", cardSize);
-
-  int num = 1;
-  sprintf(filename, "/data%03d.xml", num);
-  while (SD.exists(filename)) {
-    num++;
-    sprintf(filename, "/data%03d.xml", num);
-  }
-
-  File file = SD.open(filename, FILE_WRITE);
-  if (file) {
-    file.println('<?xml version="1.0" encoding="UTF-8"?>\n<gpx creator="ESP32 GPS LOGGER" version="1.1"\n\txmlns="http://www.topografix.com/GPX/1/1"\n\t
-      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n\txmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v2"\n\t
-      xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0"\n\txsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">\n\t<trk>\n\t\t
-      <name>Rutita</name>\n\t\t<type>hiking</type>\n\t\t<trkseg>');
-    file.close();
-  } else {
-    OLED_print("Error","creando archivo");
-  }
 }
 
 void GPS_test_wait() {
@@ -201,7 +179,7 @@ void task_mediciones(void *pvParameters) {
     String new_fecha = String(gps.date.year())+"-"+String(gps.date.month())+"-"+
                    String(gps.date.day())+"T"+String(gps.time.hour())+":"+
                    String(gps.time.minute())+":"+String(gps.time.second())+"."+
-                   String(gps.time.centisecond())
+                   String(gps.time.centisecond());
     float new_temp = dht.readTemperature();
     float new_hum = dht.readHumidity();
     float new_press = 0.0; // Placeholder, no hay sensor de presión 
@@ -242,6 +220,26 @@ void task_mediciones(void *pvParameters) {
   }
 }
 
+void crear_archivo(){
+  int num = 1;
+  sprintf(filename, "/data%03d.gpx", num);
+  while (SD.exists(filename)) {
+    num++;
+    sprintf(filename, "/data%03d.gpx", num);
+  }
+
+  File file = SD.open(filename, FILE_WRITE);
+  if (file) {
+    file.println('<?xml version="1.0" encoding="UTF-8"?>\n<gpx creator="ESP32 GPS LOGGER" version="1.1"\n\txmlns="http://www.topografix.com/GPX/1/1"\n\t
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n\txmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v2"\n\t
+      xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0"\n\txsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">\n\t<trk>\n\t\t
+      <name>Rutita</name>\n\t\t<type>hiking</type>\n\t\t<trkseg>');
+    file.close();
+  } else {
+    OLED_print("Error","creando archivo");
+  }
+}
+
 void IRAM_ATTR isr_button() {
   unsigned long now = millis();
   if (now < ignore_isr_until) {
@@ -307,6 +305,113 @@ void task_ui(void *pvParameters){
         display.ssd1306_command(SSD1306_DISPLAYOFF); //se apaga la
         pantallaOn = false;
       } else {
+        if (grabando){
+          if (duration >= PULASCION_LARGA_MS){
+            grabando = false;
+            vTaskSuspend(medicionesHandle);
+            OLED_print("Ruta","pausada");
+          } else {
+            pantallaEstado_grab = (pantallaEstado_grab + 1) % 5; //cicla entre 0-4
+            SensorData currentData;
+            if(xSemaphoreTake(dataMutex, portMAX_DELAY) == pdTRUE){
+              currentData = latestData;
+              xSemaphoreGive(dataMutex);
+            }
+            switch (pantallaEstado_grab){
+              case 0:
+                OLED_print("Posicion",String(currentData.longitude) + "," + String(currentData.latitude));
+                break;
+              case 1:
+                OLED_print("Distancia",String(distancia_total)+"km");
+                break;
+              case 2:
+                OLED_print("Altitud",String(gps.altitude.meters(), 1)+"m");
+                break;
+              case 3:
+                OLED_print("Temp/Hum",String(currentData.temperature,1)+"C/"+String(currentData.humidity,1)+"%");
+                break;  
+              case 4:
+                OLED_print("Velocidad",String(gps.speed.kmph())+"km/h");
+                break;
+            }
+          }
+        } else {
+          if (duration >= PULASCION_LARGA_MS){
+            switch (pantallaEstado_menu){
+              case 0:
+                //activar la ruta y crear el archivo
+                crear_archivo();
+                vTaskResume(medicionesHandle);
+                break;
+              case 1:
+                //cerrar el archivo y cambiar el valor de 'filename'
+              case 2:
+                //implementacion blutuch
+            }
+          } else {
+            pantallaEstado_menu = (pantallaEstado_menu + 1) % 3;
+            switch (pantallaEstado_menu){
+              case 0:
+                if (SD.exists(filename)) OLED_print("Reanudar","ruta");
+                else OLED_print("Iniciar","ruta");
+                break;
+              case 1:
+                if (SD.exists(filename)) {
+                  OLED_print("Finalizar","ruta");
+                  break;
+                }
+                pantallaEstado_menu += 1;
+              case 2:
+                if (!SD.exists(filename)) { 
+                  OLED_print("Conexion","blutuch 'WIP'");
+                  break;
+                }
+                pantallaEstado_menu += 1;
+            }
+          }
+        }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
         if (duration >= PULASCION_LARGA_MS){
           //pulsacion larga: cabia entre grabacion y no grabacion de datos
           grabando = grabando ? false : true; //toggle