Ejemplo n.º 1
0
def piglow(mod):
    print(section_header(mod))
    try:
        import piglow
        piglow.auto_update = True
        piglow.clear_on_exit = False
        piglow.all(50)
    except ModuleNotFoundError:
        print("ERROR IN CONFIG: PiGlow is not set to False but cannot load "
              "package.")
Ejemplo n.º 2
0
	def printFile(self, filename):
		if self.piGlowEnable:
			piglow.all(0)
		if filename is not False:
			if self.piGlowEnable:
				piglow.green(255)
			print "PRINT: "+ str(filename) + " [Sent to printer]"
			self.conn.printFile(self.printer, filename, "Test", {"CutMedia": "2"})
		else:
			if self.piGlowEnable:
				piglow.red(255);
		if self.piGlowEnable:
			time.sleep(2)
			piglow.all(0)
			piglow.show()
Ejemplo n.º 3
0
 def printFile(self, filename):
     if self.piGlowEnable:
         piglow.all(0)
     if filename is not False:
         if self.piGlowEnable:
             piglow.green(255)
         print "PRINT: " + str(filename) + " [Sent to printer]"
         self.conn.printFile(self.printer, filename, "Test",
                             {"CutMedia": "2"})
     else:
         if self.piGlowEnable:
             piglow.red(255)
     if self.piGlowEnable:
         time.sleep(2)
         piglow.all(0)
         piglow.show()
Ejemplo n.º 4
0
def wave(led_max=150, frame_delay=0.02, frame_count=None, initial_brightness=None, direction=None):
    """
    Creates a wave effect through the PiGlow board.

    Args (all are optional):
        led_max (int): the LED brightness at the peak of the wave.
        frame_delay (float): the time between each transition.
        frame_count (int): the number of transitions in a single wave.
        initial_brightness (int): the current brightness of the LEDs.
        direction (string): either 'inward' or 'outward'.
    """
    if initial_brightness is None:
        initial_brightness = min(piglow.get())

    if direction is None:
        direction = 'outward'

    if frame_count is None:
        frame_count = len(LEDS)

    if direction == 'outward':
        LEDS.reverse()

    led_set_count = len(LEDS)

    # initialise all of the LEDs
    piglow.all(initial_brightness)
    piglow.show()

    wave = _create_led_sine_wave(led_max, frame_count, initial_brightness, led_set_count)

    for wave_point in _window(wave, led_set_count):
        for i, led_set in enumerate(LEDS):
            for led in led_set:
                piglow.led(led, int(wave_point[i]))

            piglow.show()
            sleep(frame_delay)
Ejemplo n.º 5
0
def wave(led_max=150, frame_delay=0.02, frame_count=None, initial_brightness=None, direction=None):
    """
    Creates a wave effect through the PiGlow board.

    Args (all are optional):
        led_max (int): the LED brightness at the peak of the wave.
        frame_delay (float): the time between each transition.
        frame_count (int): the number of transitions in a single wave.
        initial_brightness (int): the current brightness of the LEDs.
        direction (string): either 'inward' or 'outward'.
    """
    if initial_brightness is None:
        initial_brightness = min(piglow.get())

    if direction is None:
        direction = 'outward'

    if frame_count is None:
        frame_count = len(LEDS)

    if direction == 'outward':
        LEDS.reverse()

    led_set_count = len(LEDS)

    # initialise all of the LEDs
    piglow.all(initial_brightness)
    piglow.show()

    wave = _create_led_sine_wave(led_max, frame_count, initial_brightness, led_set_count)

    for wave_point in _window(wave, led_set_count):
        for i, led_set in enumerate(LEDS):
            for led in led_set:
                piglow.led(led, int(wave_point[i]))

            piglow.show()
            sleep(frame_delay)
Ejemplo n.º 6
0
    def getImage(self, keyNum):
        filename = self.tmpLocation + str(keyNum) + ".png"
        if self.piGlowEnable:
            piglow.all(0)
            piglow.yellow(255)
        if (os.path.isfile(filename)):
            if (datetime.fromtimestamp(os.path.getctime(filename)).date() <
                    datetime.today().date()):
                print "DELETE: " + str(keyNum) + ", [File older than today]"
                os.remove(filename)
            else:
                print "CACHED: " + str(keyNum) + " [Returning cached file]"
                return filename

        if not self.URL:
            print 'ERROR: Unable to locate file, and URL fetching not configured'
            return False

        if (self.URL and "<CARDNUM>" not in self.URL):
            print 'ERROR: <CARDNUM> placeholder not found in URL config'
            return False

        try:
            print "GET: " + str(keyNum) + " [Downloading new file]"
            url = self.URL.replace('<CARDNUM>', str(keyNum))
            uh = urllib2.urlopen(url)
        except:
            print "NOTFOUND: " + str(keyNum) + " [Server responded non-200]"
            return False
        CHUNK = 16 * 1024
        with open(filename, 'wb') as f:
            while True:
                chunk = uh.read(CHUNK)
                if not chunk: break
                f.write(chunk)
            f.close()
        print "WROTE: " + filename
        return filename
Ejemplo n.º 7
0
	def getImage(self, keyNum):
		filename = self.tmpLocation + str(keyNum) + ".png"
		if self.piGlowEnable:
			piglow.all(0)
			piglow.yellow(255)
		if (os.path.isfile(filename)):
			if (datetime.fromtimestamp(os.path.getctime(filename)).date() < datetime.today().date()):
				print "DELETE: "+str(keyNum)+", [File older than today]"
				os.remove(filename)
			else:
				print "CACHED: "+str(keyNum)+" [Returning cached file]"
				return filename
			
		if not self.URL:
			print 'ERROR: Unable to locate file, and URL fetching not configured'
			return False	
		
		if (self.URL and "<CARDNUM>" not in self.URL):
			print 'ERROR: <CARDNUM> placeholder not found in URL config'
			return False
		
		try:
			print "GET: "+str(keyNum)+" [Downloading new file]"
			url = self.URL.replace('<CARDNUM>', str(keyNum))
			uh = urllib2.urlopen(url)
		except:
			print "NOTFOUND: "+str(keyNum)+" [Server responded non-200]"
			return False
		CHUNK = 16 * 1024
		with open(filename, 'wb') as f:
			while True:
				chunk = uh.read(CHUNK)
				if not chunk: break
				f.write(chunk) 
			f.close()
		print "WROTE: "+filename
		return filename
Ejemplo n.º 8
0
def main():
    piglow.clear_on_exit = False
    piglow.auto_update = True
    piglow.all(0)

    try:
        status = update()
    except:     # Unknown error raised when the wifi adapter dies
        piglow.blue(1)
        # os.system('sudo shutdown -r now')

    met_status = status.pop('metropolitan')
    jubilee_status = status.pop('jubilee')

    if datetime.date.today().isoweekday() in (6, 7):
        # No Waterloo and City service on the weekend
        status.pop('waterloo-city')

    # Reminder: sets can't be keys to dicts but frozensets can
    other_statuses = frozenset(status.values())
    other_status = {frozenset(['GOOD']): 'GOOD',
                    frozenset(['GOOD', 'OK']): 'OK'}.get(other_statuses, 'BAD')

    met_leds = {'GOOD': [1],
                'OK':   [1, 2],
                'BAD':  [1, 2, 3, 4, 5, 6]}[met_status]

    jubilee_leds = {'GOOD': [7],
                    'OK':   [7, 8],
                    'BAD':  [7, 8, 9, 10, 11, 12]}[jubilee_status]

    other_leds = {'GOOD': [13],
                  'OK':   [13, 14],
                  'BAD':  [13, 14, 15, 16, 17, 18]}[other_status]

    [piglow.led(n, 1) for n in met_leds + jubilee_leds + other_leds]
Ejemplo n.º 9
0
import time
import piglow

piglow.auto_update = True

for x in range(6):
    piglow.all(0)
    piglow.ring(x,100)
    time.sleep(0.5)
Ejemplo n.º 10
0
	def __init__(self):
		self.configFileLocation = os.getenv('CONFFILE', self.configFileLocation)
		self.config = ConfigParser.ConfigParser()
		#Try to load config file
		
		if self.configFileLocation not in self.config.read(self.configFileLocation):
			self.configFileLocation = None
			
		#Try to set rfid input path from config file.
		try:
			self.rfidPath = self.config.get('Parkomatic', 'rfid_input_path')
		except: 
			pass
		
		#Try to set destination URL from config file.
		try:
			self.URL = self.config.get('Parkomatic', 'url')
		except:
			pass
		
		#Try to set tmp path from config file.
		try:
			self.tmpLocation = self.config.get('Parkomatic', 'tmp_path')
		except:
			pass
		
		try:
			piglow_val = self.config.get('Parkomatic', 'piglow')
			if piglow_val == "enable":
				self.piGlowEnable = True
		except:
			 pass
		
		#Try to create the tmp location if it doesn't exist
		if not os.path.exists(self.tmpLocation):
			os.makedirs(self.tmpLocation)
		
		#Make a connection to the CUPS server
		try:
			self.conn = cups.Connection()
		except:
			print "ERROR: CUPs not available"
			#Sleep for 5 seconds as repeatedly attemping to connect to CUPs seems to make it hard for cups to start initially.
			time.sleep(5)
			sys.exit(1)
			
		printers = self.conn.getPrinters()
		if len(printers) == 0:
			print "ERROR: No printers available"
			time.sleep(5)
			sys.exit(1)
		#Get the first printer in the list
		self.printer = printers.keys()[0]
		
		#Create the RFID input device
		self.rfidDevice = InputDevice(self.rfidPath)
		print "STARTED: Waiting for input."
		if self.piGlowEnable:
			piglow.auto_update = True;
			piglow.all(0)
			piglow.red(255)
			time.sleep(0.1)
			piglow.red(0)
			piglow.green(255)
			time.sleep(0.1)
			piglow.green(0)
			piglow.yellow(255)
			time.sleep(0.1)
			piglow.white(255)
			piglow.yellow(0)
			time.sleep(0.1)
			piglow.white(0)
Ejemplo n.º 11
0
#!/usr/bin/env python

import piglow
from time import sleep

piglow.auto_update = True

# blink 3 times
BRIGHT_MAX = 20
bright = BRIGHT_MAX

for count in range(4):
    for x in range(6):
        list = [x, x + 6, x + 12]
        piglow.set(list, bright)
        sleep(0.1)

    bright = 0 if bright == BRIGHT_MAX else BRIGHT_MAX

# shine once
for x in range(130):
    piglow.all(x)
    piglow.show()
for x in reversed(range(130)):
    piglow.all(x)
    piglow.show()
Ejemplo n.º 12
0
piglow.auto_update = True

### You can customise these settings ###

show12hr = 1  # Show 12 or 24hr clock - 0= 24hr, 1= 12hr
ledbrightness = 10  # Set brightness of LED - 1-255 (recommend 10-20, put 0 and you won't see it!)
hourflash = 1  # Choose how to flash change of hour - 1= white leds, 2= all flash

armtop = "s"  # h= hour, m= minutes, s= seconds
armright = "m"
armbottom = "h"

### End of customising ###

piglow.all(0)

hourcount = 0
hourcurrent = 0

while True:
    time = datetime.now().time()
    print(str(time))
    hour = time.hour
    min = time.minute
    sec = time.second

    if show12hr == 1:
        if hour > 12:
            hour = hour - 12
Ejemplo n.º 13
0
def hello_world():
    piglow.all(64)
    piglow.show()
    return 'Shaun This is  Python Hello World!' + sys.version
Ejemplo n.º 14
0
    def __init__(self):
        self.configFileLocation = os.getenv('CONFFILE',
                                            self.configFileLocation)
        self.config = ConfigParser.ConfigParser()
        #Try to load config file

        if self.configFileLocation not in self.config.read(
                self.configFileLocation):
            self.configFileLocation = None

        #Try to set rfid input path from config file.
        try:
            self.rfidPath = self.config.get('Parkomatic', 'rfid_input_path')
        except:
            pass

        #Try to set destination URL from config file.
        try:
            self.URL = self.config.get('Parkomatic', 'url')
        except:
            pass

        #Try to set tmp path from config file.
        try:
            self.tmpLocation = self.config.get('Parkomatic', 'tmp_path')
        except:
            pass

        try:
            piglow_val = self.config.get('Parkomatic', 'piglow')
            if piglow_val == "enable":
                self.piGlowEnable = True
        except:
            pass

        #Try to create the tmp location if it doesn't exist
        if not os.path.exists(self.tmpLocation):
            os.makedirs(self.tmpLocation)

        #Make a connection to the CUPS server
        try:
            self.conn = cups.Connection()
        except:
            print "ERROR: CUPs not available"
            #Sleep for 5 seconds as repeatedly attemping to connect to CUPs seems to make it hard for cups to start initially.
            time.sleep(5)
            sys.exit(1)

        printers = self.conn.getPrinters()
        if len(printers) == 0:
            print "ERROR: No printers available"
            time.sleep(5)
            sys.exit(1)
        #Get the first printer in the list
        self.printer = printers.keys()[0]

        #Create the RFID input device
        self.rfidDevice = InputDevice(self.rfidPath)
        print "STARTED: Waiting for input."
        if self.piGlowEnable:
            piglow.auto_update = True
            piglow.all(0)
            piglow.red(255)
            time.sleep(0.1)
            piglow.red(0)
            piglow.green(255)
            time.sleep(0.1)
            piglow.green(0)
            piglow.yellow(255)
            time.sleep(0.1)
            piglow.white(255)
            piglow.yellow(0)
            time.sleep(0.1)
            piglow.white(0)
Ejemplo n.º 15
0
piglow.auto_update = True

### You can customise these settings ###

show12hr = 1            # Show 12 or 24hr clock - 0= 24hr, 1= 12hr
ledbrightness = 10      # Set brightness of LED - 1-255 (recommend 10-20, put 0 and you won't see it!)
hourflash = 1           # Choose how to flash change of hour - 1= white leds, 2= all flash

armtop = "s"            # h= hour, m= minutes, s= seconds
armright = "m"
armbottom = "h"

### End of customising ###

piglow.all(0)

hourcount = 0
hourcurrent = 0

while True:
    time = datetime.now().time()
    hour,min,sec = str(time).split(":")

    # Bug fix by Phil Moyer - Tested and verified by Ric Woods - Thanks guys!
    try:
        rv = str(sec).index(".")
        sec,micro = str(sec).split(".")
    except ValueError:
        sec = str(sec)
        micro = "0"
Ejemplo n.º 16
0
## brightness                                   ##
## Example by tng - @TommyBobbins               ##
##################################################

import piglow

piglow.auto_update = True

from time import sleep
import random

# Maximum random sleep between switching an LED on or off
sleep_period = 0.001

# Switch off all the lights first
piglow.all(0)

# We only want to select the Red, Orange and Yellow LEDs (roy)
roy_leds = ["01", "02", "03", "07", "08", "09", "13", "14", "15"]


def random_brightness():
    sleep(random.uniform(0, sleep_period))
    return random.randint(0, 255)


while True:
    # Switch one random roy LED to one random brightness
    led_to_switch = int(random.choice(roy_leds))
    piglow.led(led_to_switch, random_brightness())
    # Switch one random roy LED off
Ejemplo n.º 17
0
#!/usr/bin/env python

import piglow
from time import sleep

piglow.auto_update = True

# blink 3 times
BRIGHT_MAX = 20
bright = BRIGHT_MAX

for count in range(4):
    for x in range(6):
        list = [x, x + 6, x + 12]
        piglow.set(list, bright)
        sleep(0.1)
    
    bright = 0 if bright == BRIGHT_MAX else BRIGHT_MAX

# shine once
for x in range(130):
    piglow.all(x)
    piglow.show()
for x in reversed(range(130)):
    piglow.all(x)
    piglow.show()