From 36d7efc37f60bfd4667ce680ae6730dc28eeac51 Mon Sep 17 00:00:00 2001 From: Marius Schiffer Date: Tue, 14 Jul 2015 15:45:07 +0200 Subject: [PATCH] Extended stripe class. --- LedD/controller.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/LedD/controller.py b/LedD/controller.py index 50b4b39..b425376 100644 --- a/LedD/controller.py +++ b/LedD/controller.py @@ -1,4 +1,5 @@ import smbus +from colour import Color PCA9685_SUBADR1 = 0x2 PCA9685_SUBADR2 = 0x3 @@ -20,6 +21,8 @@ ALLLED_OFF_L = 0xFC ALLLED_OFF_H = 0xFD + + class Controller: """ A controller controls a number of stripes. @@ -77,9 +80,23 @@ class Stripe: self.name = name self.rgb = bool(rgb) self.channels = channels + self._color = Color() + self.gamma_correct = (2.8,2.8,2.8) + self.read_color() + + def read_color(self): + self._color.rgb = [self.controller.get_channel(channel)**(1/2.8) for channel in self.channels] @classmethod def from_db(cls, controller, row): - return cls(controller, name=row["name"], rgb=row["rgb"], channels={"r": row["channel_r"], - "g": row["channel_g"], - "b": row["channel_b"]}) + return cls(controller, name=row["name"], rgb=row["rgb"], channels=(row["channel_r"],row["channel_g"],row["channel_b"])) + + def set_color(self, c): + self._color = c + for channel, gamma_correct, value in zip(self.channels, self.gamma_correct, c.rgb): + self.controller.set_channel(channel,value**gamma_correct) + + def get_color(self): + return self._color + + color = property(get_color, set_color) \ No newline at end of file