Пример #1
0
    def configure_light(self, number, subtype, platform_settings) -> LightPlatformInterface:
        """Configure light in platform."""
        if not self.net_connection:
            raise AssertionError('A request was made to configure a FAST Light, '
                                 'but no connection to a NET processor is '
                                 'available')
        if subtype == "gi":
            return FASTGIString(number, self.net_connection.send, self.machine,
                                int(1 / self.machine.config['mpf']['default_light_hw_update_hz'] * 1000))
        if subtype == "matrix":
            return FASTMatrixLight(number, self.net_connection.send, self.machine,
                                   int(1 / self.machine.config['mpf']['default_light_hw_update_hz'] * 1000), self)
        if not subtype or subtype == "led":
            if not self.flag_led_tick_registered:
                # Update leds every frame
                self._led_task = self.machine.clock.schedule_interval(
                    self.update_leds, 1 / self.machine.config['mpf']['default_light_hw_update_hz'])
                self.flag_led_tick_registered = True

            number_str, channel = number.split("-")
            if number_str not in self.fast_leds:
                self.fast_leds[number_str] = FASTDirectLED(
                    number_str, int(self.config['hardware_led_fade_time']))
            fast_led_channel = FASTDirectLEDChannel(self.fast_leds[number_str], channel)

            return fast_led_channel

        raise AssertionError("Unknown subtype {}".format(subtype))
Пример #2
0
    def configure_led(self, config: dict, channels: int):
        """Configure a WS2812 LED.

        Args:
            config: LED config.
            channels: Number of channels (3 for RGB)

        Returns: LED object.

        """
        if channels > 3:
            raise AssertionError("FAST only supports RGB LEDs")
        if not self.rgb_connection:
            raise AssertionError('A request was made to configure a FAST LED, '
                                 'but no connection to an LED processor is '
                                 'available')

        if not self.flag_led_tick_registered:
            # Update leds every frame
            self.machine.clock.schedule_interval(
                self.update_leds,
                1 / self.machine.config['mpf']['default_led_hw_update_hz'])
            self.flag_led_tick_registered = True

        # if the LED number is in <channel> - <led> format, convert it to a
        # FAST hardware number
        if '-' in str(config['number']):
            num = str(config['number']).split('-')
            number = Util.int_to_hex_string((int(num[0]) * 64) + int(num[1]))
        else:
            number = self.convert_number_from_config(config['number'])

        this_fast_led = FASTDirectLED(number)
        self.fast_leds.add(this_fast_led)

        return this_fast_led