]> git.earman.xyz Git - sensor-watch.git/commitdiff
simplify lcd display logic, one screen with 10 positions
authorJoey Castillo <jose.castillo@gmail.com>
Wed, 28 Apr 2021 12:28:47 +0000 (08:28 -0400)
committerJoey Castillo <jose.castillo@gmail.com>
Wed, 28 Apr 2021 12:28:47 +0000 (08:28 -0400)
Smol Watch Project/My Project/main.c
Smol Watch Project/My Project/watch-library/watch.c
Smol Watch Project/My Project/watch-library/watch.h

index ede6d12bd4285e89d0531a02461c56b2749055c4..8289731b683087b2dddac1433e2cbb0d71aacf2d 100644 (file)
@@ -43,10 +43,12 @@ int main(void)
                        last = date_time.time.sec;
                        if (last % 2 == 0) {
                                watch_set_led_color(50, 0);
-                               watch_display_string(&watch, watch.main_display, " Hello");
+                               watch_display_string(&watch, "0123456789", 0);
                        } else {
                                watch_set_led_color(0, 50);
-                               watch_display_string(&watch, watch.main_display, " there");
+                               watch_display_string(&watch, "01", 0);
+                               watch_display_string(&watch, "23", 2);
+                               watch_display_string(&watch, "456789", 4);
                        }
                }
        }
index 7dbfed445273a61a5513463c0ed6b55cc3401553..ad4e7632ce05cdd6343f987026f1bbd9fd70f929 100644 (file)
@@ -116,7 +116,11 @@ const uint8_t Character_Set[] =
 void watch_enable_display(Watch *watch) {\r
        if (watch->display_enabled) return;\r
 \r
-       static const uint64_t main_segmap[] = {\r
+       static const uint64_t segmap[] = {\r
+               0x4e4f0e8e8f8d4d0d, // Position 8\r
+               0xc8c4c4c8b4b4b0b,  // Position 9\r
+               0xc049c00a49890949, // Position 6\r
+               0xc048088886874707, // Position 7\r
                0xc053921252139352, // Position 0\r
                0xc054511415559594, // Position 1\r
                0xc057965616179716, // Position 2\r
@@ -124,65 +128,48 @@ void watch_enable_display(Watch *watch) {
                0xc043420203048382, // Position 4\r
                0xc045440506468584, // Position 5\r
        };\r
-       watch->main_display.num_chars = 6;\r
-       watch->main_display.chars = malloc(6);\r
-       watch->main_display.segment_map = &main_segmap[0];\r
-\r
-       static const uint64_t day_segmap[] = {\r
-               0xc049c00a49890949, // Position 6\r
-               0xc048088886874707, // Position 7\r
-       };\r
-       watch->day_display.num_chars = 2;\r
-       watch->day_display.chars = malloc(2);\r
-       watch->day_display.segment_map = &day_segmap[0];\r
-\r
-       static const uint64_t date_segmap[] = {\r
-               0x4e4f0e8e8f8d4d0d, // Position 8\r
-               0xc8c4c4c8b4b4b0b, // Position 9\r
-       };\r
-       watch->date_display.num_chars = 2;\r
-       watch->date_display.chars = malloc(2);\r
-       watch->date_display.segment_map = &date_segmap[0];\r
+       watch->num_chars = 10;\r
+       watch->segment_map = &segmap[0];\r
 \r
        SEGMENT_LCD_0_init();
        slcd_sync_enable(&SEGMENT_LCD_0);
        watch->display_enabled = true;
 }\r
 \r
-void watch_display_pixel(Watch *watch, WatchDisplay display, uint8_t com, uint8_t seg) {
+void watch_display_pixel(Watch *watch, uint8_t com, uint8_t seg) {
        slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(com, seg));
 }
 \r
-void watch_clear_pixel(Watch *watch, WatchDisplay display, uint8_t com, uint8_t seg) {
+void watch_clear_pixel(Watch *watch, uint8_t com, uint8_t seg) {
        slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(com, seg));
 }
 \r
-void watch_display_character(Watch *watch, WatchDisplay display, uint8_t character, uint8_t position) {
-    uint64_t segmap = display.segment_map[position];\r
-    uint64_t segdata = Character_Set[character - 0x20];\r
-    \r
-    for (int i = 0; i < 8; i++) {\r
-           uint8_t com = (segmap & 0xFF) >> 6;\r
-           if (com > 2) {\r
+void watch_display_character(Watch *watch, uint8_t character, uint8_t position) {
+       uint64_t segmap = watch->segment_map[position];\r
+       uint64_t segdata = Character_Set[character - 0x20];\r
+\r
+       for (int i = 0; i < 8; i++) {\r
+               uint8_t com = (segmap & 0xFF) >> 6;\r
+               if (com > 2) {\r
                        // COM3 means no segment exists; skip it.\r
-                   segmap = segmap >> 8;\r
-                   segdata = segdata >> 1;\r
-                   continue;\r
-           }\r
-           uint8_t seg = segmap & 0x3F;\r
+                       segmap = segmap >> 8;\r
+                       segdata = segdata >> 1;\r
+                       continue;\r
+               }\r
+               uint8_t seg = segmap & 0x3F;\r
                slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(com, seg));
-           if (segdata & 1) slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(com, seg));\r
-           segmap = segmap >> 8;\r
-           segdata = segdata >> 1;\r
-    }\r
+               if (segdata & 1) slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(com, seg));\r
+               segmap = segmap >> 8;\r
+               segdata = segdata >> 1;\r
+       }\r
 }
 \r
-void watch_display_string(Watch *watch, WatchDisplay display, char *string) {
+void watch_display_string(Watch *watch, char *string, uint8_t position) {
        size_t i = 0;
        while(string[i] != 0) {
-               watch_display_character(watch, display, string[i], i);
+               watch_display_character(watch, string[i], position + i);
                i++;
-               if (i >= display.num_chars) break;
+               if (i >= watch->num_chars) break;
        }
 }
 \r
index 428cb15181b89e07324d636746d511def7806a74..cab19bec388f80491733e026366e2070e163bb97 100644 (file)
 #include <stdint.h>\r
 #include "hpl_calendar.h"\r
 \r
-typedef struct WatchDisplay {\r
-       uint8_t num_chars;\r
-       uint8_t* chars;\r
-       const uint64_t* segment_map;\r
-} WatchDisplay;\r
-\r
 typedef struct Watch {\r
-       struct WatchDisplay main_display; // 6 chars, main line.\r
-       struct WatchDisplay day_display;  // 2 chars, alphanumeric-ish. top center.\r
-       struct WatchDisplay date_display; // 2 chars, only supports numbers 0-39. top right.\r
-\r
        bool display_enabled;\r
        bool led_enabled;\r
        bool buzzer_enabled;\r
@@ -30,13 +20,16 @@ typedef struct Watch {
        bool i2c_enabled;\r
        bool spi_enabled;\r
        bool eic_enabled;\r
+\r
+       uint8_t num_chars;\r
+       const uint64_t* segment_map;\r
 } Watch;\r
 \r
 void watch_init(Watch *watch);\r
 \r
 void watch_enable_display(Watch *watch);
-void watch_display_pixel(Watch *watch, WatchDisplay display, uint8_t com, uint8_t seg);
-void watch_display_string(Watch *watch, WatchDisplay display, char *string);
+void watch_display_pixel(Watch *watch, uint8_t com, uint8_t seg);
+void watch_display_string(Watch *watch, char *string, uint8_t position);
 \r
 void watch_enable_led(Watch *watch);\r
 void watch_disable_led(Watch *watch);\r