From 454329f8cb32db3ad792c1f55e5325b9a4651a3b Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 3 Sep 2020 18:35:02 -0700 Subject: [PATCH] started with config reports --- adafruit_bno080/__init__.py | 71 +++++++++++++++++++++++++++++-- adafruit_bno080/reports.py | 18 ++++++++ examples/bno080_shake_detector.py | 31 ++++++++++++++ 3 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 adafruit_bno080/reports.py create mode 100644 examples/bno080_shake_detector.py diff --git a/adafruit_bno080/__init__.py b/adafruit_bno080/__init__.py index 0e245b2..b45220a 100644 --- a/adafruit_bno080/__init__.py +++ b/adafruit_bno080/__init__.py @@ -51,6 +51,8 @@ _BNO_CMD_TIMESTAMP_REBASE = const(0xFA) +_SHTP_REPORT_FRS_READ_RESPONSE = const(0xF3) +_SHTP_REPORT_FRS_READ_REQUEST = const(0xF4) _SHTP_REPORT_PRODUCT_ID_RESPONSE = const(0xF8) _SHTP_REPORT_PRODUCT_ID_REQUEST = const(0xF9) @@ -78,7 +80,7 @@ _BNO_REPORT_GEOMAGNETIC_ROTATION_VECTOR = const(0x09) _BNO_REPORT_STEP_COUNTER = const(0x11) _BNO_REPORT_SHAKE_DETECTOR = const(0x19) - +# 0x7D7D _DEFAULT_REPORT_INTERVAL = const(50000) # in microseconds = 50ms _QUAT_READ_TIMEOUT = 0.500 # timeout in seconds @@ -89,7 +91,6 @@ _Q_POINT_14_SCALAR = 2 ** (14 * -1) _Q_POINT_12_SCALAR = 2 ** (12 * -1) -# _Q_POINT_10_SCALAR = 2 ** (10 * -1) _Q_POINT_9_SCALAR = 2 ** (9 * -1) _Q_POINT_8_SCALAR = 2 ** (8 * -1) _Q_POINT_4_SCALAR = 2 ** (4 * -1) @@ -99,9 +100,11 @@ _QUAT_SCALAR = _Q_POINT_14_SCALAR _GEO_QUAT_SCALAR = _Q_POINT_12_SCALAR _MAG_SCALAR = _Q_POINT_4_SCALAR + +_FRS_RECORD_SHAKE = 0x7D7D # _QUAT_RADIAN_ACCURACY_SCALAR = _Q_POINT_12_SCALAR # _ANGULAR_VELOCITY_SCALAR = _Q_POINT_10_SCALAR - +_FRS_RECORD_DATA = {_FRS_RECORD_SHAKE: (5,)} _REPORT_LENGTHS = { _SHTP_REPORT_PRODUCT_ID_RESPONSE: 16, _BNO_CMD_GET_FEATURE_RESPONSE: 17, @@ -123,6 +126,8 @@ } DATA_BUFFER_SIZE = const(512) # data buffer size. obviously eats ram +REPORT_BUFFER_SIZE = const(32) + PacketHeader = namedtuple( "PacketHeader", ["channel_number", "sequence_number", "data_length", "packet_byte_count",], @@ -178,6 +183,15 @@ def _parse_step_couter_report(report_bytes): def _parse_shake_report(report_bytes): + """ + 0 Report ID = 0x19 + 1 Sequence number + 2 Status + 3 Delay + 4 Shake LSB + 5 Shake MSB + """ + shake_bitfield = unpack_from(" 0 @@ -224,6 +238,50 @@ def _separate_batch(packet, report_slices): next_byte_index = next_byte_index + required_bytes +def _pack_frs_read_request(record_id, report_buffer, offset=0, block_size=0): + """Create a FRS record read request report in the report buffer + + Args: + offset ([unsigned 16-bit int]): [The offset in 32-bit words into the record to start reading from ] + record_id ([unsigned 16-bit int]): [The ID of the record to read] + block_size ([type]): [The number of 32-bit words to read] + """ + # offset, in 32-bit words, from the beginning of the FRS record at which + # to begin the read operation. The first word in an FRS record is word 0. + # number of 32-bit words to read. If the block size is zero then the entire + # record beginning at the read offset is returned + + # 0 Report ID = 0xF4 + # 1 Reserved + # 2 Read Offset LSB + # 4 FRS Type LSB + # 6 Block Size LSB + + pack_into("> 4 + status = status_length_raw & 0x0F + word_offset = unpack_from("