tdse-tf_3-02

Controlador PID para derretidor de miel con control local via botones y remoto via WiFi
Index Commits Files Refs Submodules README
commit 15fd6ac7bd51adaed67332721d16f2526b3d71e0
parent a55880d4e8e884777883fb60972f15868ed9dc6f
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Sun, 12 Apr 2026 16:51:44 -0300

Agregar nueva tarea `task_remote`

Diffstat:
Afirmware-nucleo/app/inc/task_remote.h | 24++++++++++++++++++++++++
Mfirmware-nucleo/app/src/app.c | 24++++++++++++++----------
Afirmware-nucleo/app/src/task_remote.c | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 111 insertions(+), 10 deletions(-)
diff --git a/firmware-nucleo/app/inc/task_remote.h b/firmware-nucleo/app/inc/task_remote.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
+ *
+ * See file `LICENSE` for full details
+ */
+
+#ifndef TASK_INC_TASK_REMOTE_H_
+#define TASK_INC_TASK_REMOTE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern uint32_t g_task_remote_cnt;
+extern volatile uint32_t g_task_remote_tick_cnt;
+
+void task_remote_init(void *parameters);
+void task_remote_update(void *parameters);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TASK_INC_TASK_REMOTE_H_ */
diff --git a/firmware-nucleo/app/src/app.c b/firmware-nucleo/app/src/app.c
@@ -18,6 +18,7 @@
 #include "task_menu.h"
 #include "task_temp_ctrl.h"
 #include "task_temp_sensor.h"
+#include "task_remote.h"
 
 #define G_APP_CNT_INI       0ul
 #define G_APP_TICK_CNT_INI  0ul
@@ -53,6 +54,7 @@ const task_cfg_t task_cfg_list[] = {
     {task_menu_init,        task_menu_update,        &shared_data},
     {task_temp_ctrl_init,   task_temp_ctrl_update,   &shared_data},
     {task_temp_sensor_init, task_temp_sensor_update, &shared_data},
+    {task_remote_init,      task_remote_update,      &shared_data},
 };
 
 #define TASK_QTY (sizeof(task_cfg_list)/sizeof(task_cfg_t))
@@ -67,11 +69,11 @@ void app_init(void)
 
     shared_data_type *p_shared_data = &shared_data;
 
-    p_shared_data->temp_set_point = 0;
-    p_shared_data->temp_sensor = -20;
-    p_shared_data->temp_ctrl_pwm_dc = 0;
+    p_shared_data->temp_set_point    = 0;
+    p_shared_data->temp_sensor       = -20;
+    p_shared_data->temp_ctrl_pwm_dc  = 0;
     p_shared_data->temp_ctrl_enabled = false;
-    p_shared_data->timer = NULL;
+    p_shared_data->timer             = NULL;
 
     for (uint32_t index = 0; TASK_QTY > index; index++)
     {
@@ -80,13 +82,14 @@ void app_init(void)
     }
 
     __asm("CPSID i");
-    g_app_tick_cnt = G_APP_TICK_CNT_INI;
-    g_task_system_tick_cnt = G_APP_TICK_CNT_INI;
-    g_task_buttons_tick_cnt = G_APP_TICK_CNT_INI;
-    g_task_leds_tick_cnt = G_APP_TICK_CNT_INI;
-    g_task_menu_tick_cnt = G_APP_TICK_CNT_INI;
-    g_task_temp_ctrl_tick_cnt = G_APP_TICK_CNT_INI;
+    g_app_tick_cnt              = G_APP_TICK_CNT_INI;
+    g_task_system_tick_cnt      = G_APP_TICK_CNT_INI;
+    g_task_buttons_tick_cnt     = G_APP_TICK_CNT_INI;
+    g_task_leds_tick_cnt        = G_APP_TICK_CNT_INI;
+    g_task_menu_tick_cnt        = G_APP_TICK_CNT_INI;
+    g_task_temp_ctrl_tick_cnt   = G_APP_TICK_CNT_INI;
     g_task_temp_sensor_tick_cnt = G_APP_TICK_CNT_INI;
+    g_task_remote_tick_cnt      = G_APP_TICK_CNT_INI;
     __asm("CPSIE i");
 
     LOGGER_INFO("Done initializing `app`");
@@ -172,4 +175,5 @@ void HAL_SYSTICK_Callback(void)
     g_task_menu_tick_cnt++;
     g_task_temp_ctrl_tick_cnt++;
     g_task_temp_sensor_tick_cnt++;
+    g_task_remote_tick_cnt++;
 }
diff --git a/firmware-nucleo/app/src/task_remote.c b/firmware-nucleo/app/src/task_remote.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
+ *
+ * See file `LICENSE` for full details
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include "main.h"
+#include "app.h"
+
+#include "task_remote.h"
+#include "logger.h"
+
+#define G_TASK_REMOTE_TICK_INI            0ul
+#define G_TASK_REMOTE_TEMP_UPDATE_RATE_MS 1000ul
+
+uint32_t g_task_remote_tick;
+uint8_t data = 69;
+
+// this variable is incremented by 1 on every ms by HAL_SysTick
+volatile uint32_t g_task_remote_tick_cnt;
+
+void task_remote_init(void *parameters)
+{
+    LOGGER_INFO("Initializing `task_remote`...");
+
+    g_task_remote_tick = G_TASK_REMOTE_TICK_INI;
+
+    LOGGER_INFO("Done initializing `task_remote`");
+}
+
+void task_remote_update(void *parameters)
+{
+    bool b_time_update_required = false;
+    // shared_data_type *p_shared_data = (shared_data_type *)parameters;
+
+    __asm("CPSID i");
+    if (G_TASK_REMOTE_TICK_INI < g_task_remote_tick_cnt)
+    {
+        g_task_remote_tick_cnt--;
+        b_time_update_required = true;
+    }
+    __asm("CPSIE i");
+
+    while (b_time_update_required)
+    {
+        __asm("CPSID i");
+        if (G_TASK_REMOTE_TICK_INI < g_task_remote_tick_cnt)
+        {
+            g_task_remote_tick_cnt--;
+            b_time_update_required = true;
+        }
+        else
+        {
+            b_time_update_required = false;
+        }
+        __asm("CPSIE i");
+
+        if (0 == g_task_remote_tick)
+        {
+            g_task_remote_tick = G_TASK_REMOTE_TEMP_UPDATE_RATE_MS;
+            HAL_UART_Transmit(&huart3, &data, 1, 100);
+        }
+        else
+        {
+            g_task_remote_tick--;
+        }
+    }
+}