def run(self, refresh_rate_microseconds):
        """Mainloop to update the effects and LEDs

        Arguments:
            refresh_rate_microseconds {[float]} -- [Delay in the Mainloop to limit the refresh rate]
        """

        log.info("EFFECT_HANDLER", "Loop started")

        while True:
            try:
                if self.current_effect != None:
                    isFinished = self.current_effect.update()
                    self.current_effect.tile_collection.apply_to_real_tile_collection(
                    )

                    if self.transition_running and isFinished:
                        self.current_effect = self.next_effects.pop(0)
                        self.transition_running = False

                self.neopixel.show()
                time.sleep_ms(refresh_rate_microseconds)

            except Exception as e:
                log.exception("EFFECT_HANDLER", e)
    def set_effect(self, effect_name, options):
        """Sets the current effect with the given options, while doing a transition between the current effect and this new one

        Arguments:
            effect_name {[str]} -- [Name of the effect]
            options {[dict]} -- [Options to configure the effect]
        """

        virtual_tile_collection = self.tile_collection.create_virtual_tile_collection(
        )

        if effect_name == "strobe":
            effect = Strobe(virtual_tile_collection, **options)
        elif effect_name == "fade":
            effect = Fade(virtual_tile_collection, **options)
        elif effect_name == "color":
            effect = Color(virtual_tile_collection, **options)
        elif effect_name == "highlight":
            effect = Highlight(virtual_tile_collection, **options)
        elif effect_name == "swap":
            effect = Swap(virtual_tile_collection, **options)
        elif effect_name == "explode":
            effect = Explode(virtual_tile_collection, **options)
        elif effect_name == "slide":
            effect = Slide(virtual_tile_collection, **options)

        self.next_effects.append(effect)
        log.info("EFFECT_HANDLER", "Added new effect")

        self.do_transition("fade")
Example #3
0
    def __init__(self):
        self.message_buffer = []

        self.uart = machine.UART(1, tx=17, rx=16, parity=1, buffer_size=4096)
        self.uart.init(parity=1, buffer_size=4096)
        log.info("SERIAL", "Initialized")

        self.uart.callback(self.uart.CBTYPE_PATTERN,
                           self.on_data_receive,
                           pattern="[SEG]")

        self.callbacks = {}
    def __init__(self, neopixel, tile_collection):
        """Initializes the Effect Handler and sets the current effect to a static black (off)

        Arguments:
            neopixel {[Neopixel]} -- [The base neopixel object of the LED strip]
            tile_collection {[TileCollection]} -- [A Tile Collection Object]
        """

        self.neopixel = neopixel
        self.tile_collection = tile_collection
        virtual_tile_collection = self.tile_collection.create_virtual_tile_collection(
        )
        self.current_effect = Color(virtual_tile_collection, (0, 0, 0))
        self.next_effects = []
        self.transition_running = False

        log.info("EFFECT_HANDLER", "Initialized")
Example #5
0
    def on_data_receive(self, data_container):
        data = data_container[2]

        log.info("SERIAL", "Segment received")
        log.debug("SERIAL", "Segment: {}".format(data))

        self.message_buffer.append(data)

        message_buffer_string = "".join(self.message_buffer)

        for tag, callback in self.callbacks.items():
            if message_buffer_string.endswith("[{}]".format(tag)):
                data_string = remove_suffix(message_buffer_string,
                                            "[{}]".format(tag))

                log.info("SERIAL", "Complete Message received")
                log.debug("SERIAL",
                          "Message: {} - Tag: {}".format(data_string, tag))

                self.message_buffer = []
                callback(data_string)
    def do_transition(self, transition_name, options={}):
        """Creates a transition between the currently running effect and the next effect

        Arguments:
            transition_name {[str]} -- [Name of the transition (currently only fade)]

        Keyword Arguments:
            options {dict} -- [Options to configure the transition] (default: {{}})
        """

        virtual_tile_collection = self.tile_collection.create_virtual_tile_collection(
        )

        if transition_name == "fade":
            self.current_effect = FadeTransition(virtual_tile_collection,
                                                 self.current_effect,
                                                 self.next_effects[0],
                                                 **options)

            self.transition_running = True
            log.info("EFFECT_HANDLER", "Transition started")
    def handle_led_options(self, led_options):
        """Controls the the current effect, brightness and LED count.
        Mainly used as serial input callback to control the strip.

        Arguments:
            led_options {[dict/str]} -- [JSON string or dict of the options to apply]
        """

        if isinstance(led_options, str):
            led_options = json.loads(led_options)

        action = led_options["action"]
        data = led_options["data"]

        log.debug("EFFECT_HANDLER", "LED-Options: {}".format(led_options))

        if action == "led_options":
            if "brightness" in data.keys():
                log.info("EFFECT_HANDLER", "Change brightness")
                self.set_brightness(data["brightness"])

            if "active_led_count" in data.keys():
                log.info("EFFECT_HANDLER", "Set active led count")
                self.set_active_led_count(data["active_led_count"])

        elif action == "current_effect":
            log.info("EFFECT_HANDLER", "Set new effect")
            self.set_effect(data["effect_name"], data["options"])

        else:
            log.warning("EFFECT_HANDLER", "Unknown LED option")
Example #8
0
from lib.tools import log
import machine
from lib.tools import color
from lib.light_object import LightObject
from lib.tile import Tile
from lib.tile_collection import TileCollection
from effect_handler import EffectHandler
import gc
from serial import Serial

log.info("MAIN", "Libraries loaded. Initializing ...")

gc.threshold(70000)
machine.freq(240000000)

led_data_power_control = machine.Pin(19, machine.Pin.OUT)
led_data_power_control.value(1)

neopixel = machine.Neopixel(machine.Pin(5), 300, machine.Neopixel.TYPE_RGBW)

color.np = neopixel
neopixel.clear()
neopixel.brightness(255)

tiles = []

xy = [(0, 1), (1, 1), (2, 1), (3, 1), (4, 1),
      (4, 0), (5, 0), (6, 0), (6, 1), (1, 12)]

for i in range(len(xy)):
    tiles.append(Tile(xy[i][0], xy[i][1], LightObject(
Example #9
0
from lib.tools import log

log.info("MAIN", "Started. Loading Libraries ...")