示例#1
0
def shutdownEffect(brigthness):
    piglow.led(C_1, 0)
    piglow.led(C_8, 0)
    piglow.show()
    time.sleep(0.25)

    piglow.led(C_2, 0)
    piglow.led(C_7, 0)
    piglow.show()
    time.sleep(0.25)

    piglow.led(C_3, 0)
    piglow.led(C_6, 0)
    piglow.show()
    time.sleep(0.25)

    piglow.led(C_4, 0)
    piglow.led(C_5, 0)
    piglow.show()
    time.sleep(2)

    piglow.led(C_1, brigthness)
    piglow.led(C_2, brigthness)
    piglow.led(C_3, brigthness)
    piglow.led(C_4, brigthness)
    piglow.led(C_5, brigthness)
    piglow.led(C_6, brigthness)
    piglow.led(C_7, brigthness)
    piglow.led(C_8, brigthness)
    piglow.show()
示例#2
0
def _cycle(leds, speed, low, high):
    """ Cycle each LED from low to high in order """
    pulse_range = range(low, high)
    wait_for = 1/speed

    # Set each LED to the LOW state
    _set(leds, low)

    for i in range(0, len(leds)):
        for c in pulse_range:
            # Increase the LED to HIGH
            piglow.set(leds[i], c)
            piglow.show()
            sleep(wait_for)

            # Decrease the previous LED back to LOW at same rate
            if i > 0:
                piglow.set(leds[i-1], high-(c-low))
                piglow.show()
                sleep(wait_for)

    # Decrease the final LED back to LOW state
    _dim(leds[-1], speed, high, low)

    # Set each LED to the LOW state
    _set(leds, low)
示例#3
0
 def set_colour(self, item):
     for p, i in enumerate(self.new_map[item]):
         if i[1] < 1:
             i[0] = 0
         else:
             i[1] -= 1
         piglow.led(p, i[0])
     piglow.show()
示例#4
0
def disturbOff(channel, brightness):
    list = [0.3, 0.1, 0.02, 0.02, 0.1, 0.3]
    for delVal in list:
        piglow.led(channel, brightness)
        piglow.show()
        time.sleep(delVal)
        piglow.led(channel, 0)
        piglow.show()
        time.sleep(delVal)
示例#5
0
def _dim(led, speed, high, low):
    """ Dims the led from high to low at the given speed """
    dim_range = range(low, high)
    wait_for = 1/speed

    for c in reversed(dim_range):
        piglow.set(led, c)
        piglow.show()
        sleep(wait_for)
示例#6
0
def checkInternet():
    logging.debug('Check Internet')
    pingstatus = 1
    while pingstatus != 0:
        pingstatus = os.system("ping -c 1 -i 1 trimet.org")
        if pingstatus != 0:
            piglow.clear()
            piglow.show()
            errorStatus()
示例#7
0
 def setChannelBrightness(self, channel, brigthness):
     if channel == 'CH1':
         piglow.led(E_1, brigthness)
     elif channel == 'CH2':
         piglow.led(E_2, brigthness)
     elif channel == 'CH3':
         piglow.led(E_3, brigthness)
     elif channel == 'CH4':
         piglow.led(E_4, brigthness)
     piglow.show()
示例#8
0
 def setScreenBrightness(self, brigthness):
     piglow.led(C_1, brigthness)
     piglow.led(C_2, brigthness)
     piglow.led(C_3, brigthness)
     piglow.led(C_4, brigthness)
     piglow.led(C_5, brigthness)
     piglow.led(C_6, brigthness)
     piglow.led(C_7, brigthness)
     piglow.led(C_8, brigthness)
     piglow.show()
示例#9
0
def playnap(offset = 0, mediapath = "/home/pi/"):
	#blink all the indicators
    red.blink(0.25,0.25,5,1)
    red.off()
    i = 0
    while i <= 5:
      piglow.red(1)
      piglow.show()
      i += 1
      piglow.red(0)
      piglow.show()
      sleep(1)
示例#10
0
def flash_blue():

    # Turn off all, turn on blue
    piglow.clear()
    piglow.blue(BLUE)
    piglow.show()
    # Leave on for 0.1 seconds
    time.sleep(0.2)

    # Leave off for 0.1 seconds
    piglow.clear()
    piglow.show()
    time.sleep(0.2)
示例#11
0
def flash_orange():

    # Turn off all, turn on orange
    piglow.clear()
    piglow.orange(ORANGE)
    piglow.show()
    # Leave on for 0.1 seconds
    time.sleep(0.1)

    # Leave off for 0.1 seconds
    piglow.clear()
    piglow.show()
    time.sleep(0.1)
示例#12
0
def flash_yellow():

    # Turn off all, turn on yellow
    piglow.clear()
    piglow.yellow(YELLOW)
    piglow.show()
    # Leave on for 0.1 seconds
    time.sleep(0.1)

    # Leave off for 0.1 seconds
    piglow.clear()
    piglow.show()
    time.sleep(0.1)
示例#13
0
def flash_green():

    # Turn off all, turn on green
    piglow.clear()
    piglow.green(GREEN)
    piglow.show()
    # Leave on for 0.1 seconds
    time.sleep(0.2)

    # Leave off for 0.1 seconds
    piglow.clear()
    piglow.show()
    time.sleep(0.2)
示例#14
0
def flash_red():

    # Turn off all, turn on red
    piglow.clear()
    piglow.red(RED)
    piglow.show()

    # Leave on for 0.1 seconds
    time.sleep(0.1)

    # Leave off for 0.1 seconds
    piglow.clear()
    piglow.show()
    time.sleep(0.1)
示例#15
0
def _pulse(led, speed, low, high):
    """ Pulse the LED from low to high """
    pulse_range = range(low, high)
    wait_for = 1/speed

    for c in pulse_range:
        piglow.set(led, c)
        piglow.show()
        sleep(wait_for)

    for c in reversed(pulse_range):
        piglow.set(led, c)
        piglow.show()
        sleep(wait_for)
示例#16
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()
示例#17
0
def _pulse_color(color, speed, low, high):
    """ Pulse each LED of the defined color at the given speed """
    color_setter = getattr(piglow, color)
    pulse_range = range(low, high)
    wait_for = 1/speed

    for c in pulse_range:
        color_setter(c)
        piglow.show()
        sleep(wait_for)

    for c in reversed(pulse_range):
        color_setter(c)
        piglow.show()
        sleep(wait_for)
示例#18
0
    def init(self, configFile):

        # Track the file used to configure the current instance
        self.configFilePath = configFile

        # Set up handler for process termination
        signal.signal(signal.SIGTERM, onHomePiKilled)
        signal.signal(signal.SIGINT, onHomePiKilled)

        # Create a lock object for synchronization.
        self.threadLock = threading.Lock()

        # Feedback -  Performing cleanup.
        piglow.red(self.feedbackGlow)
        piglow.show()

        print 'Closing all existing GATT Connections... '
        self.closeAllGattConnections()
        print 'Done'

        # Feedback - Performing Config Initialization.
        piglow.red(0)
        piglow.orange(self.feedbackGlow)
        piglow.show()

        print 'Loading Home Devices... '
        regDevices = self.loadDevicesJSON(configFile)
        print 'Done Loading Home Device!'

        # Feedback - Connecting to registered devices.
        piglow.orange(0)
        piglow.yellow(self.feedbackGlow)
        piglow.show()

        print '\nAttempting connection to devices...'
        self.connectToRegisteredDevices(regDevices)
        print '\nConnection attempt done!'

        # Note: Seemed like a good idea but slows
        # down interaction with the HomePi while it is
        # trying to connect to the unavailable devices.
        # Removing for now until a better solution comes
        # to mind.
        #print '\nSpawning Device Checker Thread...'
        #self.statusChecker = HomePiDeviceStatusCheckerThread(self, 15)
        #self.statusChecker.setDaemon(True)
        #self.statusChecker.start()

        # Feedback - Ready and waiting for connections.
        piglow.red(0)
        piglow.orange(0)
        piglow.yellow(0)

        piglow.blue(self.feedbackGlow)
        piglow.show()

        # Listening to devices...
        self.listenForClients()
示例#19
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()
示例#20
0
	def init(self, configFile):
	 
		# Set up handler for process termination
		signal.signal(signal.SIGTERM, onHomePiKilled)
		signal.signal(signal.SIGINT, onHomePiKilled)
	
		# Create a lock object for synchronization.
		self.threadLock = threading.Lock()

		# Feedback -  Performing cleanup.
		piglow.red(self.feedbackGlow)
		piglow.show()

		print 'Closing all existing GATT Connections... '
		self.closeAllGattConnections()	
		print 'Done'
		
		# Feedback - Performing Config Initialization.
		piglow.red(0)
		piglow.orange(self.feedbackGlow)
		piglow.show()

		print 'Loading Home Devices... '
		regDevices = self.loadDevicesJSON(configFile)
		print 'Done Loading Home Device!'

		# Feedback - Connecting to registered devices.
		piglow.orange(0)
		piglow.yellow(self.feedbackGlow)
		piglow.show()

		print '\nAttempting connection to devices...'
		self.connectToRegisteredDevices(regDevices)
		print '\nConnection attempt done!'
		
		# Note: Seemed like a good idea but slows 
		# down interaction with the HomePi while it is 
		# trying to connect to the unavailable devices.
		# Removing for now until a better solution comes
		# to mind.
		#print '\nSpawning Device Checker Thread...'
		#self.statusChecker = HomePiDeviceStatusCheckerThread(self, 15)
		#self.statusChecker.setDaemon(True)
		#self.statusChecker.start()
		
		# Feedback - Ready and waiting for connections.
		piglow.red(0)
		piglow.orange(0)
		piglow.yellow(0)

		piglow.blue(self.feedbackGlow)
		piglow.show()

		# Listening to devices...	
		self.listenForClients()
示例#21
0
    def turn_on(self, **kwargs):
        """Instruct the light to turn on."""
        piglow.clear()

        if ATTR_BRIGHTNESS in kwargs:
            self._brightness = kwargs[ATTR_BRIGHTNESS]

        if ATTR_HS_COLOR in kwargs:
            self._hs_color = kwargs[ATTR_HS_COLOR]

        rgb = color_util.color_hsv_to_RGB(self._hs_color[0], self._hs_color[1],
                                          self._brightness / 255 * 100)
        piglow.red(rgb[0])
        piglow.green(rgb[1])
        piglow.blue(rgb[2])
        piglow.show()
        self._is_on = True
        self.schedule_update_ha_state()
示例#22
0
	def shutdown(self):
		try:
			print '\nShutting down HomePi!!'
			self.notifyShutdown()
			#self.bRunning = False
			
			# Feedback - Performing cleanup
			piglow.blue(0)
			piglow.red(self.feedbackGlow)
			piglow.show()

			# Start device disconnect.
			self.disconnectFromDevices(self.connectedDevices)
			self.disconnectFromClients(self.connectedClients)		
			self.notifyShutdown()
			self.btServerSocket.close()
			print '\nServer Socket Closed'
		except bluetooth.btcommon.BluetoothError:
			pass
示例#23
0
def glow(color="green"):
  if showLight:
      print("Make the World bright")
      try:
        if color=="green":
          piglow.green(200)
          piglow.red(0)
          piglow.orange(0)
        elif color=="red":
          piglow.green(0)
          piglow.red(150)
          piglow.orange(0)
        else:
          piglow.green(0)
          piglow.red(0)
          piglow.orange(150)
        piglow.show()
      except Exception as ex:
        print(ex)
示例#24
0
    def shutdown(self):
        try:
            print '\nShutting down HomePi!!'
            self.notifyShutdown()
            #self.bRunning = False

            # Feedback - Performing cleanup
            piglow.blue(0)
            piglow.red(self.feedbackGlow)
            piglow.show()

            # Start device disconnect.
            self.disconnectFromDevices(self.connectedDevices)
            self.disconnectFromClients(self.connectedClients)
            self.notifyShutdown()
            self.btServerSocket.close()
            print '\nServer Socket Closed'
            time.sleep(3)

        except bluetooth.btcommon.BluetoothError:
            pass
示例#25
0
def update_pressure():
    """ Broadcast the current accumulator pressure """
    pressure = pressure_sensor.read_pressure()
    poof_track.add_observation(pressure)
    if metrics.pressure.empty or poof_track.poofing():
        piglow.red(64)
        piglow.show()
        broadcast("/pressure", float(pressure))
        metrics.pressure = pd.concat([
            metrics.pressure,
            pd.DataFrame.from_records([{
                "timestamp": metrics.now_string(),
                "level": pressure
            }]),
        ])
        broadcast("/poof_count", float(poof_track.poof_count))
        logger.info(f"Pressure = {pressure}")
    elif not poof_track.poofing():
        piglow.red(0)
        piglow.show()
        poof_track.stop()
        broadcast("/poof_seconds", float(poof_track.poof_time))
示例#26
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)
示例#27
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)
示例#28
0
def _clear_all():
    """ Clear all LEDs """
    for l in range(0, 18):
        piglow.set(l, 0)
    piglow.show()
示例#29
0
def errorStatus():
    logging.debug('Network Error')
    piglow.white(255)
    piglow.show()
示例#30
0
def all_off():
    piglow.off()
    piglow.show()
    return 'All off now'
示例#31
0
 def turn_off(self, **kwargs):
     """Instruct the light to turn off."""
     piglow.clear()
     piglow.show()
     self._is_on = False
     self.schedule_update_ha_state()
示例#32
0
def bounceEffect(brightness):
    piglow.led(C_1, 0)
    piglow.led(C_8, 0)
    piglow.show()
    time.sleep(0.1)

    piglow.led(C_2, 0)
    piglow.led(C_7, 0)
    piglow.show()
    time.sleep(0.1)

    piglow.led(C_3, 0)
    piglow.led(C_6, 0)
    piglow.show()
    time.sleep(0.1)

    piglow.led(C_4, 0)
    piglow.led(C_5, 0)
    piglow.show()
    time.sleep(0.01)

    piglow.led(C_4, brightness)
    piglow.led(C_5, brightness)
    piglow.show()
    time.sleep(0.01)

    piglow.led(C_3, brightness)
    piglow.led(C_6, brightness)
    piglow.show()
    time.sleep(0.1)

    piglow.led(C_2, brightness)
    piglow.led(C_7, brightness)
    piglow.show()
    time.sleep(0.1)

    piglow.led(C_1, brightness)
    piglow.led(C_8, brightness)
    piglow.show()
示例#33
0
def _set(leds, value):
    """ Sets the value of each led """
    for led in leds:
        piglow.set(led, value)
    piglow.show()
示例#34
0
#!/usr/bin/env python

import time

import piglow


i = 0
x = 0

while True:
    if i % 32 == 0:
        piglow.leg((x % 3), 64)
        x += 1
    piglow.set(0, list(map(lambda x: x - 1 if x > 1 else 0, piglow.get())))
    piglow.show()
    time.sleep(0.1)
    i += 1
示例#35
0
def _set_color(color, value):
    """ Set the value of the defined color """
    color_setter = getattr(piglow, color)
    color_setter(value)
    piglow.show()
示例#36
0
#!/usr/bin/env python

import piglow
import sys
from time import sleep

piglow.auto_update = True

argv = sys.argv
color = 'all'

if len(argv) > 1:
    color = argv[1]

method = getattr(piglow, color)

# shine once
for x in range(180):
    method(x)
    piglow.show()
for x in reversed(range(180)):
    method(x)
    piglow.show()
示例#37
0
def hello_world():
    piglow.all(64)
    piglow.show()
    return 'Shaun This is  Python Hello World!' + sys.version