def step(self): if self._pulse_time is None: return pulse_dt = min( ((time.monotonic_ns() - self._pulse_time) / 1000000000) / 0.2, 1.0) self._led[0] = ( int(_utils.lerp(255, self._hue_rgb[0], pulse_dt)), int(_utils.lerp(255, self._hue_rgb[1], pulse_dt)), int(_utils.lerp(255, self._hue_rgb[2], pulse_dt)), ) if pulse_dt == 1.0: self._pulse_time = None
def _calculate_stop_phase_level(self, start_phase_level, now): release_s = self.release * _NS_TO_S if release_s == 0: release_percent = 1.0 else: release_percent = (now - self._release_time) / release_s return _utils.lerp(start_phase_level, 0, min(release_percent, 1.0))
def output(self): if self._target is None: return 0 now = time.monotonic_ns() rate_s = self.rate * _NS_TO_S delta = min(1.0, (now - self._set_time) / rate_s) return _utils.lerp(self._last, self._target, delta)
def _calculate_start_phase_level(self, now): attack_s = self.attack * _NS_TO_S attack_end = self._trigger_time + attack_s if attack_s == 0: attack_percent = 1.1 # No attack phase else: attack_percent = (now - self._trigger_time) / attack_s decay_s = self.decay * _NS_TO_S if decay_s == 0: decay_percent = 1.0 else: decay_percent = (now - attack_end) / decay_s if attack_percent <= 1.0: return _utils.lerp(0, 1.0, attack_percent) elif decay_percent >= 0.0: return _utils.lerp(1.0, self.sustain, min(decay_percent, 1.0))