giving loop to other classes may keep the other loops from crashing/becoming un-useable.
This commit is contained in:
+6
-9
@@ -17,24 +17,21 @@ class MyWand(Wand):
|
||||
# # Vibrate the wand and set its color to red
|
||||
# self.set_led(self.colors.pop())
|
||||
# # Subscribe to notifications
|
||||
# self.subscribe_button()
|
||||
self.subscribe_button()
|
||||
|
||||
# Button callback, automatically called after connecting to wand
|
||||
def on_button(self, pressed):
|
||||
async def on_button(self, pressed):
|
||||
if pressed:
|
||||
# Unsubscribe from the position callback
|
||||
# NOTE You could pass `continue_notifications=True`
|
||||
# to continue using the wand's `on_position` function
|
||||
|
||||
self.set_led(self.colors.pop())
|
||||
await self.set_led(self.colors.pop())
|
||||
# Disconnect if we run out of colors
|
||||
if len(self.colors) == 0:
|
||||
self.disconnect()
|
||||
await self.disconnect()
|
||||
|
||||
async def main():
|
||||
|
||||
# Create a new wand scanner
|
||||
shop = Shop(wand_class=MyWand, debug=True)
|
||||
shop = Shop(asyncio.get_running_loop(), wand_class=MyWand, debug=True)
|
||||
wands = []
|
||||
try:
|
||||
# While we don't have any wands
|
||||
@@ -45,7 +42,7 @@ async def main():
|
||||
# For each wand (Only tested with one)
|
||||
for wand in wands:
|
||||
# Vibrate the wand and set its color to red
|
||||
wand.vibrate(PATTERN.BURST)
|
||||
await wand.vibrate(PATTERN.BURST)
|
||||
|
||||
# Callback for position
|
||||
# def onPos(x, y, pitch, roll):
|
||||
|
||||
Reference in New Issue
Block a user