From: Gajula, Anish Date: Tue, 25 Nov 2025 13:36:11 +0000 (-0500) Subject: watchdog timer demo X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=16bd95c3778b42b1b12ff0ee12354c54ec354e58;p=smartwatch.git watchdog timer demo --- diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index c41f1c1..f2faec2 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -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 index 0000000..88989ee --- /dev/null +++ b/main/app_health.c @@ -0,0 +1,65 @@ +#include +#include +#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 index 0000000..989ad48 --- /dev/null +++ b/main/app_health.h @@ -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 diff --git a/main/hello_world_main.c b/main/hello_world_main.c index bc2b430..d1f93f0 100644 --- a/main/hello_world_main.c +++ b/main/hello_world_main.c @@ -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" @@ -18,10 +19,14 @@ #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); diff --git a/main/task_imu.c b/main/task_imu.c index 80f616b..0e2322a 100644 --- a/main/task_imu.c +++ b/main/task_imu.c @@ -12,8 +12,15 @@ #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"); } diff --git a/main/task_imu.h b/main/task_imu.h index 9bcd14d..effc8a7 100644 --- a/main/task_imu.h +++ b/main/task_imu.h @@ -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); diff --git a/main/task_lcd.c b/main/task_lcd.c index 97de30d..7bed529 100644 --- a/main/task_lcd.c +++ b/main/task_lcd.c @@ -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; diff --git a/main/task_lcd.h b/main/task_lcd.h index 3938ce9..0f226c3 100644 --- a/main/task_lcd.h +++ b/main/task_lcd.h @@ -52,7 +52,7 @@ /* digital clock spacing */ -#define NUM_APPS 2 +#define NUM_APPS 4 typedef void (*app_fn_t) (gl_display_t *);