<gh_stars>1-10
"""Contains classes that pertain to anything light related."""

from rpi_ws281x import Color, ws, PixelStrip
import os
import time


class BACKLIGHT():
    def __init__(self, count=7, pin=10):
        """
        At instantiation, define the following defaults.

        Parameters
        ----------
        count : int, optional
            The number of LEDs on the Neopixel board. The Jewel has 7.
        pin : int, optional
            The pin for communicating with the Neopixels. The default is 10.

        Returns
        -------
        None.

        """
        self.count = count
        self.pin = pin
        self.frequency = 800000
        self.dma = 10
        self.invert = False
        self.channel = 0
        self.brightness = 255
        self.strip = ws.SK6812W_STRIP
        self.tracker = {}  # This is used as a holder for NeoPixel values.

    def initialize(self):
        """
        Initialize the LEDs.

        Returns
        -------
        None.

        """
        self.leds = PixelStrip(self.count, self.pin, self.frequency,
                               self.dma, self.invert, self.brightness,
                               self.channel, self.strip)
        self.leds.begin()

    def set_led(self, position, R, G, B, W):
        """
        Set a single LED to an RGBW state.

        Parameters
        ----------
        position : int
            The position of the LED.
        R : int, 0-255
            The red value.
        G : int, 0-255
            The green value.
        B : int, 0-255
            The blue value.
        W : int, 0-255
            The white value.

        Returns
        -------
        None.

        """
        self.leds.setPixelColor(position, Color(R, G, B, W))
        self.leds.show()
        self.tracker[position] = [R, G, B, W]
        time.sleep(0.05)

    def set_leds(self, R=0, G=0, B=0, W=255):
        """
        Set all of the LEDs on the board to an RGBW value.

        Parameters
        ----------
        position : int
            The position of the LED.
        R : int, 0-255
            The red value.
        G : int, 0-255
            The green value.
        B : int, 0-255
            The blue value.
        W : int, 0-255
            The white value.

        Returns
        -------
        None.

        """
        for position in range(self.count):
            self.leds.setPixelColor(position, Color(R, G, B, W))
            self.tracker[position] = [R, G, B, W]
        self.leds.show()
        time.sleep(0.05)

    def reset(self):
        """
        Reset the LEDs if new settings did not take.

        Returns
        -------
        None.

        """
        self.initialize()
        for position in range(self.count):
            R = self.tracker[position][0]
            G = self.tracker[position][1]
            B = self.tracker[position][2]
            W = self.tracker[position][3]
            self.leds.setPixelColor(position, Color(R, G, B, W))
        self.leds.show()
        time.sleep(0.05)

    def off(self):
        """
        Turn off the LEDs. It is not clear if they still draw power after
        they are set to zero.

        Returns
        -------
        None.

        """
        self.brightness = 0
        self.set_leds(0, 0, 0, 0)
        self.reset()


class BOARD():
    def __init__(self):
        self._trigger = "echo none /sys/class/leds/led0/trigger"
        self._off = "echo 0>/sys/class/leds/led0/brightness"
        self._on = "echo 1>/sys/class/leds/led0/brightness"

    def off(self):
        os.system(self._trigger)
        os.system(self._off)

    def on(self):
        os.system(self._trigger)
        os.system(self._on)

"""Contains classes that pertain to anything light related."""

from rpi_ws281x import Color, ws, PixelStrip
import os
import time


class BACKLIGHT():
    def __init__(self, count=7, pin=10):
        """
        At instantiation, define the following defaults.

        Parameters
        ----------
        count : int, optional
            The number of LEDs on the Neopixel board. The Jewel has 7.
        pin : int, optional
            The pin for communicating with the Neopixels. The default is 10.

        Returns
        -------
        None.

        """
        self.count = count
        self.pin = pin
        self.frequency = 800000
        self.dma = 10
        self.invert = False
        self.channel = 0
        self.brightness = 255
        self.strip = ws.SK6812W_STRIP
        self.tracker = {}  # This is used as a holder for NeoPixel values.

    def initialize(self):
        """
        Initialize the LEDs.

        Returns
        -------
        None.

        """
        self.leds = PixelStrip(self.count, self.pin, self.frequency,
                               self.dma, self.invert, self.brightness,
                               self.channel, self.strip)
        self.leds.begin()

    def set_led(self, position, R, G, B, W):
        """
        Set a single LED to an RGBW state.

        Parameters
        ----------
        position : int
            The position of the LED.
        R : int, 0-255
            The red value.
        G : int, 0-255
            The green value.
        B : int, 0-255
            The blue value.
        W : int, 0-255
            The white value.

        Returns
        -------
        None.

        """
        self.leds.setPixelColor(position, Color(R, G, B, W))
        self.leds.show()
        self.tracker[position] = [R, G, B, W]
        time.sleep(0.05)

    def set_leds(self, R=0, G=0, B=0, W=255):
        """
        Set all of the LEDs on the board to an RGBW value.

        Parameters
        ----------
        position : int
            The position of the LED.
        R : int, 0-255
            The red value.
        G : int, 0-255
            The green value.
        B : int, 0-255
            The blue value.
        W : int, 0-255
            The white value.

        Returns
        -------
        None.

        """
        for position in range(self.count):
            self.leds.setPixelColor(position, Color(R, G, B, W))
            self.tracker[position] = [R, G, B, W]
        self.leds.show()
        time.sleep(0.05)

    def reset(self):
        """
        Reset the LEDs if new settings did not take.

        Returns
        -------
        None.

        """
        self.initialize()
        for position in range(self.count):
            R = self.tracker[position][0]
            G = self.tracker[position][1]
            B = self.tracker[position][2]
            W = self.tracker[position][3]
            self.leds.setPixelColor(position, Color(R, G, B, W))
        self.leds.show()
        time.sleep(0.05)

    def off(self):
        """
        Turn off the LEDs. It is not clear if they still draw power after
        they are set to zero.

        Returns
        -------
        None.

        """
        self.brightness = 0
        self.set_leds(0, 0, 0, 0)
        self.reset()


class BOARD():
    def __init__(self):
        self._trigger = "echo none /sys/class/leds/led0/trigger"
        self._off = "echo 0>/sys/class/leds/led0/brightness"
        self._on = "echo 1>/sys/class/leds/led0/brightness"

    def off(self):
        os.system(self._trigger)
        os.system(self._off)

    def on(self):
        os.system(self._trigger)
        os.system(self._on)
Contains classes that pertain to anything light related. At instantiation, define the following defaults.          Parameters         ----------         count : int, optional             The number of LEDs on the Neopixel board. The Jewel has 7.         pin : int, optional             The pin for communicating with the Neopixels. The default is 10.          Returns         -------         None. # This is used as a holder for NeoPixel values. Initialize the LEDs.          Returns         -------         None. Set a single LED to an RGBW state.          Parameters         ----------         position : int             The position of the LED.         R : int, 0-255             The red value.         G : int, 0-255             The green value.         B : int, 0-255             The blue value.         W : int, 0-255             The white value.          Returns         -------         None. Set all of the LEDs on the board to an RGBW value.          Parameters         ----------         position : int             The position of the LED.         R : int, 0-255             The red value.         G : int, 0-255             The green value.         B : int, 0-255             The blue value.         W : int, 0-255             The white value.          Returns         -------         None. Reset the LEDs if new settings did not take.          Returns         -------         None. Turn off the LEDs. It is not clear if they still draw power after         they are set to zero.          Returns         -------         None.