def main(): # If we pass a -d flag, enable debugging debug = False if len(sys.argv) > 1: debug = sys.argv[1] == "-d" # Create a new wand scanner shop = Shop(wand_class=MyWand, debug=debug) wands = [] try: # While we don't have any wands while len(wands) == 0: # Scan for wands and automatically connect print("Scanning...") wands = shop.scan(connect=True) # For each wand (Only tested with one) for wand in wands: # Vibrate the wand and set its color to red wand.vibrate(PATTERN.BURST) # Callback for position def onPos(x, y, pitch, roll): pitch = "Pitch: {}".format(pitch).ljust(16) roll = "Roll: {}".format(roll).ljust(16) print("{}{}(x, y): ({}, {})".format(pitch, roll, x, y)) # Add the event callback to the wand wand.position_id = wand.on("position", onPos) # Detect keyboard interrupt disconnect except KeyboardInterrupt as e: for wand in wands: wand.disconnect()
def main(): client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message client.connect("localhost", 1883, 60) client.subscribe("homeassistant/#") client.subscribe("stat/#") client.loop_start() shop = Shop(wand_class=GestureWand) wands = [] try: while len(wands) == 0: print("Scanning...") wands = shop.scan(connect=True) wand = wands[0] while wand.connected: sleep = random.uniform(0.1, 0.2) if wand.spell is "lumos": publish_all(client, "power", "On") elif wand.spell is "nox": publish_all(client, "power", "Off") elif wand.spell is "engorgio": publish_all(client, "dimmer", "+") elif wand.spell is "reducto": publish_all(client, "dimmer", "-") wand.spell = None time.sleep(sleep) except KeyboardInterrupt as e: for wand in wands: wand.disconnect() client.loop_stop()
def main(): # If we pass a -d flag, enable debugging debug = False if len(sys.argv) > 1: debug = sys.argv[1] == "-d" # Create a new wand scanner shop = Shop(debug=debug) wands = [] try: # While we don't have any wands while len(wands) == 0: # Scan for wands and automatically connect print("Scanning...") wands = shop.scan(connect=True) # For each wand (Only tested with one) for wand in wands: print("Connected to {}".format(wand.name)) colors = [ "#a333c8", "2185d0", "0x21ba45", "#fbbd08", "#f2711c", "#db2828" ] # Vibrate the wand and set its color to red wand.vibrate(PATTERN.BURST) wand.set_led(colors.pop()) # Callback for position def onPos(x, y, pitch, roll): pitch = "Pitch: {}".format(pitch).ljust(16) roll = "Roll: {}".format(roll).ljust(16) print("{}{}(x, y): ({}, {})".format(pitch, roll, x, y)) # Add the position callback to the wand position_id = wand.on("position", onPos) # Callback for button presses def onButton(pressed): global wand global colors global position_id # If the button was pressed if pressed: if position_id != None: wand.off(position_id) position_id = None # Update the led wand.set_led(colors.pop()) # Disconnect if we run out of colors if len(colors) == 0: wand.disconnect() # Add the button callback to the wand wand.on("button", onButton) # Detect keyboard interrupt and disconnect wands except KeyboardInterrupt as e: for wand in wands: wand.disconnect()
def main(): # Create the manager and shop to search for wands manager = LightManager() shop = Shop(wand_class=GestureWand) wands = [] try: # Scan for wands until it finds some while len(wands) == 0: print("Scanning...") wands = shop.scan(connect=True) wand = wands[0] while wand.connected: # Make a random sleep and transition time sleep = random.uniform(0.1, 0.2) transition = math.ceil(sleep * 10) # Flicker the bulb and sleep manager.flicker(wand, transition) time.sleep(sleep) # Reset bulbs to initial state when wand disconnects manager.reset() # Detect keyboard interrupt and disconnect wands, reset light except KeyboardInterrupt as e: for wand in wands: wand.disconnect() manager.reset()
def main(): # If we pass a -d flag, enable debugging debug = False if len(sys.argv) > 1: debug = sys.argv[1] == "-d" # Create a new wand scanner shop = Shop(wand_class=MyWand, debug=debug) wands = [] try: # While we don't have any wands while len(wands) == 0: # Scan for wands and automatically connect print("Scanning...") wands = shop.scan(connect=True) # Detect keyboard interrupt and disconnect wands except KeyboardInterrupt as e: for wand in wands: wand.disconnect()
from kano_wand.kano_wand import Shop, PATTERN import time shop = Shop() while True: wands = shop.scan() if len(wands): print(wands[0]._dev.rssi) else: print("Out of range")
def on_button(self, pressed): x_pos, y_pos = self._m.position() if pressed: self._m.press(x_pos, y_pos, 1 if self.left else 2) self.pressed_left = self.left else: self._m.release(x_pos, y_pos, 1 if self.left else 2) if self.pressed_left and not self.left: self.disconnect() # If we pass a -d flag, enable debugging debug = False if len(sys.argv) > 1: debug = sys.argv[1] == "-d" # Create a new wand scanner shop = Shop(wand_class=MouseWand, debug=debug) wands = [] try: # While we don't have any wands while len(wands) == 0: print("Scanning...") # Scan for wands and automatically connect wands = shop.scan(connect=True) # Detect keyboard interrupt and disconnect wands except KeyboardInterrupt as e: for wand in wands: wand.disconnect()