arvydas / blinkstick-python

BlinkStick Python interface to control devices connected to the computer
Other
136 stars 53 forks source link

Add reverse color setting to Blinkstick device #8

Closed zebaz closed 11 years ago

zebaz commented 11 years ago

Hi,

First of all thanks for the great Python interface!

I'm using it to control my IKEA Dioder, and in my particular setup I need to reverse the colorcodes to make it work (so for a white color I need to send #00000 instead of #FFFFF).

This functionality is integrated in the Blinkstick Windows client, but I think it would be nice to integrate this as well in the Python bindings.

For now I've extended the Python script, and used an array to reverse the colorcodes like so (be warned, I'm coming from a Java background and still figuring out Python ;)):

R = 255
G = 0
B = 0

#Lets build an array of numbers containing the values 255 - 0 respectively
reverse = []
top = 256
for i in range(256):
        top = top - 1
        reverse.append(top)

for bstick in blinkstick.find_all():
        #Here we reverse the colors by using the color as a position
        #in the array with the reverse numbers
        bstick.set_color(reverse[R],reverse[G],reverse[B])

This works without any issues, but it might be nice to integrate this in the library? Just a thought.

arvydas commented 11 years ago

Thanks for this! :-)

I will include this feature in the next release tomorrow.

arvydas commented 11 years ago

This requirement has been implemented in the following way: BlinkStick object has 2 new functions set_inverse(value) and get_inverse(). It either sets or gets inverse mode for the object and all functions adapt accordingly. This means that when you call set_color(name="red") it will correctly set it to red on IKEA DIODER modded with BlinkStick and get_color(color_format="hex") will return #ff0000 as the current color of BlinkStick. So the code example that should work for you is as follows:

stick = blinkstick.find_first()
stick.set_inverse(True)

stick.set_color(name="blue") # this correctly sets color to blue

New version of package will be released as soon as I finish testing.

zebaz commented 11 years ago

Thanks for the speedy response, it works flawlessly!

arvydas commented 11 years ago

Glad to hear it works for you :-)

LMK if you need anything else!