]> Devi Nivas Git - smartwatch.git/commitdiff
watchdog timer demo
authorGajula, Anish <agajula7@gatech.edu>
Tue, 25 Nov 2025 13:36:11 +0000 (08:36 -0500)
committerGajula, Anish <agajula7@gatech.edu>
Tue, 25 Nov 2025 13:36:11 +0000 (08:36 -0500)
main/CMakeLists.txt
main/app_health.c [new file with mode: 0644]
main/app_health.h [new file with mode: 0644]
main/hello_world_main.c
main/task_imu.c
main/task_imu.h
main/task_lcd.c
main/task_lcd.h

index c41f1c11e010a41a5b136e3f3463d4c3f72a56a9..f2faec2fe436365774e75e4630ad1f576a60540f 100644 (file)
@@ -1,10 +1,11 @@
-idf_component_register(SRCS "hello_world_main.c"
+idf_component_register(SRCS "app_health.c" "hello_world_main.c"
                             "goldeloxSerial.c"
                             "task_lcd.c"
                             "task_button.c"
                             "task_imu.c"
                             "sdcardspi.c"
                             "bmp_reader.c"
+                            "app_health.c"
                        INCLUDE_DIRS "."
                        PRIV_REQUIRES esp_driver_gpio
                                      esp_driver_uart
diff --git a/main/app_health.c b/main/app_health.c
new file mode 100644 (file)
index 0000000..88989ee
--- /dev/null
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <stdint.h>
+#include "freertos/FreeRTOS.h"
+
+#include "Goldelox_Types4D.h"
+#include "Goldelox_const4D.h"
+#include "goldeloxSerial.h"
+
+#include "task_button.h"
+#include "task_imu.h"
+#include "app_health.h"
+
+void app_health_data(gl_display_t *disp) {
+    char data[64] = "watchdog test...";
+    gl_gfx_Cls(disp);
+    gl_txt_BGcolour(disp, BLACK);
+    gl_txt_FGcolour(disp, WHITE);
+    while (1) {
+        gl_txt_MoveCursor(disp, 0, 0);
+        struct gt_btn_msg_t *btnmsg;
+        struct gt_health_msg_t healthmsg;
+        gl_putstr(disp, (uint8_t *) "watch dog diagnosis");
+        gl_txt_MoveCursor(disp, 5, 0);
+        gl_putstr(disp, (uint8_t *) data);
+        while (xQueueReceive(gt_btnq, (void *) &btnmsg, 0) == pdPASS) {
+            if (btnmsg->btn == GT_BTN_WHITE
+                    && btnmsg->evt == BUTTON_SINGLE_CLICK) {
+                return;
+            }
+        }
+
+        while (xQueueReceive(gt_healthq, (void *) &healthmsg, 0) == pdPASS) {
+            snprintf(data, 64, "Steps: %d\nCalories: %.4f", healthmsg.step, healthmsg.cal);
+        }
+        printf(data);
+        
+        vTaskDelay(pdMS_TO_TICKS(100));
+    }
+}
+
+void app_health_data2(gl_display_t *disp) {
+    char data[64] = "watchdog test...";
+    gl_gfx_Cls(disp);
+    gl_txt_BGcolour(disp, BLACK);
+    gl_txt_FGcolour(disp, WHITE);
+    while (1) {
+        // gl_txt_MoveCursor(disp, 0, 0);
+        struct gt_btn_msg_t *btnmsg;
+        struct gt_health_msg_t healthmsg;
+        snprintf(data, 64, "Steps: %d Cal: %.4f", gt_health_step, gt_health_cal);
+        printf(data);
+        // gl_putstr(disp, (uint8_t *) "Pedometer");
+        gl_txt_MoveCursor(disp, 5, 0);
+        for (char *x = &data[0]; *x == '\0' ; x++)
+            gl_putCH(disp, 'A');
+        while (xQueueReceive(gt_btnq, (void *) &btnmsg, 0) == pdPASS) {
+            if (btnmsg->btn == GT_BTN_WHITE
+                    && btnmsg->evt == BUTTON_SINGLE_CLICK) {
+                return;
+            }
+        }
+        
+        vTaskDelay(pdMS_TO_TICKS(100));
+    }
+}
\ No newline at end of file
diff --git a/main/app_health.h b/main/app_health.h
new file mode 100644 (file)
index 0000000..989ad48
--- /dev/null
@@ -0,0 +1,11 @@
+#pragma once
+
+#ifndef __APP_HEALTH_H__
+#define __APP_HEALTH_H__
+#include "Goldelox_Types4D.h"
+
+void app_health_data(gl_display_t *disp);
+
+void app_health_data2(gl_display_t *disp);
+
+#endif
\ No newline at end of file
index bc2b4302f040922da3d93a4524b6dbdd135290dd..d1f93f01e5e22c638298588f47b331c14d91016f 100644 (file)
@@ -10,6 +10,7 @@
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 #include "driver/gpio.h"
+#include "esp_log.h"
 
 /* custom headers we made!!*/
 #include "task_imu.h"
 #include "task_button.h"
 #include "sdcardspi.h"
 
+static const char *TAG = "hello_world_main";
+
 int gt_global_sdsupport;
 
 void app_main(void)
 {
+    TaskHandle_t imu_taskh;
+
     printf("Hello world!\n");
 
     ESP_ERROR_CHECK(gpio_reset_pin(PIN_BUTTON_WHITE));
@@ -54,8 +59,14 @@ void app_main(void)
 
     gt_global_sdsupport = task_sdcard();
     /* start the main gui thread  which starts all else */
-   // lcd_task();
-    task_imu_all(NULL);
+
+    if (xTaskCreate(task_imu_all,
+    "task.imu", 4096, NULL, tskIDLE_PRIORITY, &imu_taskh) != pdPASS) {
+        ESP_LOGW(TAG, "failed to initialize imu");
+    }
+
+    lcd_task();
+    //task_imu_all(NULL);
     /*
     for (int i = 10; i >= 0; i--) {
         printf("Restarting in %d seconds...\n", i);
index 80f616b86d6b4c755b4e275657fbe5d32228bd87..0e2322ab7ec0e8865570d46ae03a1163c66e61a8 100644 (file)
 #include "icm20948.h"
 #include "icm20948_i2c.h"
 #include "pins.h"
+#include "task_imu.h"
 #define TAG "i2c_agmt"
 
+#define EVENT_Q_SIZE 1
+
+
+int gt_health_step;
+float gt_health_cal;
+
 /* i2c bus configuration */
 i2c_config_t conf = {
        .mode = I2C_MODE_MASTER,
@@ -25,6 +32,7 @@ i2c_config_t conf = {
        .clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL
 };
 
+QueueHandle_t gt_healthq;
 static int step_count = 0;
 static bool is_paused = false;
 static uint32_t pause_start_ms = 0;
@@ -56,7 +64,7 @@ void step_counter(icm20948_agmt_t agmt) {
     // check for the arm movement 
     if (x >= SWING_THRESHOLD) {
         step_count += 2;  // add 2 steps 
-        ESP_LOGI(TAG, "Swing detected. Total steps: %d", step_count);
+        // ESP_LOGI(TAG, "Swing detected. Total steps: %d", step_count);
 
         is_paused = true;  // add a buffer to prevent over counting
         pause_start_ms = now_ms; 
@@ -89,6 +97,9 @@ void task_imu_all(void *)
 {
        icm20948_device_t icm;
 
+       /* init q */
+       gt_healthq = xQueueCreate(EVENT_Q_SIZE, sizeof(struct gt_health_msg_t));
+
        /* setup i2c */
        ESP_ERROR_CHECK(i2c_param_config(icm_config.i2c_port, &conf));
        ESP_ERROR_CHECK(i2c_driver_install(icm_config.i2c_port, conf.mode, 0, 0, 0));
@@ -148,13 +159,20 @@ void task_imu_all(void *)
     /* loop */
     while(1)
        {
+               struct gt_health_msg_t msg;
                vTaskDelay(100 / portTICK_PERIOD_MS);
 
                icm20948_agmt_t agmt; // = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0}};
                if (icm20948_get_agmt(&icm, &agmt) == ICM_20948_STAT_OK) {
-                       print_agmt(agmt);
+                       // print_agmt(agmt);
             step_counter(agmt);
-                       ESP_LOGI(TAG, "Calories burned: %.2f kcal\n Step Count: %d", calculate_calories_from_steps(step_count, 170.0f, 65.5f), step_count);
+                       msg.cal = calculate_calories_from_steps(step_count, 170.0f, 65.5f);
+                       msg.step = step_count;
+                       // ESP_LOGI(TAG, "Calories burned: %.2f kcal; Step Count: %d", msg.cal, step_count);
+                       gt_health_step = step_count;
+                       gt_health_cal = msg.cal;
+                       xQueueSendToBackFromISR(gt_healthq, &msg, NULL);
+                       
                } else {
                        ESP_LOGE(TAG, "Uh oh");
                }        
index 9bcd14d6e887f93e569007ce8986f1de0d5923ff..effc8a7a3338efcd9cc7b5b17ce5d54d627128f3 100644 (file)
@@ -2,6 +2,16 @@
 
 #ifndef __TASK_IMU_H__
 #define __TASK_IMU_H__
+#include "freertos/FreeRTOS.h"
+
+struct gt_health_msg_t {
+    int step;
+    float cal;
+};
+
+extern QueueHandle_t gt_healthq;
+extern int gt_health_step;
+extern float gt_health_cal;
 
 void task_imu_all(void *pvParams);
 
index 97de30ddd2d97a11ce918ce7387b70754840550e..7bed529f036d145e77a9021f9db45c507deadb49 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "task_lcd.h"
 #include "task_button.h"
+#include "app_health.h"
 #include "pins.h"
 
 static const char* TAG = "task_lcd";
@@ -36,6 +37,20 @@ struct app_t applist[NUM_APPS] = {
         .icon.height = 0,
         .icon.data = NULL,
         .name = "About SWOS"
+    },
+    {
+        .fn = &app_health_data,
+        .icon.width = 0,
+        .icon.height = 0,
+        .icon.data = NULL,
+        .name = "WatchDog Test"
+    },
+    {
+        .fn = &app_health_data2,
+        .icon.width = 0,
+        .icon.height = 0,
+        .icon.data = NULL,
+        .name = "Pedometer fr :)"
     }
 };
 
@@ -115,7 +130,7 @@ int Callback4DImpl (int, unsigned char) {
         gl_reset2(error_disp);
         //gl_setbaudWait(error_disp, BAUD_600000, &faster_baud);
     }
-    if (g_time > 9)
+    if (g_time > 4)
         esp_restart();
     g_time++;
     return 10;
@@ -354,6 +369,7 @@ void lcd_homepage_loop(gl_display_t *disp) {
             uint8_t old_idx = curr_idx;
             if (btnmsg->btn == GT_BTN_YELLOW
                     && btnmsg->evt == BUTTON_SINGLE_CLICK) {
+                gl_gfx_Cls(disp);
                 applist[curr_idx].fn(disp);
                 lcd_homepage_draw_face(disp, num_rows, num_cols, num_padd);
                 continue;
index 3938ce936fb5166114a45e6420b5ea49d32551d0..0f226c31ab2557c2aa0744bf9575b3ba2b381ec6 100644 (file)
@@ -52,7 +52,7 @@
 
 /* digital clock spacing */
 
-#define NUM_APPS 2
+#define NUM_APPS 4
 
 typedef void (*app_fn_t) (gl_display_t *);