]> Devi Nivas Git - smartwatch.git/commitdiff
Watch Face Drawing Code (Untested)
authorAdvaith Menon <noreply-git@bp4k.net>
Tue, 18 Nov 2025 19:51:02 +0000 (14:51 -0500)
committerAdvaith Menon <noreply-git@bp4k.net>
Tue, 18 Nov 2025 19:51:02 +0000 (14:51 -0500)
* 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

main/task_lcd.c
main/task_lcd.h

index ee5ca7b07dbd8b9504f32e2a95d38da2bae91c13..496cbf7e8c96da9458cfb3e60e64a1e73b08a39e 100644 (file)
@@ -1,4 +1,5 @@
 #include <time.h>
+#include <math.h>
 
 #include "freertos/FreeRTOS.h"
 #include "driver/gpio.h"
 
 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);
+}
index f499af28428abbfcc46b55dac77e4f1f8537d466..cebf466d1bfab387ad0456dd38c4fad3115883bc 100644 (file)
 #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;