Skip to content

Commit

Permalink
fix: add workaround to vibrate runtime error; resolves #22
Browse files Browse the repository at this point in the history
  • Loading branch information
iomz committed Aug 11, 2023
1 parent 0313c5c commit 2fd513d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions myo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)
Expand All @@ -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}")

Expand Down

0 comments on commit 2fd513d

Please sign in to comment.