From: Advaith Menon Date: Sun, 23 Nov 2025 04:21:58 +0000 (-0500) Subject: Add working homescreen X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=e1cb4dec000ded20a87cf26bb98b6476e218a9ec;p=smartwatch.git Add working homescreen * Pad homescreen to allow space to display app name * Add array to store app names * Allow selecting boxes in homescreen with green text * Convert the boot screen to an app * Add an easter egg to the boot screen --- diff --git a/main/task_button.c b/main/task_button.c index d30f033..f3991e5 100644 --- a/main/task_button.c +++ b/main/task_button.c @@ -26,7 +26,7 @@ static struct gt_btn_msg_t btn_evts[10] = { }; -static const char* TAG = "task_button"; +// static const char* TAG = "task_button"; /* local fn definitions */ @@ -88,8 +88,6 @@ void gt_btn_setup(void) { void button_all_cb(void *arg, void *user_data) { - struct gt_btn_msg_t *msg = (struct gt_btn_msg_t*) user_data; - ESP_LOGI(TAG, "Button pressed"); - ESP_LOGI(TAG, "The selected event: %d; and event %d", msg->btn, msg->evt); + // struct gt_btn_msg_t *msg = (struct gt_btn_msg_t*) user_data; xQueueSendToBackFromISR(gt_btnq, (void *) &user_data, NULL); } diff --git a/main/task_lcd.c b/main/task_lcd.c index 3c4f602..ac6b746 100644 --- a/main/task_lcd.c +++ b/main/task_lcd.c @@ -5,6 +5,7 @@ #include "driver/gpio.h" #include "driver/uart.h" #include "iot_button.h" +#include "esp_log.h" #include "Goldelox_const4D.h" #include "goldeloxSerial.h" @@ -14,17 +15,45 @@ #include "task_button.h" #include "pins.h" +static const char* TAG = "task_lcd"; const uart_port_t uart_num = UART_NUM_1; int g_time = 0; gl_display_t *error_disp = NULL; +/* list of all apps as function pointers */ +struct app_t applist[NUM_APPS] = { + { + .fn = &lcd_clock_loop, + .icon.width = 0, + .icon.height = 0, + .icon.data = NULL, + .name = "Clock" + }, + { + .fn = &lcd_boot_flash_app, + .icon.width = 0, + .icon.height = 0, + .icon.data = NULL, + .name = "SWOS Flash" + } +}; + +/* ================================================================= */ +/* functions definitons */ 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(); +int flush_tx(uint32_t); +void faster_baud(); +void slower_baud(); +void lcd_homepage_draw_base(gl_display_t *, uint8_t, uint8_t, uint8_t); - +/* ================================================================= */ int write_tx(const void *data, size_t sz) { return uart_write_bytes(uart_num, data, sz); @@ -140,13 +169,13 @@ void lcd_task(void) { /* change baud rate */ gl_setbaudWait(&disp, BAUD_600000, &faster_baud); - lcd_boot_flash(&disp); + lcd_boot_flash(&disp, 1); //lcd_clock_loop(&disp); lcd_homepage_loop(&disp); } -void lcd_boot_flash(gl_display_t *disp) { +void lcd_boot_flash(gl_display_t *disp, uint8_t ret) { gl_gfx_BGcolour(disp, WHITE); gl_gfx_Cls(disp); @@ -185,10 +214,39 @@ void lcd_boot_flash(gl_display_t *disp) { gl_putstr(disp, (uint8_t *) "Anish &"); gl_txt_MoveCursor(disp, 11, 10); gl_putstr(disp, (uint8_t *) "Advaith"); - ESP_ERROR_CHECK(gpio_set_level(PIN_VIBRATOR, 1)); - vTaskDelay(pdMS_TO_TICKS(500)); - ESP_ERROR_CHECK(gpio_set_level(PIN_VIBRATOR, 0)); - vTaskDelay(pdMS_TO_TICKS(1500)); + + if (ret) { + ESP_ERROR_CHECK(gpio_set_level(PIN_VIBRATOR, 1)); + vTaskDelay(pdMS_TO_TICKS(500)); + ESP_ERROR_CHECK(gpio_set_level(PIN_VIBRATOR, 0)); + vTaskDelay(pdMS_TO_TICKS(1500)); + return; + } + + + while(1) { + struct gt_btn_msg_t *btnmsg; + while (xQueueReceive(gt_btnq, (void *) &btnmsg, portMAX_DELAY) + == pdPASS) { + if (btnmsg->btn == GT_BTN_WHITE && btnmsg->evt + == BUTTON_SINGLE_CLICK) { + return; + } else if (btnmsg->btn == GT_BTN_RED && btnmsg->evt + == BUTTON_DOUBLE_CLICK) { + ESP_LOGI(TAG, "Writing diego swears lol"); + gl_txt_BGcolour(disp, WHITE); + gl_txt_FGcolour(disp, GREEN); + gl_txt_MoveCursor(disp, 0, 0); + gl_putstr(disp, (uint8_t *) + "Diego Swears: 2"); + } + } + } +} + + +void lcd_boot_flash_app(gl_display_t *disp) { + lcd_boot_flash(disp, 0); } @@ -237,29 +295,13 @@ void lcd_clock_loop(gl_display_t *disp) { } -void lcd_homepage_loop(gl_display_t *disp) { - uint8_t num_rows = 3; - uint8_t num_cols = 3; - uint8_t num_padd = APPSCR_PAD; - lcd_clock_loop(disp); - +void lcd_homepage_draw_face(gl_display_t *disp, uint8_t num_rows, + uint8_t num_cols, uint8_t num_padd) { gl_gfx_BGcolour(disp, BLACK); gl_gfx_Cls(disp); for (uint8_t i = 0; i < num_rows; ++i) { for (uint8_t j = 0; j < num_cols; ++j) { - /* - printf("adding %d, %d [%d|%d|%d|%d]\n", - i + 1, j + 1, - APPSCR_TOPCALCW(i + 1), APPSCR_TOPCALCH(j + 1), - APPSCR_TOPCALCW(i + 1) + APPSCR_PADCALCW(0), - APPSCR_TOPCALCH(j + 1) + APPSCR_PADCALCH(0)); - gl_gfx_RectangleFilled(disp, - APPSCR_TOPCALCW(i + 1), APPSCR_TOPCALCH(j + 1), - APPSCR_TOPCALCW(i + 1) + APPSCR_PADCALCW(0), - APPSCR_TOPCALCH(j + 1) + APPSCR_PADCALCH(0), - WHITE); - */ gl_gfx_RectangleFilled(disp, APPSCR_TOPCALCVW(num_cols, num_padd, j + 1), APPSCR_TOPCALCVH(num_rows, num_padd, i + 1), @@ -270,8 +312,81 @@ void lcd_homepage_loop(gl_display_t *disp) { WHITE); } } - while(1) - vTaskDelay(pdMS_TO_TICKS(1000)); +} + + +void lcd_homepage_draw_color(gl_display_t *disp, uint8_t num_rows, + uint8_t num_cols, uint8_t num_padd, uint8_t old_r, uint8_t old_c, + uint8_t new_r, uint8_t new_c) { + gl_gfx_RectangleFilled(disp, + APPSCR_TOPCALCVW(num_cols, num_padd, old_c + 1), + APPSCR_TOPCALCVH(num_rows, num_padd, old_r + 1), + APPSCR_TOPCALCVW(num_cols, num_padd, old_c + 1) + + APPSCR_PADCALCVW(num_cols, num_padd), + APPSCR_TOPCALCVH(num_rows, num_padd, old_r + 1) + + APPSCR_PADCALCVH(num_rows, num_padd), + WHITE); + gl_gfx_RectangleFilled(disp, + APPSCR_TOPCALCVW(num_cols, num_padd, new_c + 1), + APPSCR_TOPCALCVH(num_rows, num_padd, new_r + 1), + APPSCR_TOPCALCVW(num_cols, num_padd, new_c + 1) + + APPSCR_PADCALCVW(num_cols, num_padd), + APPSCR_TOPCALCVH(num_rows, num_padd, new_r + 1) + + APPSCR_PADCALCVH(num_rows, num_padd), + GREEN); +} + + +void lcd_homepage_loop(gl_display_t *disp) { + uint8_t num_rows = 3; + uint8_t num_cols = 3; + uint8_t num_padd = APPSCR_PAD; + uint8_t curr_idx = num_rows * num_cols - 1; + lcd_clock_loop(disp); + lcd_homepage_draw_face(disp, num_rows, num_cols, num_padd); + + while(1) { + struct gt_btn_msg_t *btnmsg; + while (xQueueReceive(gt_btnq, (void *) &btnmsg, portMAX_DELAY) + == pdPASS) { + uint16_t chw; + char *txt; + uint8_t old_idx = curr_idx; + if (btnmsg->btn == GT_BTN_YELLOW + && btnmsg->evt == BUTTON_SINGLE_CLICK) { + applist[curr_idx].fn(disp); + lcd_homepage_draw_face(disp, num_rows, num_cols, num_padd); + continue; + } else if (btnmsg->btn == GT_BTN_BLUE) { + if (btnmsg->evt == BUTTON_SINGLE_CLICK) { + curr_idx = (curr_idx + 1) % (NUM_APPS); + } else if (btnmsg->evt == BUTTON_DOUBLE_CLICK) { + curr_idx = (curr_idx + num_rows) % (NUM_APPS); + } + } else if (btnmsg->btn == GT_BTN_GREEN) { + if (btnmsg->evt == BUTTON_SINGLE_CLICK) { + curr_idx = (curr_idx + NUM_APPS - 1) + % (NUM_APPS); + } else if (btnmsg->evt == BUTTON_DOUBLE_CLICK) { + curr_idx = (curr_idx + NUM_APPS - num_rows) + % (NUM_APPS); + } + } + lcd_homepage_draw_color(disp, num_rows, num_cols, num_padd, + old_idx / num_rows, old_idx % num_rows, + curr_idx / num_rows, curr_idx % num_rows); + /* draw app name */ + txt = applist[curr_idx].name; + gl_gfx_RectangleFilled(disp, 0, LCD_HHEIGHT, LCD_WIDTH, LCD_HEIGHT, + BLACK); + chw = txt_strw(disp, txt); + gl_gfx_MoveTo(disp, LCD_WIDTH / 2 - chw / 2, LCD_HHEIGHT + + APPSCR_PAD); + gl_txt_BGcolour(disp, BLACK); + gl_txt_FGcolour(disp, WHITE); + gl_putstr(disp, (uint8_t *) txt); + } + } } diff --git a/main/task_lcd.h b/main/task_lcd.h index 9bee7ab..3938ce9 100644 --- a/main/task_lcd.h +++ b/main/task_lcd.h @@ -27,9 +27,13 @@ #define APPSCR_TOPCALCW(x) ((x) * APPSCR_PAD) + (((x) - 1) * APPSCR_PADCALCW(0)) #define APPSCR_TOPCALCH(x) ((x) * APPSCR_PAD) + (((x) - 1) * APPSCR_PADCALCH(0)) +/* home screen lcd width and height */ + +#define LCD_HWIDTH 128 +#define LCD_HHEIGHT 112 /* v stands for variale */ -#define APPSCR_PADCALCVW(n, pad) (LCD_WIDTH - (n) * (pad)) / (n) -#define APPSCR_PADCALCVH(n, pad) (LCD_HEIGHT - (n) * (pad)) / (n) +#define APPSCR_PADCALCVW(n, pad) (LCD_HWIDTH - (n) * (pad)) / (n) +#define APPSCR_PADCALCVH(n, pad) (LCD_HHEIGHT - (n) * (pad)) / (n) #define APPSCR_TOPCALCVW(n, pad, x) ((x) * (pad)) + \ (((x) - 1) * APPSCR_PADCALCVW(n, pad)) #define APPSCR_TOPCALCVH(n, pad, x) ((x) * (pad)) + \ @@ -48,18 +52,32 @@ /* digital clock spacing */ -typedef struct { +#define NUM_APPS 2 + +typedef void (*app_fn_t) (gl_display_t *); + + +struct lcd_icon_t { uint8_t width; uint8_t height; uint16_t *data; -} lcd_icon_t; +}; + + +struct app_t { + app_fn_t fn; + struct lcd_icon_t icon; + char *name; +}; void lcd_homepage_loop(gl_display_t *); void lcd_clock_loop(gl_display_t *); -void lcd_boot_flash(gl_display_t *); +void lcd_boot_flash(gl_display_t *, uint8_t); + +void lcd_boot_flash_app(gl_display_t *); void lcd_task(void);