wok-next rev 16511

Improve pyglow support
author Christophe Lincoln <pankso@slitaz.org>
date Thu Apr 24 20:43:02 2014 +0200 (2014-04-24)
parents cbb88e362894
children fe06085e7586
files python-rpi-pyglow/receipt python-rpi-pyglow/stuff/pyglow python-rpi-pyglow/stuff/vortex.py slitaz-arm-configs/receipt
line diff
     1.1 --- a/python-rpi-pyglow/receipt	Thu Apr 24 18:23:05 2014 +0200
     1.2 +++ b/python-rpi-pyglow/receipt	Thu Apr 24 20:43:02 2014 +0200
     1.3 @@ -21,5 +21,6 @@
     1.4  	mkdir -p $fs/${pylibs} $fs/usr/share $fs/usr/bin
     1.5  	cp -a ${src}/pyglow.py $fs/${pylibs}
     1.6  	cp -a ${src}/examples $fs/usr/share/pyglow
     1.7 +	cp ${stuff}/vortex.py $fs/usr/share/pyglow
     1.8  	cp ${stuff}/pyglow $fs/usr/bin
     1.9  }
     2.1 --- a/python-rpi-pyglow/stuff/pyglow	Thu Apr 24 18:23:05 2014 +0200
     2.2 +++ b/python-rpi-pyglow/stuff/pyglow	Thu Apr 24 20:43:02 2014 +0200
     2.3 @@ -1,6 +1,6 @@
     2.4  #!/bin/sh
     2.5  #
     2.6 -# Tiny wrapper to Python Pyglow examples
     2.7 +# Tiny wrapper to Python Pimorini (vortex.py) and Pyglow examples
     2.8  #
     2.9  
    2.10  ex="/usr/share/pyglow"
    2.11 @@ -11,16 +11,18 @@
    2.12  fi
    2.13  
    2.14  case "$1" in
    2.15 +	'test') 
    2.16 +		python ${ex}/test.py ;;
    2.17  	cpu) 
    2.18  		python ${ex}/cpu.py ;;
    2.19  	clock) 
    2.20  		python ${ex}/clock.py ;;
    2.21  	set-leds) 
    2.22  		python ${ex}/set_leds.py ;;
    2.23 -	'test') 
    2.24 -		python ${ex}/test.py ;;
    2.25 +	vortex)
    2.26 +		python ${ex}/vortex.py ;;
    2.27  	*) 
    2.28 -		echo "Usage: $(basename $0) [test|cpu|clock|set-leds]" ;;
    2.29 +		echo "Usage: $(basename $0) [test|cpu|clock|set-leds|vortex]" ;;
    2.30  esac
    2.31  
    2.32  exit 0
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/python-rpi-pyglow/stuff/vortex.py	Thu Apr 24 20:43:02 2014 +0200
     3.3 @@ -0,0 +1,71 @@
     3.4 +# Sample script for PiGlow that creates a continuous whirly vortex animation
     3.5 +#
     3.6 +# Please see our GitHub repository for more information: https://github.com/pimoroni/piglow
     3.7 +#
     3.8 +# Once running you'll need to press ctrl-C to cancel stop the script
     3.9 +
    3.10 +import time
    3.11 +from smbus import SMBus
    3.12 +
    3.13 +# command register addresses for the SN3218 IC used in PiGlow
    3.14 +CMD_ENABLE_OUTPUT = 0x00
    3.15 +CMD_ENABLE_LEDS = 0x13
    3.16 +CMD_SET_PWM_VALUES = 0x01
    3.17 +CMD_UPDATE = 0x16
    3.18 +
    3.19 +class PiGlow:
    3.20 +	i2c_addr = 0x54 # fixed i2c address of SN3218 ic
    3.21 +	bus = None
    3.22 +
    3.23 +	def __init__(self, i2c_bus=1):
    3.24 +		self.bus = SMBus(i2c_bus)
    3.25 +
    3.26 +        # first we tell the SN3218 to enable output (turn on)
    3.27 +		self.write_i2c(CMD_ENABLE_OUTPUT, 0x01)
    3.28 +
    3.29 +        # then we ask it to enable each bank of LEDs (0-5, 6-11, and 12-17)
    3.30 +		self.write_i2c(CMD_ENABLE_LEDS, [0xFF, 0xFF, 0xFF])
    3.31 +
    3.32 +	def update_leds(self, values):
    3.33 +		print "update pwm"
    3.34 +		self.write_i2c(CMD_SET_PWM_VALUES, values)
    3.35 +		self.write_i2c(CMD_UPDATE, 0xFF)
    3.36 +
    3.37 +	# a helper that writes the given value or list of values to the SN3218 IC
    3.38 +	# over the i2c protocol
    3.39 +	def write_i2c(self, reg_addr, value):
    3.40 +        # if a single value is provided then wrap it in a list so we can treat
    3.41 +        # all writes in teh same way
    3.42 +		if not isinstance(value, list):
    3.43 +			value = [value];
    3.44 +
    3.45 +        # write the data to the SN3218
    3.46 +		self.bus.write_i2c_block_data(self.i2c_addr, reg_addr, value)
    3.47 +
    3.48 +# a list of 18 values between 0 - 255 that represent each LED on the PiGlow.
    3.49 +# to change the LEDs we set the values in this array and then pass it to the
    3.50 +# update_leds() function to actually update the LDEs
    3.51 +values = [0x01,0x02,0x04,0x08,0x10,0x18,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xA0,0xC0,0xE0,0xFF]
    3.52 +
    3.53 +# create an instance of our PiGlow class and tell it that "1" is the I2C bus
    3.54 +# index (should be 0 for old old old Pis)
    3.55 +piglow = PiGlow(1)
    3.56 +
    3.57 +# loop forever, i mean why would we ever want to stop now the party has started?
    3.58 +# you can however use Ctrl+C to stop the script and reset the LEDs to off state
    3.59 +try:
    3.60 +        while True:
    3.61 +                # pop the first value off then drop it back on again - this just cycles the values around
    3.62 +                values.append(values.pop(0))
    3.63 +
    3.64 +                # update the piglow with current values
    3.65 +                piglow.update_leds(values)
    3.66 +
    3.67 +                # sleep for a bit, don't go too fast!
    3.68 +                time.sleep(0.1)
    3.69 +                
    3.70 +except KeyboardInterrupt:
    3.71 +	# set all the LEDs to "off" when Ctrl+C is pressed before exiting
    3.72 +        values = [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
    3.73 +        piglow.update_leds(values)
    3.74 +
     4.1 --- a/slitaz-arm-configs/receipt	Thu Apr 24 18:23:05 2014 +0200
     4.2 +++ b/slitaz-arm-configs/receipt	Thu Apr 24 20:43:02 2014 +0200
     4.3 @@ -1,7 +1,7 @@
     4.4  # SliTaz package receipt.
     4.5  
     4.6  PACKAGE="slitaz-arm-configs"
     4.7 -VERSION="0.4"
     4.8 +VERSION="0.5"
     4.9  CATEGORY="base-system"
    4.10  SHORT_DESC="SliTaz ARM config files and artwork."
    4.11  MAINTAINER="pankso@slitaz.org"