diff options
| -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)  | 
