@@ -143,12 +143,7 @@ async def command(self, client: BleakClient, cmd: Command):
143
143
"""
144
144
Command Characteristic
145
145
"""
146
- try :
147
- await client .write_gatt_char (Handle .COMMAND .value , cmd .data , True )
148
- except AttributeError :
149
- # wait a bit and try once again
150
- await asyncio .sleep (0.1 )
151
- await client .write_gatt_char (Handle .COMMAND .value , cmd .data , True )
146
+ await client .write_gatt_char (Handle .COMMAND .value , cmd .data , True )
152
147
153
148
async def deep_sleep (self , client : BleakClient ):
154
149
"""
@@ -241,6 +236,7 @@ def __init__(self, aggregate_all=False, aggregate_emg=False):
241
236
self ._client = None
242
237
self .fv_aggregated = None # for aggregate_all
243
238
self .imu_aggregated = None # for aggregate_all
239
+ self ._lock = asyncio .Lock () # for aggregate_all
244
240
245
241
@classmethod
246
242
async def with_device (cls , mac = None , aggregate_all = False , aggregate_emg = False ):
@@ -337,15 +333,16 @@ async def on_data(self, data):
337
333
"""
338
334
<> for on_aggregated_data: data is either FVData or IMUData
339
335
"""
340
- if isinstance (data , FVData ):
341
- self .fv_aggregated = data
342
- elif isinstance (data , IMUData ):
343
- self .imu_aggregated = data
344
- # trigger on_aggregated_data when both FVData and IMUData are ready
345
- if all ((self .fv_aggregated , self .imu_aggregated )):
346
- await self .on_aggregated_data (AggregatedData (self .fv_aggregated , self .imu_aggregated ))
347
- self .fv_aggregated = None
348
- self .imu_aggregated = None
336
+ async with self ._lock :
337
+ if isinstance (data , FVData ):
338
+ self .fv_aggregated = data
339
+ elif isinstance (data , IMUData ):
340
+ self .imu_aggregated = data
341
+ # trigger on_aggregated_data when both FVData and IMUData are ready
342
+ if all (d is not None for d in (self .fv_aggregated , self .imu_aggregated )):
343
+ await self .on_aggregated_data (AggregatedData (self .fv_aggregated , self .imu_aggregated ))
344
+ self .fv_aggregated = None
345
+ self .imu_aggregated = None
349
346
350
347
async def on_aggregated_data (self , ad : AggregatedData ):
351
348
"""
0 commit comments