Example #1
0
    def rgb(self, red, green=None, blue=None, transitiontime=5):
        if isinstance(red, basestring):
            # assume a hex string is passed
            rstring = red
            red = int(rstring[1:3], 16)
            green = int(rstring[3:5], 16)
            blue = int(rstring[5:], 16)

        print red, green, blue

        # We need to convert the RGB value to Yxy.
        redScale = float(red) / 255.0
        greenScale = float(green) / 255.0
        blueScale = float(blue) / 255.0
        colormodels.init(
            phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
            phosphor_green=colormodels.xyz_color(0.4091, 0.518),
            phosphor_blue=colormodels.xyz_color(0.167, 0.04))
        # logger.debug(redScale, greenScale, blueScale)
        xyz = colormodels.irgb_color(red, green, blue)
        # logger.debug(xyz)
        xyz = colormodels.xyz_from_rgb(xyz)
        # logger.debug(xyz)
        xyz = colormodels.xyz_normalize(xyz)
        # logger.debug(xyz)

        return self.set_state(
            {"xy": [xyz[0], xyz[1]], "transitiontime": transitiontime})
Example #2
0
    def rgb(self, red, green=None, blue=None, transitiontime=5):
        if isinstance(red, basestring):
            # assume a hex string is passed
            rstring = red
            red = int(rstring[1:3], 16)
            green = int(rstring[3:5], 16)
            blue = int(rstring[5:], 16)

        print red, green, blue

        # We need to convert the RGB value to Yxy.
        redScale = float(red) / 255.0
        greenScale = float(green) / 255.0
        blueScale = float(blue) / 255.0
        colormodels.init(phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
                         phosphor_green=colormodels.xyz_color(0.4091, 0.518),
                         phosphor_blue=colormodels.xyz_color(0.167, 0.04))
        logger.debug(redScale, greenScale, blueScale)
        xyz = colormodels.irgb_color(red, green, blue)
        logger.debug(xyz)
        xyz = colormodels.xyz_from_rgb(xyz)
        logger.debug(xyz)
        xyz = colormodels.xyz_normalize(xyz)
        logger.debug(xyz)

        return self.set_state({
            "xy": [xyz[0], xyz[1]],
            "transitiontime": transitiontime
        })
Example #3
0
def test_rgb_irgb(verbose=1):
    '''Test that conversions between rgb and irgb are invertible.'''
    for i in range(0, 100):
        ir = random.randrange(0, 256)
        ig = random.randrange(0, 256)
        ib = random.randrange(0, 256)
        irgb0 = colormodels.irgb_color(ir, ig, ib)
        rgb0 = colormodels.rgb_from_irgb(irgb0)
        irgb1 = colormodels.irgb_from_rgb(rgb0)
        rgb1 = colormodels.rgb_from_irgb(irgb1)
        if (irgb0[0] != irgb1[0]) or (irgb0[1] != irgb1[1]) or (irgb0[2] !=
                                                                irgb1[2]):
            msg = 'irgb0 %s and irgb1 %s do not match' % (str(irgb0),
                                                          str(irgb1))
            raise ValueError(msg)
        tolerance = 1.0e-14
        err_rgb = rgb1 - rgb0
        err_r = math.fabs(err_rgb[0])
        err_g = math.fabs(err_rgb[1])
        err_b = math.fabs(err_rgb[2])
        if (err_r > tolerance) or (err_g > tolerance) or (err_b > tolerance):
            msg = 'rgb0 %s and rgb1 %s differ by %g' % (
                str(rgb0), str(rgb1), max(err_r, err_g, err_b))
            raise ValueError(msg)
    if verbose >= 1:
        print('Passed test_rgb_irgb()')
Example #4
0
    def rgb(self, red, green=None, blue=None, transitiontime=5):
        if isinstance(red, basestring):
            if not red.startswith('#'):
                raise ArgumentError('rgb strings must start with "#"')
            # assume a hex string is passed
            rstring = red
            red = int(rstring[1:3], 16)
            green = int(rstring[3:5], 16)
            blue = int(rstring[5:], 16)

        logger.debug("%d %d %d"%(red, green, blue))

        # We need to convert the RGB value to Yxy.
        redScale = float(red) / 255.0
        greenScale = float(green) / 255.0
        blueScale = float(blue) / 255.0
        logger.debug("%d %d %d"%(redScale, greenScale, blueScale))
        xyz = colormodels.irgb_color(red, green, blue)
        logger.debug(xyz)
        xyz = colormodels.xyz_from_rgb(xyz)
        logger.debug(xyz)
        xyz = colormodels.xyz_normalize(xyz)
        logger.debug(xyz)

        return self.set_state(
            {"xy": [xyz[0], xyz[1]], "transitiontime": transitiontime})
Example #5
0
    def color_adj(self, light_id):
        if light_id == 1:    
            rgba = self.color_picker1.wheel.color
        elif light_id == 2:
            rgba = self.color_picker2.wheel.color
        elif light_id == 3:
            rgba = self.color_picker2.wheel.color
        red = rgba[0]
        green = rgba[1]
        blue = rgba[2]

        colormodels.init(
            phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
            phosphor_green=colormodels.xyz_color(0.4091, 0.518),
            phosphor_blue=colormodels.xyz_color(0.167, 0.04))
        xyz = colormodels.irgb_color(red, green, blue)
        xyz = colormodels.xyz_from_rgb(xyz)
        xyz = colormodels.xyz_normalize(xyz)
        #print xyz, '\n'
        xy = [xyz[0], xyz[1]]
        huehub = 'http://' + ip + '/api/'+ myhash + "/lights/" + str(light_id)
        reply = requests.get(huehub)
        a=json.loads(reply.text)
        #print bri_val
        payload = json.dumps({"xy":xy})
        sethuehub = huehub + "/state"
        reply = requests.put(sethuehub, data=payload)

        #Update hue data printout
        reply= requests.get(huehub)
        a=json.loads(reply.text)

        if light_id == 1:    
            self.hue_label1.text = 'Hue :'+str(a['state']['hue'])
            self.bri_label1.text = 'Brightness :'+str(a['state']['bri'])
            self.sat_label1.text = 'Saturation :'+str(a['state']['sat'])
            self.ct_label1.text = 'Colour Temp :'+str(a['state']['ct'])
            self.xy_label1.text = '(x, y) :'+str(a['state']['xy'])
        elif light_id == 2:
            self.hue_label2.text = 'Hue :'+str(a['state']['hue'])
            self.bri_label2.text = 'Brightness :'+str(a['state']['bri'])
            self.sat_label2.text = 'Saturation :'+str(a['state']['sat'])
            self.ct_label2.text = 'Colour Temp :'+str(a['state']['ct'])
            self.xy_label2.text = '(x, y) :'+str(a['state']['xy'])
        elif light_id == 3:
            self.hue_label3.text = 'Hue :'+str(a['state']['hue'])
            self.bri_label3.text = 'Brightness :'+str(a['state']['bri'])
            self.sat_label3.text = 'Saturation :'+str(a['state']['sat'])
            self.ct_label3.text = 'Colour Temp :'+str(a['state']['ct'])
            self.xy_label3.text = '(x, y) :'+str(a['state']['xy'])
Example #6
0
    def _rgb_transfer(self, red, green=None, blue=None):
        if isinstance(red, basestring):
            rstring = red
            red = int(rstring[1:3], 16)
            green = int(rstring[3:5], 16)
            blue = int(rstring[5:], 16)

        colormodels.init(
            phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
            phosphor_green=colormodels.xyz_color(0.4091, 0.518),
            phosphor_blue=colormodels.xyz_color(0.167, 0.04))
        xyz = colormodels.irgb_color(red, green, blue)
        xyz = colormodels.xyz_from_rgb(xyz)
        xyz = colormodels.xyz_normalize(xyz)
        d = dict(xy=[xyz[0], xyz[1]],
                transitiontime=self._conf.default_transitiontime)
        return self.set_state(d)
Example #7
0
def test_irgb_string(verbose=1):
    '''Convert back and forth from irgb and irgb_string.'''
    for i in range(0, 100):
        ir = random.randrange(0, 256)
        ig = random.randrange(0, 256)
        ib = random.randrange(0, 256)
        irgb = colormodels.irgb_color(ir, ig, ib)
        irgb_string = colormodels.irgb_string_from_irgb(irgb)
        irgb2 = colormodels.irgb_from_irgb_string(irgb_string)
        irgb_string2 = colormodels.irgb_string_from_irgb(irgb2)
        if (irgb[0] != irgb2[0]) or (irgb[1] != irgb2[1]) or (irgb[2] !=
                                                              irgb2[2]):
            msg = 'irgb %s and irgb2 %s do not match' % (str(irgb), str(irgb2))
            raise ValueError(msg)
        if (irgb_string != irgb_string2):
            msg = 'irgb_string %s and irgb_string2 %s do not match' % (
                irgb_string, irgb_string2)
            raise ValueError(msg)
    if verbose >= 1:
        print('Passed test_irgb_string()')
    def colour_select(self, light_id):

        try:
            (rgb, hx) = tkColorChooser.askcolor()
            if (rgb, hx) == (None, None):
                warnings.warn('ColorChooser Error: No RGB colour selected.')
    
            else:
                print '(rgb, hx):', rgb, hx
                red = rgb[0]
                green = rgb[1]
                blue = rgb[2]

                redScale = float(red) / 255.0 #rgb goes from 0-255, this changes it into the 0-1.0 that xy uses
                greenScale = float(green) / 255.0
                blueScale = float(blue) / 255.0
                # Initialization function for conversion between CIE XYZ and linear RGB spaces
                colormodels.init(
                    phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
                    phosphor_green=colormodels.xyz_color(0.4091, 0.518),
                    phosphor_blue=colormodels.xyz_color(0.167, 0.04))
                xyz = colormodels.irgb_color(red, green, blue)
                xyz = colormodels.xyz_from_rgb(xyz)
                xyz = colormodels.xyz_normalize(xyz)
                print xyz, '\n'
                xy = [xyz[0], xyz[1]]
                

                #print 'rgb: ', red, green, blue
                #global huehub
                huehub = "http://192.168.0.100/api/"+ myhash + "/lights/" + str(light_id)
                reply = requests.get(huehub)
                a=json.loads(reply.text)
                #print bri_val
                payload = json.dumps({"xy":xy})
                sethuehub = huehub + "/state"
                reply = requests.put(sethuehub, data=payload)
        except TypeError, e:
            print 'Error closing ColorChooser: variable referenced before assignment\n', e, '\n'
            pass
    def rgb(self, red, green, blue, transitiontime=5):
        red = int(red)
        blue = int(blue)
        green = int(green)
        transitiontime = int(transitiontime)

        # We need to convert the RGB value to Yxy.
        redScale = float(red) / 255.0
        greenScale = float(green) / 255.0
        blueScale = float(blue) / 255.0
        colormodels.init(
            phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
            phosphor_green=colormodels.xyz_color(0.4091, 0.518),
            phosphor_blue=colormodels.xyz_color(0.167, 0.04))
        logger.debug(redScale, greenScale, blueScale)
        xyz = colormodels.irgb_color(red, green, blue)
        logger.debug(xyz)
        xyz = colormodels.xyz_from_rgb(xyz)
        logger.debug(xyz)
        xyz = colormodels.xyz_normalize(xyz)
        logger.debug(xyz)

        return self.set_state(
            **{"xy": [xyz[0], xyz[1]], "transitiontime": transitiontime})