From: Gajula, Anish Date: Tue, 25 Nov 2025 14:17:38 +0000 (-0500) Subject: Add actual health app X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=9126c99a16c01b3ee4fb3320b0d7ae5007bb3fd9;p=smartwatch.git Add actual health app * Add health app and implement viewing data via a queue * Move txt_strw to goldeloxSerial and rename with gl_ prefix --- diff --git a/main/app_health.c b/main/app_health.c index 88989ee..5d7ee3a 100644 --- a/main/app_health.c +++ b/main/app_health.c @@ -8,8 +8,12 @@ #include "task_button.h" #include "task_imu.h" +#include "task_lcd.h" #include "app_health.h" +#define HEALTH_BANNER_HEIGHT 16 +#define HEALTH_PAD 5 + void app_health_data(gl_display_t *disp) { char data[64] = "watchdog test..."; gl_gfx_Cls(disp); @@ -39,27 +43,56 @@ void app_health_data(gl_display_t *disp) { } void app_health_data2(gl_display_t *disp) { - char data[64] = "watchdog test..."; + char data[64] = "loading..."; + char dat2[64] = "loading..."; + const char *title = "Exercise"; + const gl_word_t charht = gl_charheight(disp, 'x'); gl_gfx_Cls(disp); + + + + uint16_t txtw = gl_txt_strw(disp, title); + gl_gfx_RectangleFilled(disp, 0, 0, LCD_WIDTH, HEALTH_BANNER_HEIGHT, ROSYBROWN); + gl_gfx_MoveTo(disp, LCD_WIDTH / 2 - txtw / 2, (HEALTH_BANNER_HEIGHT - charht) / 2); + gl_txt_BGcolour(disp, ROSYBROWN); + gl_txt_FGcolour(disp, WHITE); + gl_txt_Bold(disp, 1); + gl_putstr(disp, (uint8_t *) title); + + 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; } } + + while (xQueueReceive(gt_healthq, (void *) &healthmsg, 0) == pdPASS) { + snprintf(data, 64, "Steps: %d", healthmsg.step); + snprintf(dat2, 64, "Calories: %d", (int) healthmsg.cal); + } + + // printf(data); + + // gl_txt_MoveCursor(disp, 5, 0); + txtw = gl_txt_strw(disp, data); + gl_gfx_MoveTo(disp, LCD_WIDTH / 2 - txtw / 2, LCD_HEIGHT / 2 - charht - HEALTH_PAD); + //for (char *x = &data[0]; *x == '\0' ; x++) + gl_putstr(disp, (unsigned char *) data); + + txtw = gl_txt_strw(disp, dat2); + gl_gfx_MoveTo(disp, LCD_WIDTH / 2 - txtw / 2, LCD_HEIGHT / 2 + HEALTH_PAD); + gl_putstr(disp, (unsigned char *) dat2); vTaskDelay(pdMS_TO_TICKS(100)); } } \ No newline at end of file diff --git a/main/goldeloxSerial.c b/main/goldeloxSerial.c index 7e39b94..0e3fd7d 100644 --- a/main/goldeloxSerial.c +++ b/main/goldeloxSerial.c @@ -1329,3 +1329,13 @@ void gl_reset2(gl_display_t *disp) { disp->serif->flush_rx(); } + + +gl_word_t gl_txt_strw(gl_display_t *disp, char *str) { + gl_word_t pxlw = 0; + while (*str) { + pxlw += gl_charwidth(disp, (unsigned char) *str); + str++; + } + return pxlw; +} \ No newline at end of file diff --git a/main/goldeloxSerial.h b/main/goldeloxSerial.h index 77b1b4c..0d7cf21 100644 --- a/main/goldeloxSerial.h +++ b/main/goldeloxSerial.h @@ -234,6 +234,9 @@ gl_word_t gl_peekW(gl_display_t *display, gl_word_t Address) ; void gl_reset2(gl_display_t *); +gl_word_t gl_txt_strw(gl_display_t *, char *); + + #ifdef __cplusplus } diff --git a/main/task_imu.c b/main/task_imu.c index 0e2322a..12c49a9 100644 --- a/main/task_imu.c +++ b/main/task_imu.c @@ -18,9 +18,6 @@ #define EVENT_Q_SIZE 1 -int gt_health_step; -float gt_health_cal; - /* i2c bus configuration */ i2c_config_t conf = { .mode = I2C_MODE_MASTER, @@ -169,8 +166,6 @@ void task_imu_all(void *) 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 { diff --git a/main/task_imu.h b/main/task_imu.h index effc8a7..f0d6251 100644 --- a/main/task_imu.h +++ b/main/task_imu.h @@ -10,8 +10,6 @@ struct gt_health_msg_t { }; 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 7bed529..ce0e7c8 100644 --- a/main/task_lcd.c +++ b/main/task_lcd.c @@ -59,7 +59,7 @@ struct app_t applist[NUM_APPS] = { void lcd_clock_draw_face(gl_display_t *); void lcd_clock_draw_hand(gl_display_t *, uint16_t, uint16_t, uint8_t, gl_word_t); -gl_word_t txt_strw(gl_display_t *, char *); + int write_tx(const void*, size_t); int read_rx(void *, size_t, uint32_t); int flush_rx(); @@ -281,7 +281,7 @@ void lcd_clock_loop(gl_display_t *disp) { tm / 60 % 60, (tm / (60 * 60) % 24 > 12) ? "PM" : "AM"); /*gl_txt_Italic(disp, 1);*/ - uint16_t chw = txt_strw(disp, txt); + uint16_t chw = gl_txt_strw(disp, txt); gl_gfx_MoveTo(disp, (LCD_WIDTH / 2) - (chw / 2), (LCD_HEIGHT / 2) + (CLOCKSCR_CIRCRAD / 2)); gl_putstr(disp, (unsigned char *) txt); @@ -395,7 +395,7 @@ void lcd_homepage_loop(gl_display_t *disp) { txt = applist[curr_idx].name; gl_gfx_RectangleFilled(disp, 0, LCD_HHEIGHT, LCD_WIDTH, LCD_HEIGHT, BLACK); - chw = txt_strw(disp, txt); + chw = gl_txt_strw(disp, txt); gl_gfx_MoveTo(disp, LCD_WIDTH / 2 - chw / 2, LCD_HHEIGHT + APPSCR_PAD); gl_txt_BGcolour(disp, BLACK); @@ -457,11 +457,4 @@ void lcd_clock_draw_hand(gl_display_t *disp, uint16_t x, uint16_t n, uint8_t l, } -gl_word_t txt_strw(gl_display_t *disp, char *str) { - gl_word_t pxlw = 0; - while (*str) { - pxlw += gl_charwidth(disp, (unsigned char) *str); - str++; - } - return pxlw; -} + diff --git a/main/task_lcd.h b/main/task_lcd.h index 0f226c3..082b861 100644 --- a/main/task_lcd.h +++ b/main/task_lcd.h @@ -81,4 +81,6 @@ void lcd_boot_flash_app(gl_display_t *); void lcd_task(void); + + #endif