|
|
@@ -67,6 +67,7 @@ SemaphoreHandle_t dataMutex; // Mutex para proteger el acceso a latestData
|
|
|
SemaphoreHandle_t buttonSemaphore; // Semáforo para la tarea del botón
|
|
|
|
|
|
bool grabando = false; //inicia apagado
|
|
|
+bool finalizado = true; //indica que no hay ninguna grabacion ni iniciada ni pausada
|
|
|
TaskHandle_t medicionesHandle = NULL; //para suspend/resume
|
|
|
int pantallaEstado_grab = -1; //maquina de estados cuando se graba ruta
|
|
|
int pantallaEstado_menu = -1; //maquina de estados cuando no se esta grabando ruta
|
|
|
@@ -240,6 +241,20 @@ void crear_archivo(){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void cerrar_archivo() {
|
|
|
+ File file = SD.open(filename, FILE_APPEND);
|
|
|
+ if (file){
|
|
|
+ file.print('\t\t</trkseg>\n\t</trk>\n</gpx>');
|
|
|
+ file.close();
|
|
|
+ }
|
|
|
+ int num = 1;
|
|
|
+ sprintf(filename, "/data%03d.gpx", num);
|
|
|
+ while (SD.exists(filename)) {
|
|
|
+ num++;
|
|
|
+ sprintf(filename, "/data%03d.gpx", num);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void IRAM_ATTR isr_button() {
|
|
|
unsigned long now = millis();
|
|
|
if (now < ignore_isr_until) {
|
|
|
@@ -296,7 +311,7 @@ void task_ui(void *pvParameters){
|
|
|
drawProgressBar(0, SCREEN_HEIGHT - 10, SCREEN_WIDTH, 8, checkTime - pressTime, PULASCION_LARGA_MS);
|
|
|
}
|
|
|
|
|
|
- ignore_isr_until = millis() + 50; //ignorar nuevas interrupciones durante 500 ms
|
|
|
+ ignore_isr_until = millis() + 500; //ignorar nuevas interrupciones durante 500 ms
|
|
|
|
|
|
unsigned long duration = checkTime - pressTime;
|
|
|
|
|
|
@@ -342,17 +357,23 @@ void task_ui(void *pvParameters){
|
|
|
//activar la ruta y crear el archivo
|
|
|
crear_archivo();
|
|
|
vTaskResume(medicionesHandle);
|
|
|
+ OLED_print("Ruta","iniciada");
|
|
|
+ finalizado = false;
|
|
|
break;
|
|
|
case 1:
|
|
|
//cerrar el archivo y cambiar el valor de 'filename'
|
|
|
+ cerrar_archivo();
|
|
|
+ finalizado = true;
|
|
|
+ break;
|
|
|
case 2:
|
|
|
//implementacion blutuch
|
|
|
+ break;
|
|
|
}
|
|
|
} else {
|
|
|
pantallaEstado_menu = (pantallaEstado_menu + 1) % 3;
|
|
|
switch (pantallaEstado_menu){
|
|
|
case 0:
|
|
|
- if (SD.exists(filename)) OLED_print("Reanudar","ruta");
|
|
|
+ if (!finalizado) OLED_print("Reanudar","ruta");
|
|
|
else OLED_print("Iniciar","ruta");
|
|
|
break;
|
|
|
case 1:
|
|
|
@@ -362,101 +383,14 @@ void task_ui(void *pvParameters){
|
|
|
}
|
|
|
pantallaEstado_menu += 1;
|
|
|
case 2:
|
|
|
- if (!SD.exists(filename)) {
|
|
|
+ if (finalizado) {
|
|
|
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
|
|
|
- if (grabando){
|
|
|
- vTaskResume(medicionesHandle);
|
|
|
- //Mostrar que empieza la grabación
|
|
|
- OLED_print("Ruta","iniciada");
|
|
|
- } else {
|
|
|
- vTaskSuspend(medicionesHandle);
|
|
|
- //Mostrar que se pausa/finaliza la grabación
|
|
|
- OLED_print("Ruta","pausada");
|
|
|
- }
|
|
|
- } else {
|
|
|
- //Pulsacion corta + grabando datos, cicla datos
|
|
|
- if (grabando) {
|
|
|
- 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 {
|
|
|
- pantallaEstado_menu = (pantallaEstado_menu + 1) % 3;
|
|
|
- OLED_print("Ruta","pausada");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ }
|
|
|
}
|
|
|
lastActivity = millis(); //reset watchdog
|
|
|
processingButton = false;
|
|
|
@@ -472,8 +406,6 @@ void task_ui(void *pvParameters){
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
- Serial.begin(115200);
|
|
|
-
|
|
|
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
|
|
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), isr_button, FALLING);
|
|
|
|