altos: Add support for backlight control in ao_lco_bits
authorKeith Packard <keithp@keithp.com>
Sun, 28 Jan 2024 00:03:20 +0000 (16:03 -0800)
committerKeith Packard <keithp@keithp.com>
Thu, 1 Feb 2024 01:50:19 +0000 (17:50 -0800)
Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_lco.h
src/drivers/ao_lco_bits.c

index 50ed068acb2477040fc5630269b181c6db879a7a..42f4e6d845a2ad0a798f683e796f4211aa5a4045 100644 (file)
@@ -51,10 +51,19 @@ extern struct ao_pad_query  ao_pad_query;   /* Last received QUERY from pad */
 #define AO_LCO_BOX_FIRST       AO_LCO_BOX_DRAG
 #else
 #define AO_LCO_LCO_VOLTAGE     0               /* Box number to show LCO voltage */
+# ifdef AO_LCO_HAS_BACKLIGHT
+#   define AO_LCO_BACKLIGHT    -2
+#   ifndef AO_LCO_BOX_FIRST
+#    define AO_LCO_BOX_FIRST AO_LCO_BACKLIGHT
+#   endif
+# endif
 # ifdef AO_LCO_HAS_CONTRAST
 #  define AO_LCO_CONTRAST      -1
-#  define AO_LCO_BOX_FIRST     AO_LCO_CONTRAST
-# else
+#  ifndef AO_LCO_BOX_FIRST
+#   define AO_LCO_BOX_FIRST    AO_LCO_CONTRAST
+#  endif
+# endif
+# ifndef AO_LCO_BOX_FIRST
 #  define AO_LCO_BOX_FIRST     AO_LCO_LCO_VOLTAGE
 # endif
 #endif
@@ -75,6 +84,10 @@ ao_lco_box_pseudo(int16_t box)
 #ifdef AO_LCO_CONTRAST
        case AO_LCO_CONTRAST:
                return true;
+#endif
+#ifdef AO_LCO_BACKLIGHT
+       case AO_LCO_BACKLIGHT:
+               return true;
 #endif
        default:
                return false;
@@ -182,12 +195,20 @@ ao_lco_box_present(int16_t box);
 
 #ifdef AO_LCO_HAS_CONTRAST
 void
-ao_lco_set_contrast(int16_t contrast);
+ao_lco_set_contrast(int32_t contrast);
 
-int16_t
+int32_t
 ao_lco_get_contrast(void);
 #endif
 
+#ifdef AO_LCO_HAS_BACKLIGHT
+void
+ao_lco_set_backlight(int32_t backlight);
+
+int32_t
+ao_lco_get_backlight(void);
+#endif
+
 #ifdef AO_LCO_SEARCH_API
 
 void
index 8e9ea09bf3b63ae32fcd69025dc24572623baad0..7dd63615dcce880fcef42b87c985abd457ca23de 100644 (file)
@@ -254,15 +254,31 @@ ao_lco_step_pad(int8_t dir)
 
 #ifdef AO_LCO_HAS_CONTRAST
        if (ao_lco_box == AO_LCO_CONTRAST) {
-               int16_t contrast = ao_lco_get_contrast();
+               int32_t contrast = ao_lco_get_contrast();
 
-               contrast += (int16_t) (dir * AO_LCO_CONTRAST_STEP);
+               contrast = (contrast + AO_LCO_CONTRAST_STEP - 1) / AO_LCO_CONTRAST_STEP;
+               contrast += dir;
+               contrast *= AO_LCO_CONTRAST_STEP;
                if (contrast < AO_LCO_MIN_CONTRAST)
                        contrast = AO_LCO_MIN_CONTRAST;
                if (contrast > AO_LCO_MAX_CONTRAST)
                        contrast = AO_LCO_MAX_CONTRAST;
                ao_lco_set_contrast(contrast);
        }
+#endif
+#ifdef AO_LCO_HAS_BACKLIGHT
+       if (ao_lco_box == AO_LCO_BACKLIGHT) {
+               int32_t backlight = ao_lco_get_backlight();
+
+               backlight = (backlight + AO_LCO_BACKLIGHT_STEP - 1) / AO_LCO_BACKLIGHT_STEP;
+               backlight += dir;
+               backlight *= AO_LCO_BACKLIGHT_STEP;
+               if (backlight < AO_LCO_MIN_BACKLIGHT)
+                       backlight = AO_LCO_MIN_BACKLIGHT;
+               if (backlight > AO_LCO_MAX_BACKLIGHT)
+                       backlight = AO_LCO_MAX_BACKLIGHT;
+               ao_lco_set_backlight(backlight);
+       }
 #endif
        new_pad = (int16_t) ao_lco_pad;
        do {
@@ -297,11 +313,7 @@ ao_lco_step_box(int8_t dir)
                new_box += dir;
                if (new_box > ao_lco_max_box)
                        new_box = AO_LCO_BOX_FIRST;
-#ifdef AO_LCO_HAS_CONTRAST
-               else if (new_box < AO_LCO_CONTRAST)
-#else
-               else if (new_box < 0)
-#endif
+               else if (new_box < AO_LCO_BOX_FIRST)
                        new_box = ao_lco_max_box;
                if (new_box == ao_lco_box)
                        break;