Skip to content

Commit

Permalink
Add microbit accelerometer subscription (#417)
Browse files Browse the repository at this point in the history
* Add microbit accelerometer subscription

* fix docstring lint error
  • Loading branch information
WayneKeenan authored Oct 24, 2024
1 parent e120285 commit 90f38a0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bluezero/microbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def __init__(self, device_addr, adapter_addr=None, **kwargs):
self.user_btn_b_callback = None
self.user_calibrate_cb = None
self.uart_tx_cb = None
self.user_accel_cb = None

# Micro:bit Characteristics
# if accelerometer_service:
Expand Down Expand Up @@ -392,6 +393,22 @@ def accelerometer(self):

return tools.bytes_to_xyz(accel_bytes)

def _decode_accel(self, *accel_values):
"""Decode accelerometer values and pass on to user callback."""
self.user_accel_cb(*tools.bytes_to_xyz(accel_values[1]['Value']))

def subscribe_accelerometer(self, user_callback):
"""
Execute user_callback on data being received on accelerometer service
:param user_callback: User callback method receiving the accelerometer
values
:return:
"""
self.user_accel_cb = user_callback
self._accel_data.add_characteristic_cb(self._decode_accel)
self._accel_data.start_notify()

@property
def magnetometer(self):
"""
Expand Down

0 comments on commit 90f38a0

Please sign in to comment.