# HG changeset patch # User Christophe Lincoln # Date 1398364982 -7200 # Node ID 7b9df94be9aa90c3dc5b18eae3682e156e42c53a # Parent cbb88e36289419a57cfe68b7f9ad4cf96f4692f1 Improve pyglow support diff -r cbb88e362894 -r 7b9df94be9aa python-rpi-pyglow/receipt --- a/python-rpi-pyglow/receipt Thu Apr 24 18:23:05 2014 +0200 +++ b/python-rpi-pyglow/receipt Thu Apr 24 20:43:02 2014 +0200 @@ -21,5 +21,6 @@ mkdir -p $fs/${pylibs} $fs/usr/share $fs/usr/bin cp -a ${src}/pyglow.py $fs/${pylibs} cp -a ${src}/examples $fs/usr/share/pyglow + cp ${stuff}/vortex.py $fs/usr/share/pyglow cp ${stuff}/pyglow $fs/usr/bin } diff -r cbb88e362894 -r 7b9df94be9aa python-rpi-pyglow/stuff/pyglow --- a/python-rpi-pyglow/stuff/pyglow Thu Apr 24 18:23:05 2014 +0200 +++ b/python-rpi-pyglow/stuff/pyglow Thu Apr 24 20:43:02 2014 +0200 @@ -1,6 +1,6 @@ #!/bin/sh # -# Tiny wrapper to Python Pyglow examples +# Tiny wrapper to Python Pimorini (vortex.py) and Pyglow examples # ex="/usr/share/pyglow" @@ -11,16 +11,18 @@ fi case "$1" in + 'test') + python ${ex}/test.py ;; cpu) python ${ex}/cpu.py ;; clock) python ${ex}/clock.py ;; set-leds) python ${ex}/set_leds.py ;; - 'test') - python ${ex}/test.py ;; + vortex) + python ${ex}/vortex.py ;; *) - echo "Usage: $(basename $0) [test|cpu|clock|set-leds]" ;; + echo "Usage: $(basename $0) [test|cpu|clock|set-leds|vortex]" ;; esac exit 0 diff -r cbb88e362894 -r 7b9df94be9aa python-rpi-pyglow/stuff/vortex.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python-rpi-pyglow/stuff/vortex.py Thu Apr 24 20:43:02 2014 +0200 @@ -0,0 +1,71 @@ +# Sample script for PiGlow that creates a continuous whirly vortex animation +# +# Please see our GitHub repository for more information: https://github.com/pimoroni/piglow +# +# Once running you'll need to press ctrl-C to cancel stop the script + +import time +from smbus import SMBus + +# command register addresses for the SN3218 IC used in PiGlow +CMD_ENABLE_OUTPUT = 0x00 +CMD_ENABLE_LEDS = 0x13 +CMD_SET_PWM_VALUES = 0x01 +CMD_UPDATE = 0x16 + +class PiGlow: + i2c_addr = 0x54 # fixed i2c address of SN3218 ic + bus = None + + def __init__(self, i2c_bus=1): + self.bus = SMBus(i2c_bus) + + # first we tell the SN3218 to enable output (turn on) + self.write_i2c(CMD_ENABLE_OUTPUT, 0x01) + + # then we ask it to enable each bank of LEDs (0-5, 6-11, and 12-17) + self.write_i2c(CMD_ENABLE_LEDS, [0xFF, 0xFF, 0xFF]) + + def update_leds(self, values): + print "update pwm" + self.write_i2c(CMD_SET_PWM_VALUES, values) + self.write_i2c(CMD_UPDATE, 0xFF) + + # a helper that writes the given value or list of values to the SN3218 IC + # over the i2c protocol + def write_i2c(self, reg_addr, value): + # if a single value is provided then wrap it in a list so we can treat + # all writes in teh same way + if not isinstance(value, list): + value = [value]; + + # write the data to the SN3218 + self.bus.write_i2c_block_data(self.i2c_addr, reg_addr, value) + +# a list of 18 values between 0 - 255 that represent each LED on the PiGlow. +# to change the LEDs we set the values in this array and then pass it to the +# update_leds() function to actually update the LDEs +values = [0x01,0x02,0x04,0x08,0x10,0x18,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xA0,0xC0,0xE0,0xFF] + +# create an instance of our PiGlow class and tell it that "1" is the I2C bus +# index (should be 0 for old old old Pis) +piglow = PiGlow(1) + +# loop forever, i mean why would we ever want to stop now the party has started? +# you can however use Ctrl+C to stop the script and reset the LEDs to off state +try: + while True: + # pop the first value off then drop it back on again - this just cycles the values around + values.append(values.pop(0)) + + # update the piglow with current values + piglow.update_leds(values) + + # sleep for a bit, don't go too fast! + time.sleep(0.1) + +except KeyboardInterrupt: + # set all the LEDs to "off" when Ctrl+C is pressed before exiting + values = [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00] + piglow.update_leds(values) + diff -r cbb88e362894 -r 7b9df94be9aa slitaz-arm-configs/receipt --- a/slitaz-arm-configs/receipt Thu Apr 24 18:23:05 2014 +0200 +++ b/slitaz-arm-configs/receipt Thu Apr 24 20:43:02 2014 +0200 @@ -1,7 +1,7 @@ # SliTaz package receipt. PACKAGE="slitaz-arm-configs" -VERSION="0.4" +VERSION="0.5" CATEGORY="base-system" SHORT_DESC="SliTaz ARM config files and artwork." MAINTAINER="pankso@slitaz.org"