]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/commitdiff
implemented basic backlight functionality
authorMelissa LeBlanc-Williams <melissa@adafruit.com>
Wed, 10 Jun 2020 00:13:09 +0000 (17:13 -0700)
committerMelissa LeBlanc-Williams <melissa@adafruit.com>
Wed, 10 Jun 2020 00:13:09 +0000 (17:13 -0700)
displayio/display.py

index 10ccf4ecaa34c84084310097418a0c97aa2ffa5e..c5a82a350aafb1c2c4a760c3d6c41e9ec80336f3 100644 (file)
@@ -38,6 +38,7 @@ displayio for Blinka
 import time
 import struct
 import threading
+import digitalio
 from PIL import Image
 import numpy
 from recordclass import recordclass
@@ -48,6 +49,9 @@ __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git"
 Rectangle = recordclass("Rectangle", "x1 y1 x2 y2")
 displays = []
 
+BACKLIGHT_IN_OUT = 1
+BACKLIGHT_PWM = 2
+
 # pylint: disable=unnecessary-pass, unused-argument
 
 # pylint: disable=too-many-instance-attributes
@@ -137,7 +141,7 @@ class Display:
         self._rowstart = rowstart
         self._rotation = rotation
         self._auto_brightness = auto_brightness
-        self._brightness = brightness
+        self._brightness = 1.0
         self._auto_refresh = auto_refresh
         self._initialize(init_sequence)
         self._buffer = Image.new("RGB", (width, height))
@@ -149,6 +153,13 @@ class Display:
         if self._auto_refresh:
             self.auto_refresh = True
 
+        self._backlight_type = None
+        if backlight_pin is not None:
+            self._backlight_type = BACKLIGHT_IN_OUT
+            self._backlight = digitalio.DigitalInOut(backlight_pin)
+            self._backlight.switch_to_output()
+            self.brightness = brightness
+
     # pylint: enable=too-many-locals
 
     def _initialize(self, init_sequence):
@@ -331,7 +342,15 @@ class Display:
 
     @brightness.setter
     def brightness(self, value):
-        self._brightness = value
+        print("Brightness set")
+        if 0 <= float(value) <= 1.0:
+            self._brightness = value
+            if self._backlight_type == BACKLIGHT_IN_OUT:
+                self._backlight.value = int(round(self._brightness))
+                print(int(round(self._brightness)))
+            # PWM not currently implemented
+        else:
+            raise ValueError("Brightness must be between 0.0 and 1.0")
 
     @property
     def auto_brightness(self):