giving loop to other classes may keep the other loops from crashing/becoming un-useable.

This commit is contained in:
Lucas Oskorep
2020-03-06 10:32:43 -06:00
parent d58229f0a1
commit f9c9b9fc8c
3 changed files with 25 additions and 26 deletions
+6 -9
View File
@@ -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):