adding files for the commit

This commit is contained in:
Lucas Oskorep
2019-11-09 21:09:27 -06:00
parent 40c4e01f55
commit e91c870eca
71 changed files with 1923 additions and 56 deletions
+21 -9
View File
@@ -1,5 +1,7 @@
import logging
import struct
from time import sleep
from converters import BinToInt, BinToFloat
from .wand_sensors import *
from bleak import BleakClient
@@ -17,8 +19,9 @@ class KanoBLEClient(object):
self.decoder = wand_decoder()
self.wand_sensors = WandSensors(self.sensor_update_handler)
self.loop = loop
self.dateframe_handler = None
async def connect_and_read(self, debug=False):
async def connect(self, debug=False):
if debug:
import sys
l = logging.getLogger("asyncio")
@@ -28,25 +31,34 @@ class KanoBLEClient(object):
l.addHandler(h)
logger.addHandler(h)
async with BleakClient(self.wand_address, loop=self.loop) as client:
self.client = client
x = await client.is_connected()
logger.info("Connected: {0}".format(x))
await start_notify(self.client, self.sensor_handling)
self.client = BleakClient(self.wand_address, loop=self.loop)
await self.client.connect()
x = await self.client.is_connected()
logger.info("Connected: {0}".format(x))
async def stop_recieving_data(self):
await stop_notify(self.client)
async def start_recieving_data(self, sensors=None):
await start_notify(self.client, self.sensor_handling, sensors)
async def stop_recieving_data(self, sensors):
await stop_notify(self.client, sensors)
def change_spell(self, spell):
self.wand_sensors.data_folder = "./training_data/" + spell + "/"
print(f"changed wand folder to {self.wand_sensors.data_folder}")
def sensor_update_handler(self, sensors):
print(sensors)
# print("SENSORS RECIEVED")
return
def sensor_handling(self, sender, data):
"""Simple notification handler which prints the data received."""
sender = CHARACTERISTIC_UUIDS[sender]
sender = get_key(sender, CHARACTERISTIC_UUIDS)
if sender == BUTTON:
self.wand_sensors.set_button(self.decoder.decode_button(data))
self.loop.run_until_complete(self.client.write_gatt_char(RESET_CHAR, struct.pack("h", 1)))
elif sender == NINE_AXIS:
self.wand_sensors.set_gyro(*self.decoder.decode_nine_axis(data))
elif sender == ACCELEROMETER: