altos/telelco-v3.0: Show backlight/contrast value as percent
authorKeith Packard <keithp@keithp.com>
Sun, 28 Jan 2024 07:13:17 +0000 (23:13 -0800)
committerKeith Packard <keithp@keithp.com>
Thu, 1 Feb 2024 01:50:19 +0000 (17:50 -0800)
Provide a bit more feedback about the setting.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/telelco-v3.0/Makefile
src/telelco-v3.0/ao_lco_v3.c

index 55de1b231af0ddfa7845569627a1cabd4dcf5dc9..cc17a2219b723f5245f80e66cd3789dc3991b838 100644 (file)
@@ -66,6 +66,7 @@ ALTOS_SRC = \
        ao_st7565.c \
        ao_rect.c \
        ao_text.c \
+       ao_text_width.c \
        ao_box.c \
        ao_copy.c \
        ao_blt.c \
index 2055701b7eb48f7c1a5b27b45d67a6909e7195c3..dbee0bc2ed269223195ca8bad6a236c797c6a0d1 100644 (file)
@@ -75,11 +75,15 @@ static const struct ao_transform show_transform = {
 #define CONTRAST_X     (WIDTH - CONTRAST_WIDTH) / 2
 #define CONTRAST_Y     20
 #define CONTRAST_HEIGHT        20
+#define CONTRAST_VALUE_X       64
+#define CONTRAST_VALUE_Y       (CONTRAST_Y + CONTRAST_HEIGHT + SMALL_FONT.ascent + 3)
 #define BACKLIGHT_LABEL_X      37
 #define BACKLIGHT_WIDTH        100
 #define BACKLIGHT_X    (WIDTH - BACKLIGHT_WIDTH) / 2
 #define BACKLIGHT_Y    20
 #define BACKLIGHT_HEIGHT       20
+#define BACKLIGHT_VALUE_X      64
+#define BACKLIGHT_VALUE_Y      (BACKLIGHT_Y + BACKLIGHT_HEIGHT + SMALL_FONT.ascent + 3)
 #define INFO_START_Y   ((int16_t) (SMALL_FONT.ascent + 2))
 #define INFO_STEP_Y    ((int16_t) (SMALL_FONT.ascent + 3))
 
@@ -142,21 +146,33 @@ _ao_lco_batt_voltage(void)
 static void
 _ao_lco_show_contrast(void)
 {
+       char buf[8];
        uint8_t brightness = ao_st7565_get_brightness();
        int16_t contrast = (int16_t) (brightness * CONTRAST_WIDTH / AO_LCO_MAX_CONTRAST);
+       int16_t width;
 
        ao_text(&fb, &SMALL_FONT, CONTRAST_LABEL_X, LABEL_Y, "Contrast", AO_BLACK, AO_COPY);
        ao_rect(&fb, CONTRAST_X, CONTRAST_Y, contrast, CONTRAST_HEIGHT, AO_BLACK, AO_COPY);
+       /* this "knows" that CONTRAST_WIDTH == 100 */
+       snprintf(buf, sizeof(buf), "%d %%", contrast);
+       width = ao_text_width(&SMALL_FONT, buf);
+       ao_text(&fb, &SMALL_FONT, BACKLIGHT_VALUE_X - width / 2, BACKLIGHT_VALUE_Y, buf, AO_BLACK, AO_COPY);
 }
 
 static void
 _ao_lco_show_backlight(void)
 {
+       char buf[8];
        int32_t backlight = ao_lco_get_backlight();
        int16_t value = (int16_t) (backlight * BACKLIGHT_WIDTH / AO_LCO_MAX_BACKLIGHT);
+       int16_t width;
 
        ao_text(&fb, &SMALL_FONT, BACKLIGHT_LABEL_X, LABEL_Y, "Backlight", AO_BLACK, AO_COPY);
        ao_rect(&fb, BACKLIGHT_X, BACKLIGHT_Y, value, BACKLIGHT_HEIGHT, AO_BLACK, AO_COPY);
+       /* this "knows" that BACKLIGHT_WIDTH == 100 */
+       snprintf(buf, sizeof(buf), "%d %%", value);
+       width = ao_text_width(&SMALL_FONT, buf);
+       ao_text(&fb, &SMALL_FONT, BACKLIGHT_VALUE_X - width / 2, BACKLIGHT_VALUE_Y, buf, AO_BLACK, AO_COPY);
 }
 
 static int16_t info_y;