From: Advaith Menon Date: Tue, 18 Nov 2025 19:51:02 +0000 (-0500) Subject: Watch Face Drawing Code (Untested) X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=259409dcae9d0acfacd7b4b636dd469e857d106c;p=smartwatch.git Watch Face Drawing Code (Untested) * Modify APPSCR macros to allow variable number of apps per screen, allowing dynamic changing of these values via a Settings interface * Comment old macro code in lcd_homepage_loop * Add lcd_draw_clock_face to draw a circular clock face with hour ticks using trigonometry * Add lcd_clock_draw_hand to draw clock hands in an easy way * Modify lcd_clock_loop to use the new lcd_draw_clock_face and lcd_clock_draw_hand functions --- diff --git a/main/task_lcd.c b/main/task_lcd.c index ee5ca7b..496cbf7 100644 --- a/main/task_lcd.c +++ b/main/task_lcd.c @@ -1,4 +1,5 @@ #include +#include #include "freertos/FreeRTOS.h" #include "driver/gpio.h" @@ -12,6 +13,11 @@ const uart_port_t uart_num = UART_NUM_1; + +void lcd_clock_draw_face(gl_display_t *); +void lcd_clock_draw_hand(gl_display_t *, uint16_t, uint16_t, uint8_t); + + int write_tx(const void *data, size_t sz) { return uart_write_bytes(uart_num, data, sz); } @@ -102,7 +108,7 @@ void lcd_boot_flash(gl_display_t *disp) { gl_gfx_Cls(disp); /* draw straps */ - for (uint8_t r = 0; r <= LCD_HEIGHT; r+= 5) { + for (uint8_t r = 0; r <= LCD_HEIGHT; r+= 4) { gl_gfx_RectangleFilled(disp, LCD_WIDTH / 2 - BOOT_STRAP_WIDTH / 2 - BOOT_CIRCL_OFFSET, LCD_HEIGHT / 2 - r / 2, @@ -138,16 +144,19 @@ void lcd_boot_flash(gl_display_t *disp) { void lcd_clock_loop(gl_display_t *disp) { - gl_txt_FGcolour(disp, GREEN); - gl_txt_BGcolour(disp, BLACK); - gl_txt_MoveCursor(disp, 0, 0); - gl_putstr(disp, (uint8_t *) "Debug Clock Mode"); + gl_gfx_Cls(disp); + gl_gfx_BGcolour(disp, BLACK); + lcd_clock_draw_face(disp); while (1) { time_t tm = time(NULL); char txt[10]; snprintf(txt, 10, "%lld", (long long) tm); - gl_txt_MoveCursor(disp, 1, 0); - gl_putstr(disp, (uint8_t *) txt); + // gl_txt_MoveCursor(disp, 1, 0); + // gl_putstr(disp, (uint8_t *) txt); + lcd_clock_draw_hand(disp, tm % 60, 60, CLOCKSCR_TIMEHDSE); + lcd_clock_draw_hand(disp, tm % (60 * 60), (60 * 60), CLOCKSCR_TIMEHDMN); + lcd_clock_draw_hand(disp, tm % (60 * 60 * 12), + (60 * 60 * 12), CLOCKSCR_TIMEHDHR); vTaskDelay(pdMS_TO_TICKS(1000)); } } @@ -159,6 +168,7 @@ void lcd_homepage_loop(gl_display_t *disp) { for (uint8_t i = 0; i < APPSCR_RCNUM; ++i) { for (uint8_t j = 0; j < APPSCR_RCNUM; ++j) { + /* printf("adding %d, %d [%d|%d|%d|%d]\n", i + 1, j + 1, APPSCR_TOPCALCW(i + 1), APPSCR_TOPCALCH(j + 1), @@ -169,6 +179,56 @@ void lcd_homepage_loop(gl_display_t *disp) { APPSCR_TOPCALCW(i + 1) + APPSCR_PADCALCW(0), APPSCR_TOPCALCH(j + 1) + APPSCR_PADCALCH(0), WHITE); + */ } } } + + +void lcd_clock_draw_face(gl_display_t *disp) { + /* draw the circle */ + gl_gfx_CircleFilled(disp, LCD_WIDTH / 2, LCD_HEIGHT / 2, CLOCKSCR_CIRCRAD, + ALICEBLUE); + + for (double angle = 0; angle < 2 * M_PI; angle += (2 * M_PI) / 12) { + /* draw hour ticks */ + + /* full 'x' tick start length */ + int8_t fxs = cos(angle) * (CLOCKSCR_CIRCRAD - (CLOCKSCR_TIMEMKHR / 2)); + /* full 'y' tick start length */ + int8_t fys = sin(angle) * (CLOCKSCR_CIRCRAD - (CLOCKSCR_TIMEMKHR / 2)); + + /* full 'x' tick end length */ + int8_t fxe = cos(angle) * (CLOCKSCR_CIRCRAD + (CLOCKSCR_TIMEMKHR / 2)); + /* full 'y' tick end length */ + int8_t fye = sin(angle) * (CLOCKSCR_CIRCRAD + (CLOCKSCR_TIMEMKHR / 2)); + + /* plot the line. remember this is with respect to the origin so we + * need to correct for that by adding LCD_WIDTH / 2 or the ht. + */ + + gl_gfx_Line(disp, + fxs + (LCD_WIDTH / 2), + fys + (LCD_HEIGHT / 2), + fxe + (LCD_WIDTH / 2), + fye + (LCD_HEIGHT / 2), RED); + } +} + + +void lcd_clock_draw_hand(gl_display_t *disp, uint16_t x, uint16_t n, uint8_t l) { + /* x = current (minute/second etc., n = total, l = length of hand */ + + double angle = (double) x * M_PI * 2 / n; + + /* full 'x' tick end length */ + int8_t fxe = cos(angle) * l; + /* full 'y' tick end length */ + int8_t fye = sin(angle) * l; + + gl_gfx_Line(disp, + 0 + (LCD_WIDTH / 2), + 0 + (LCD_HEIGHT / 2), + fxe + (LCD_WIDTH / 2), + fye + (LCD_HEIGHT / 2), BLACK); +} diff --git a/main/task_lcd.h b/main/task_lcd.h index f499af2..cebf466 100644 --- a/main/task_lcd.h +++ b/main/task_lcd.h @@ -27,6 +27,25 @@ #define APPSCR_TOPCALCW(x) ((x) * APPSCR_PAD) + (((x) - 1) * APPSCR_PADCALCW(0)) #define APPSCR_TOPCALCH(x) ((x) * APPSCR_PAD) + (((x) - 1) * APPSCR_PADCALCH(0)) +/* v stands for variale */ +#define APPSCR_PADCALCVW(n, pad) (LCD_WIDTH - (n) * (pad)) +#define APPSCR_PADCALCVH(n, pad) (LCD_HEIGHT - (n) * (pad)) +#define APPSCR_TOPCALCVW(n, pad, x) ((x) * (pad)) + \ + (((x) - 1) * APPSCR_PADCALCVW(n, pad)) +#define APPSCR_TOPCALCVH(n, pad, x) ((x) * (pad)) + \ + (((x) - 1) * APPSCR_PADCALCVH(n, pad)) + +#define CLOCKSCR_CIRCRAD 50 +/* time markers (hour) length */ +#define CLOCKSCR_TIMEMKHR 6 + +/* time hand (hour) length */ +#define CLOCKSCR_TIMEHDHR 20 +/* time hand (min) length */ +#define CLOCKSCR_TIMEHDMN 30 +/* time hand (sec) length */ +#define CLOCKSCR_TIMEHDSE 45 + typedef struct { uint8_t width; uint8_t height;