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()
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()
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)
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()
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
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
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]
def blueLine(): logging.debug('Blue Line') piglow.blue(255)
piglow.show() time.sleep(0.01) for x in reversed(range(100)): piglow.leg_bar(0, x / 100.0) #piglow.leg_bar(1, x / 100.0) #piglow.leg_bar(2, x / 100.0) piglow.yellow(200) piglow.show() time.sleep(0.01) elif hourlyData.icon == "rain": for x in range(100): piglow.leg_bar(0, x / 100.0) #piglow.leg_bar(1, x / 100.0) #piglow.leg_bar(2, x / 100.0) piglow.blue(200) piglow.show() time.sleep(0.01) for x in reversed(range(100)): piglow.leg_bar(0, x / 100.0) #piglow.leg_bar(1, x / 100.0) #piglow.leg_bar(2, x / 100.0) piglow.blue(200) piglow.show() time.sleep(0.01) elif hourlyData.icon == "snow": for x in range(100): piglow.leg_bar(0, x / 100.0) #piglow.leg_bar(1, x / 100.0) #piglow.leg_bar(2, x / 100.0)
type=int, default=8888, help="The port the mobile osc display is listening on", ) args = parser.parse_args() display_client = udp_client.UDPClient(args.display_ip, args.display_port) pressure_client = udp_client.UDPClient(args.pressure_ip, args.pressure_port) mobile_client = udp_client.UDPClient(args.mobile_ip, args.mobile_port) watchdog_led = False while True: try: metrics.persist() update_pressure() update_imu() update_temperature() update_disk_usage() new_data = gps_socket.next() if new_data: data_stream.unpack(new_data) update_position(data_stream) if not watchdog_led: piglow.blue(64) else: piglow.blue(0) watchdog_led = not watchdog_led broadcast_last() except Exception as exception: logger.error(exception)
import piglow from time import sleep import psutil piglow.auto_update = True while True: cpu = psutil.cpu_percent() #piglow.all(0) if cpu < 5: piglow.all(0) if cpu > 10: piglow.white(20) if cpu > 20: piglow.blue(20) if cpu > 40: piglow.green(20) if cpu > 60: piglow.yellow(20) if cpu > 80: piglow.orange(20) if cpu > 90: piglow.red(20) piglow.show() sleep(0.01)
#requires piglow & gpiozero already installed ###################################### # begin user customizable parameters # ###################################### ledpin = 16 # specifies the pin the button LED is connected to blueintensity = 128 #specifies the intensity with which the blue light will shine sunriseduration = 3 #number of seconds for the sun to stay risen ##################################### # end user customizable parameters # ##################################### import piglow from gpiozero import LED from time import sleep piglow.blue(blueintensity) piglow.show() led = LED(ledpin) led.on() sleep(sunriseduration) led.off()