From 2fd513d87c504b0826998da647557af2cef77909 Mon Sep 17 00:00:00 2001 From: Iori Mizutani Date: Fri, 11 Aug 2023 11:52:07 +0200 Subject: [PATCH] fix: add workaround to vibrate runtime error; resolves #22 --- myo/core.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/myo/core.py b/myo/core.py index a34ef9e..86756bb 100644 --- a/myo/core.py +++ b/myo/core.py @@ -210,7 +210,10 @@ async def vibrate(self, client: BleakClient, vibration_type): """ Vibrate Command """ - await self.command(client, Vibrate(vibration_type)) + try: + await self.command(client, Vibrate(vibration_type)) + except AttributeError: + logger.debug(f"Myo.vibrate() raised AttributeError, BleakClient.is_connected: {client.is_connected}") async def vibrate2(self, client: BleakClient, duration, strength): """ @@ -501,10 +504,6 @@ async def stop(self): """ <> stop notify/indicate """ - # vibrate short*2 - await self.vibrate(VibrationType.SHORT) - await self.vibrate(VibrationType.SHORT) - # unsubscribe from notify/indicate if self.emg_mode in [EMGMode.SEND_EMG, EMGMode.SEND_RAW]: await self.stop_notify(Handle.EMG0_DATA.value) @@ -520,6 +519,13 @@ async def stop(self): if self.classifier_mode == ClassifierMode.ENABLED: await self.stop_notify(Handle.CLASSIFIER_EVENT.value) + # vibrate short*2 + try: + await self.vibrate(VibrationType.SHORT) + await self.vibrate(VibrationType.SHORT) + except AttributeError: + await asyncio.sleep(0.1) + await self.led(RGB_GREEN) logger.info(f"stopped notification from {self.device.name}")