Ejemplo n.º 1
0
    def _get_brightness_and_fade(self, max_fade_ms: int, color: str, *, current_time=None) -> Tuple[float, int, bool]:
        uncorrected_color, fade_ms, done = self._get_color_and_fade(self.stack, max_fade_ms, current_time=current_time)
        corrected_color = self.gamma_correct(uncorrected_color)
        corrected_color = self.color_correct(corrected_color)

        if color in ["red", "blue", "green"]:
            brightness = getattr(corrected_color, color) / 255.0
        elif color == "white":
            brightness = min(corrected_color.red, corrected_color.green, corrected_color.blue) / 255.0
        else:
            raise ColorException("Invalid color {}".format(color))
        return brightness, fade_ms, done
Ejemplo n.º 2
0
    def _schedule_update(self):
        start_color, start_time, target_color, target_time = self._get_color_and_target_time(
            self.stack)

        # check if our fade target really changed
        if (start_color, start_time, target_color,
                target_time) == self._last_fade_target:
            # nope its the same -> nothing to do
            return

        if self._last_fade_target and target_color == self._last_fade_target[2] and \
                (self._last_fade_target[3] < 0 or self._last_fade_target[3] < self.machine.clock.get_time()):
            # last fade had the same target and finished already -> nothing to do
            return

        self._last_fade_target = (start_color, start_time, target_color,
                                  target_time)

        if start_color != target_color:
            start_color = self.color_correct(self.gamma_correct(start_color))
            target_color = self.color_correct(self.gamma_correct(target_color))
        else:
            start_color = self.color_correct(self.gamma_correct(start_color))
            target_color = start_color

        for color, drivers in self.hw_drivers.items():
            if color in ["red", "blue", "green"]:
                start_brightness = getattr(start_color, color) / 255.0
                target_brightness = getattr(target_color, color) / 255.0
            elif color == "white":
                start_brightness = min(start_color.red, start_color.green,
                                       start_color.blue) / 255.0
                target_brightness = min(target_color.red, target_color.green,
                                        target_color.blue) / 255.0
            else:
                raise ColorException("Invalid color {}".format(color))
            for driver in drivers:
                driver.set_fade(start_brightness, start_time,
                                target_brightness, target_time)

        for platform in self.platforms:
            platform.light_sync()