]> git.earman.xyz Git - sensor-watch.git/commitdiff
segment lcd: add indicator methods, document character map
authorJoey Castillo <jose.castillo@gmail.com>
Sat, 7 Aug 2021 15:22:49 +0000 (11:22 -0400)
committerJoey Castillo <jose.castillo@gmail.com>
Sat, 7 Aug 2021 15:22:49 +0000 (11:22 -0400)
Sensor Watch BME280 Project/app.c
watch-library/watch/watch.c
watch-library/watch/watch.h

index e84e5760e0b3b201a9fde1b920341f2d89316aef..9053ca650a4ffff398dde3098204e9e6fe8b653c 100644 (file)
@@ -114,7 +114,7 @@ bool app_loop() {
             temperature = read_temperature(NULL);
             sprintf(buf, "TE  %4.1f#C", temperature);
             watch_display_string(buf, 0);
-            watch_clear_pixel(1, 16);
+            watch_clear_colon();
             break;
         case MODE_HUMIDITY:
             // take one reading
@@ -126,7 +126,7 @@ bool app_loop() {
             humidity = read_humidity(t_fine);
             sprintf(buf, "HU  rH %3d", (int)humidity);
             watch_display_string(buf, 0);
-            watch_set_pixel(1, 16);
+            watch_set_colon();
             break;
         case MODE_OFF:
             watch_display_string("    Sleep ", 0);
index 6931a73a6fa1fb31c89159c19c311238bd9a7c8e..5d046925f7e013f498e8680d037a232213a15643 100644 (file)
@@ -22,20 +22,20 @@ void _watch_init() {
 static const uint8_t Character_Set[] =
 {
     0b00000000, //  
-    0b00000000, // !
+    0b00000000, // ! (unused)
     0b00100010, // "
     0b01100011, // # (degree symbol, hash mark doesn't fit)
-    0b00000000, // $
-    0b00000000, // %
-    0b01000100, // &
+    0b00000000, // $ (unused)
+    0b00000000, // % (unused)
+    0b01000100, // & ("lowercase 7" for positions 4 and 6)
     0b00100000, // '
-    0b00000000, // (
-    0b00000000, // )
-    0b00000000, // *
-    0b11000000, // +
+    0b00111001, // (
+    0b00001111, // )
+    0b00000000, // * (unused)
+    0b11000000, // + (only works in position 0)
     0b00000100, // ,
     0b01000000, // -
-    0b01000000, // .
+    0b01000000, // . (same as -, semantically most useful)
     0b00010010, // /
     0b00111111, // 0
     0b00000110, // 1
@@ -47,13 +47,13 @@ static const uint8_t Character_Set[] =
     0b00000111, // 7
     0b01111111, // 8
     0b01101111, // 9
-    0b00000000, // :
-    0b00000000, // ;
+    0b00000000, // : (unused)
+    0b00000000, // ; (unused)
     0b01011000, // <
     0b01001000, // =
     0b01001100, // >
     0b01010011, // ?
-    0b11111111, // @
+    0b11111111, // @ (all segments on)
     0b01110111, // A
     0b01111111, // B
     0b00111001, // C
@@ -64,7 +64,7 @@ static const uint8_t Character_Set[] =
     0b01110110, // H
     0b10001001, // I
     0b00001110, // J
-    0b11101010, // K
+    0b01110101, // K
     0b00111000, // L
     0b10110111, // M
     0b00110111, // N
@@ -83,7 +83,7 @@ static const uint8_t Character_Set[] =
     0b00111001, // [
     0b00100100, // backslash
     0b00001111, // ]
-    0b00100110, // ^
+    0b00100011, // ^
     0b00001000, // _
     0b00000010, // `
     0b01011111, // a
@@ -133,16 +133,24 @@ static const uint64_t Segment_Map[] = {
 
 static const uint8_t Num_Chars = 10;
 
+static const uint32_t IndicatorSegments[6] = {
+    SLCD_SEGID(0, 17), // WATCH_INDICATOR_SENSING
+    SLCD_SEGID(0, 16), // WATCH_INDICATOR_BELL
+    SLCD_SEGID(2, 17), // WATCH_INDICATOR_PM
+    SLCD_SEGID(2, 16), // WATCH_INDICATOR_24H
+    SLCD_SEGID(1, 10), // WATCH_INDICATOR_LAP
+};
+
 void watch_enable_display() {
     SEGMENT_LCD_0_init();
     slcd_sync_enable(&SEGMENT_LCD_0);
 }
 
-void watch_set_pixel(uint8_t com, uint8_t seg) {
+inline void watch_set_pixel(uint8_t com, uint8_t seg) {
     slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(com, seg));
 }
 
-void watch_clear_pixel(uint8_t com, uint8_t seg) {
+inline void watch_clear_pixel(uint8_t com, uint8_t seg) {
     slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(com, seg));
 }
 
@@ -175,6 +183,31 @@ void watch_display_string(char *string, uint8_t position) {
     }
 }
 
+inline void watch_set_colon() {
+    slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(1, 16));
+}
+
+inline void watch_clear_colon() {
+    slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(1, 16));
+}
+
+inline void watch_set_indicator(WatchIndicatorSegment indicator) {
+    slcd_sync_seg_on(&SEGMENT_LCD_0, IndicatorSegments[indicator]);
+}
+
+inline void watch_clear_indicator(WatchIndicatorSegment indicator) {
+    slcd_sync_seg_off(&SEGMENT_LCD_0, IndicatorSegments[indicator]);
+}
+
+void watch_clear_all_indicators() {
+    slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(2, 17));
+    slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(2, 16));
+    slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(0, 17));
+    slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(0, 16));
+    slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(1, 10));
+}
+
+
 //////////////////////////////////////////////////////////////////////////////////////////
 // Buttons
 
index c842d727a04e56776eb2ca468add8a87789e5050..0f70890cdf7ac2dbbdca00e55181f40026b20d0b 100644 (file)
@@ -108,6 +108,15 @@ void _watch_init();
   *        for displaying strings of characters and indicators on the main watch display.
   */
 /// @{
+
+typedef enum WatchIndicatorSegment {
+    WATCH_INDICATOR_SENSING = 0,
+    WATCH_INDICATOR_BELL,
+    WATCH_INDICATOR_PM,
+    WATCH_INDICATOR_24H,
+    WATCH_INDICATOR_LAP
+} WatchIndicatorSegment;
+
 /** @brief Enables the Segment LCD display.
   * Call this before attempting to set pixels or display strings.
   */
@@ -122,7 +131,6 @@ void watch_set_pixel(uint8_t com, uint8_t seg);
 /** @brief Clears a pixel. Use this to manually clear a pixel with a given common and segment number.
   * @param com the common pin, numbered from 0-2.
   * @param seg the segment pin, numbered from 0-23.
-  * Use this to manually set a pixel with a common and a segment number.
   */
 void watch_clear_pixel(uint8_t com, uint8_t seg);
 
@@ -136,6 +144,30 @@ void watch_clear_pixel(uint8_t com, uint8_t seg);
           position 0, positions 2-9 will retain whatever state they were previously displaying.
   */
 void watch_display_string(char *string, uint8_t position);
+
+/** @brief Turns the colon segment on.
+  */
+void watch_set_colon();
+
+/** @brief Turns the colon segment off.
+  */
+void watch_clear_colon();
+
+/** @brief Sets an indicator on the LCD. Use this to turn on one of the indicator segments.
+  * @param indicator One of the indicator segments from the enum. @see WatchIndicatorSegment
+  */
+void watch_set_indicator(WatchIndicatorSegment indicator);
+
+/** @brief Clears an indicator on the LCD. Use this to turn off one of the indicator segments.
+  * @param indicator One of the indicator segments from the enum. @see WatchIndicatorSegment
+  */
+void watch_clear_indicator(WatchIndicatorSegment indicator);
+
+/** @brief Clears all indicator segments.
+  * @see WatchIndicatorSegment
+  */
+void watch_clear_all_indicators();
+
 /// @}