Ading data collection script for spell capturing
This commit is contained in:
+22
-14
@@ -1,8 +1,6 @@
|
||||
from shop import Shop
|
||||
from wand import Wand
|
||||
from constants import *
|
||||
from KanoWandAsync import Shop, Wand
|
||||
from KanoWandAsync.constants import *
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
# Custom wand class extending the default wand
|
||||
class MyWand(Wand):
|
||||
@@ -12,22 +10,39 @@ class MyWand(Wand):
|
||||
self.position_id = None
|
||||
|
||||
# Do some functions after connecting
|
||||
def post_connect(self):
|
||||
async def post_connect(self):
|
||||
print("Connected to {}".format(self.name))
|
||||
# # Vibrate the wand and set its color to red
|
||||
# self.set_led(self.colors.pop())
|
||||
# # Subscribe to notifications
|
||||
self.subscribe_button()
|
||||
await self.subscribe_button()
|
||||
await self.subscribe_position()
|
||||
await self.get_organization()
|
||||
await self.subscribe_battery()
|
||||
await self.subscribe_temperature()
|
||||
|
||||
|
||||
# Button callback, automatically called after connecting to wand
|
||||
async def on_button(self, pressed):
|
||||
if pressed:
|
||||
await self.vibrate(PATTERN.BURST)
|
||||
# Unsubscribe from the position callback
|
||||
await self.set_led(self.colors.pop())
|
||||
await self.reset_position()
|
||||
# Disconnect if we run out of colors
|
||||
if len(self.colors) == 0:
|
||||
await self.disconnect()
|
||||
|
||||
async def on_position(self, x, y, pitch, roll):
|
||||
print(x, y, pitch, roll)
|
||||
|
||||
async def on_battery(self, value):
|
||||
print("Battery:", value)
|
||||
|
||||
async def on_temperature(self, value):
|
||||
print("Temperature", value)
|
||||
|
||||
|
||||
async def main():
|
||||
|
||||
# Create a new wand scanner
|
||||
@@ -43,15 +58,8 @@ async def main():
|
||||
for wand in wands:
|
||||
# Vibrate the wand and set its color to red
|
||||
await wand.vibrate(PATTERN.BURST)
|
||||
await asyncio.sleep(20)
|
||||
|
||||
# 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:
|
||||
|
||||
Reference in New Issue
Block a user