Skip to content

0.2.0 package release #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
v0.1.0, 2013-03-27 -- Initial release.
v0.1.0, 2013-03-27 -- Initial release.
v0.2.0, 2013-04-08 -- Add ability to set color by CSS name or hex string
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Requirements

- Python
- PyUSB
- webcolors
- grapefruit - package for color manipulations
- pyusb - package to access USB devices
- psutil - only for example-cpu.py
Expand Down
26 changes: 17 additions & 9 deletions blinkstick/blinkstick.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from grapefruit import Color
import webcolors

import usb.core
import usb.util
Expand Down Expand Up @@ -40,24 +41,31 @@ def get_description(self):
"""Get the description of the device"""
return usb.util.get_string(self.device, 256, 2)

def set_color(self, red=0, green=0, blue=0):
def set_color(self, red=0, green=0, blue=0, name=None, hex=None):
"""Set the color to the device as RGB

Args:
r (byte): Red color intensity 0 is off, 255 is full red intensity
g (byte): Green color intensity 0 is off, 255 is full green intensity
b (byte): Blue color intensity 0 is off, 255 is full blue intensity
red: Red color intensity 0 is off, 255 is full red intensity
green: Green color intensity 0 is off, 255 is full green intensity
blue: Blue color intensity 0 is off, 255 is full blue intensity
name: Use CSS colour name as defined here: http://www.w3.org/TR/css3-color/
hex: Specify color using hexadecimal color value e.g. '#FF3366'
"""

try:
if name:
red, green, blue = webcolors.name_to_rgb(name)
elif hex:
red, green, blue = webcolors.hex_to_rgb(hex)
except ValueError:
red = green = blue = 0

self.device.ctrl_transfer(0x20, 0x9, 0x0001, 0, "\x00" + chr(red) + chr(green) + chr(blue))

def _get_color(self):

"""
Get the current color settings as a grapefruit Color object

:param get_color_obj:
:return:
"""
device_bytes = self.device.ctrl_transfer(0x80 | 0x20, 0x1, 0x0001, 0, 33)
# Color object requires RGB values in range 0-1, not 0-255
Expand All @@ -71,7 +79,7 @@ def get_color(self):
"""Get the color to the device as Color namedtuple

Returns:
Color - the current color of the device
Color - the current color of the device as a 3-tuple of integers

Example:
b = BlinkStick.find_first()
Expand All @@ -84,7 +92,7 @@ def get_color(self):
return int(r * 255), int(g * 255), int(b * 255)

def get_color_string(self):
"""Get the color to the device as Color namedtuple
"""Get the current device color as hexadecimal string

Returns:
String - current color of the device as HEX encoded string #rrggbb
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def read(fname):

setup(
name='BlinkStick',
version='0.1.0',
version='0.2.0',
author='Arvydas Juskevicius',
author_email='arvydas@arvydas.co.uk',
packages=find_packages(),
Expand All @@ -25,6 +25,8 @@ def read(fname):
long_description=read('README.rst'),
install_requires=[
"grapefruit",
"pyusb"
"webcolors",
"pyusb",
"websocket-client"
],
)