Skip to content

Commit

Permalink
fix: make the on_* callback methods async
Browse files Browse the repository at this point in the history
  • Loading branch information
iomz committed Jun 20, 2023
1 parent 3ec8fcb commit e3ea052
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/sample_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class SampleClient(MyoClient):
def on_fv_data(self, fvd: FVData):
async def on_fv_data(self, fvd: FVData):
logging.info(f"{Handle.FV_DATA.name}: {fvd.json()}")


Expand Down
28 changes: 14 additions & 14 deletions myo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def disconnect(self):
self._client = None
logger.info(f"disconnected from {self.device.name}")

def emg_data_aggregate(self, handle, emg_data: EMGData):
async def emg_data_aggregate(self, handle, emg_data: EMGData):
"""
<> aggregate the raw EMG data channels
"""
Expand All @@ -108,8 +108,8 @@ def emg_data_aggregate(self, handle, emg_data: EMGData):
Handle.EMG2_DATA,
Handle.EMG3_DATA,
]:
self.on_emg_data(emg_data.sample1)
self.on_emg_data(emg_data.sample2)
await self.on_emg_data(emg_data.sample1)
await self.on_emg_data(emg_data.sample2)

async def get_services(self, indent=1) -> str:
"""
Expand Down Expand Up @@ -146,36 +146,36 @@ async def led(self, color):
"""
await self.m.led(self._client, color, color)

def on_classifier_event(self, ce: ClassifierEvent):
async def on_classifier_event(self, ce: ClassifierEvent):
raise NotImplementedError()

def on_emg_data(self, emg): # data: list of 8 8-bit unsigned short
async def on_emg_data(self, emg): # data: list of 8 8-bit unsigned short
raise NotImplementedError()

def on_fv_data(self, fvd: FVData):
async def on_fv_data(self, fvd: FVData):
raise NotImplementedError()

def on_imu_data(self, imu: IMUData):
async def on_imu_data(self, imu: IMUData):
raise NotImplementedError()

def on_motion_event(self, me: MotionEvent):
async def on_motion_event(self, me: MotionEvent):
raise NotImplementedError()

def notify_callback(self, sender: BleakGATTCharacteristic, data: bytearray):
async def notify_callback(self, sender: BleakGATTCharacteristic, data: bytearray):
"""
<> invoke the on_* callbacks
"""
handle = Handle(sender.handle)
if handle == Handle.CLASSIFIER_EVENT:
self.on_classifier_event(ClassifierEvent(data))
await self.on_classifier_event(ClassifierEvent(data))
elif handle == Handle.FV_DATA:
self.on_fv_data(FVData(data))
await self.on_fv_data(FVData(data))
elif handle == Handle.IMU_DATA:
self.on_imu_data(IMUData(data))
await self.on_imu_data(IMUData(data))
elif handle == Handle.MOTION_EVENT:
self.on_motion_event(MotionEvent(data))
await self.on_motion_event(MotionEvent(data))
else: # on EMG[0-3]_DATA handle
self.emg_data_aggregate(handle, EMGData(data))
await self.emg_data_aggregate(handle, EMGData(data))

async def set_mode(self, emg_mode, imu_mode, classifier_mode):
"""
Expand Down

0 comments on commit e3ea052

Please sign in to comment.