Conditions | 7 |
Total Lines | 38 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | """ |
||
19 | def callback(self): |
||
20 | # New |
||
21 | if self.__start is None: |
||
22 | self.__start = self.fixture.controller.ticker.millis_now() |
||
23 | |||
24 | offset = self.speed * self.offset # Calculate offset duration |
||
25 | delay = self.speed * self.delay # Calculate delay period after effect |
||
26 | total = self.speed + delay # Calculate total loop time (speed + delay) |
||
27 | |||
28 | start = self.__start + offset # Account for initial offset |
||
29 | since_start = self.fixture.controller.ticker.millis_now() - start # Calculate time since effect started |
||
30 | since_last = since_start % total # Calculate time since this loop started |
||
31 | |||
32 | # If in delay period |
||
33 | if since_last > self.speed: |
||
34 | self.fixture.set_channel('dimmer', 0) |
||
35 | return |
||
36 | |||
37 | # Get progress through this loop (excl delay) |
||
38 | progress = since_last / self.speed |
||
39 | |||
40 | # Ensure in range 0 <= p <= 1 |
||
41 | while progress > 1: |
||
42 | progress = progress - 1 |
||
43 | while progress < 0: |
||
44 | progress = 1 + progress |
||
45 | |||
46 | # Flip half way through |
||
47 | progress *= 2 |
||
48 | if progress > 1: |
||
49 | progress = 1 - (progress - 1) |
||
50 | |||
51 | # Ensure we reach 100% |
||
52 | if progress >= 0.95: |
||
53 | progress = 1 |
||
54 | |||
55 | # Apply dimmer |
||
56 | self.fixture.set_channel('dimmer', int(255 * progress)) |
||
57 | |||
61 |