Skip to content

Commit

Permalink
Rearrange BlinkM API to be more sensible
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Mar 29, 2013
1 parent e0a8407 commit 0cffbb1
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions public/blinkm.py
Expand Up @@ -3,19 +3,34 @@

public = Blueprint('blinkm', __name__, template_folder='templates')

@public.route('/blinkm/<address>/hsb/<hue>/<saturation>/<brightness>', methods=['GET', 'POST'])
@public.route('/blinkm/hsb/<address>/<hue>/<saturation>/<brightness>', methods=['GET', 'POST'])
def blinkm_set_hsb(address, hue, saturation, brightness):
import subprocess
cmd = ('blinkm fade-hsb -d ' + address +
' -h ' + hue +
' -s ' + saturation +
' -b ' + brightness +
'; blinkm stop-script -d ' + address)
' -b ' + brightness)
print cmd
subprocess.Popen([cmd], shell=True)
return ('HSB sent to Blinkm')
return 'HSB triplet ({0}, {1}, {2}) sent to Blinkm at address {3}'.format(hue, saturation, brightness, address)

@public.route('/blinkm/<address>/hsb', methods=['GET', 'POST'])
@public.route('/blinkm/hsb/<address>', methods=['GET', 'POST'])
def blinkm_get_hsb(address):
rgb = pytronics.i2cRead(int(address), 0x67, 'I', 3)
return json.dumps(zip(['hue', 'saturation', 'brightness'], colorsys.rgb_to_hsv(rgb[0]/255.0, rgb[1]/255.0, rgb[2]/255.0)))
return json.dumps(zip(['hue', 'saturation', 'brightness'], colorsys.rgb_to_hsv(rgb[0]/255.0, rgb[1]/255.0, rgb[2]/255.0)))

@public.route('/blinkm/rgb/<address>/<red>/<green>/<blue>', methods=['GET', 'POST'])
def blinkm_set_rgb(address, red, green, blue):
import subprocess
cmd = ('blinkm fade-rgb -d ' + address +
' -r ' + red +
' -g ' + green +
' -b ' + blue)
print cmd
subprocess.Popen([cmd], shell=True)
return 'RGB triplet ({0}, {1}, {2}) sent to Blinkm at address {3}'.format(red, green, blue, address)

@public.route('/blinkm/rgb/<address>', methods=['GET', 'POST'])
def blinkm_get_rgb(address):
rgb = pytronics.i2cRead(int(address), 0x67, 'I', 3)
return json.dumps(zip(['red', 'green', 'blue'], rgb))

0 comments on commit 0cffbb1

Please sign in to comment.