-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
--- /dev/null
+#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
--- /dev/null
+#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
#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));
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);
#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,
.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;
// 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;
{
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));
/* 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");
}
#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);
#include "task_lcd.h"
#include "task_button.h"
+#include "app_health.h"
#include "pins.h"
static const char* TAG = "task_lcd";
.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 :)"
}
};
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;
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;
/* digital clock spacing */
-#define NUM_APPS 2
+#define NUM_APPS 4
typedef void (*app_fn_t) (gl_display_t *);