diff options
author | Ben Connors <benconnors@outlook.com> | 2019-02-25 17:17:30 -0500 |
---|---|---|
committer | Ben Connors <benconnors@outlook.com> | 2019-02-25 17:17:30 -0500 |
commit | 9e689b32e82ed19654aa018cd2d4c5ff3576ee02 (patch) | |
tree | ecd924686b46b93245b14265a4307710d4158883 | |
parent | 3ad04193b84ded750d3acb74137d258b4597b108 (diff) |
Add curved outputs
- Prolong life, different fades
- Wrap current output
-rw-r--r-- | blc/output.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/blc/output.py b/blc/output.py index 147ea6b..dfe9a3d 100644 --- a/blc/output.py +++ b/blc/output.py @@ -1,9 +1,10 @@ """DMX module. -Defines a generic interface for a DMX interface. +Defines a generic interface for a DMX interface along with some utility interfaces. """ from abc import ABC, abstractmethod +import array class LightingOutput(ABC): """Generic lighting interface.""" @@ -40,3 +41,30 @@ class ChainedLightingOutput(LightingOutput): def __init__(self, *outputs): self.outputs = outputs self.trans_time = min((i.trans_time for i in outputs)) + +class CurvedOutput(LightingOutput): + """Class for using a custom dimmer curve. + + The given f may be a callable (which must accept integers from 0--255, inclusive) or a list + of 256 values, with f[0] representing the output at 0 and f[255] the output at 255. + """ + def set_values(self, values): + self.output.set_values(map(self.map, values)) + + def __init__(self, output, f=lambda x: x): + self.output = output + self.trans_time = output.trans_time + if callable(f): + self.curve = array.array('B', (f(i) for i in range(256))) + else: + self.curve = array.array('B', f) + self.map = lambda a: (a[0], self.curve[a[1]],) + +## Enforce that all lights remain on at 5% +LINEAR_PREHEAT = lambda x: int(243/255*x + 12) + +## Enforce that all lights stay below 95% +LINEAR_TOPSET = lambda x: int(243/255*x) + +## Enforce that all lights remain in the 5%--95% range +LINEAR_BOTH = lambda x: int(231/255*x + 12) |