|
21 | 21 | #endif
|
22 | 22 |
|
23 | 23 |
|
24 |
| - |
| 24 | +/** |
| 25 | + * @brief Enumeration for defining wiring configuration between host board and Nicla client. We can select between an I2C connection over ESLOV (NICLA_VIA_ESLOV) or as a Shield for the MKR boards (NICAL_AS_SHIELD). |
| 26 | + * |
| 27 | + * For NICLA_AS_SHIELD configuration, see https://docs.arduino.cc/tutorials/nicla-sense-me/use-as-mkr-shield |
| 28 | + * |
| 29 | + */ |
25 | 30 | enum NiclaWiring {
|
26 |
| - NICLA_VIA_ESLOV = 0, |
27 |
| - NICLA_AS_SHIELD, |
28 |
| - NICLA_VIA_BLE |
| 31 | + NICLA_VIA_ESLOV = 0, /*!< Host connects to Nicla board via ESLOV */ |
| 32 | + NICLA_AS_SHIELD, /*!< Host connects to Nicla board as a Shield */ |
| 33 | + NICLA_VIA_BLE /*!< Host connects to Nicla board via BLE */ |
29 | 34 | };
|
30 | 35 |
|
31 | 36 |
|
| 37 | +/** |
| 38 | + * @brief Class to interface with the Bosch BHI260 sensor hub on the Nicla Sense ME. |
| 39 | + * Provides functionality for reading/configuring sensors based on sensor ID and accessing debug features. |
| 40 | +*/ |
32 | 41 | class Arduino_BHY2Host {
|
33 | 42 | public:
|
34 | 43 | Arduino_BHY2Host();
|
35 | 44 | virtual ~Arduino_BHY2Host();
|
36 | 45 |
|
37 | 46 | // Necessary API. Update function should be continuously polled if PASSTHORUGH is ENABLED
|
| 47 | + /** |
| 48 | + * @brief Initialise the BHY2 functionality on the host board, for a given @ref NiclaWiring configuration. |
| 49 | + * |
| 50 | + * @note When called without input parameters, I2C communication is over ESLOV by default. |
| 51 | + * |
| 52 | + * @param passthrough Define passthrough state. Disabled by default |
| 53 | + * @param NiclaWiring Defining I2C configuration (NICLA_VIA_ESLOV, NICLA_AS_SHIELD or NICLA_VIA_BLE). @see NiclaWiring |
| 54 | + * |
| 55 | + * Configuring for operation as a Shield: |
| 56 | + * @code |
| 57 | + * BHY2Host.begin(NICLA_VIA_BLE); |
| 58 | + * @endcode |
| 59 | + */ |
38 | 60 | bool begin(bool passthrough = false, NiclaWiring niclaConnection = NICLA_VIA_ESLOV);
|
| 61 | + /** |
| 62 | + * @brief Update sensor data by reading the FIFO buffer on the BHI260 and then pass it to a suitable parser. |
| 63 | + * |
| 64 | + * @param ms (optional) Time (in milliseconds) to wait before returning data. |
| 65 | + */ |
39 | 66 | void update();
|
40 | 67 | void update(unsigned long ms); // Update and then sleep
|
41 | 68 |
|
42 | 69 | // Functions for controlling the BHY when PASSTHROUGH is DISABLED
|
| 70 | + /** |
| 71 | + * @brief Configure a virtual sensor on the BHI260 to have a set sample rate (Hz) and latency (milliseconds) |
| 72 | + * This can be achieved |
| 73 | + * |
| 74 | + * @param config Instance of @see SensorConfigurationPacket class, with sensorID, sampleRate and latency |
| 75 | + * |
| 76 | + * @code |
| 77 | + * #set virtual sensor SENSOR_ID_DEVICE_ORI_WU to have sample rate of 1 Hz and latency of 500 milliseconds |
| 78 | + * SensorConfigurationPacket config(70, 1, 500); |
| 79 | + * BHY2.configureSensor(config) |
| 80 | + * @endcode |
| 81 | + * |
| 82 | + * @note Alternatively, we can directly configure the virtual sensor without creating a SensorConfigurationPacket class |
| 83 | + * |
| 84 | + * @param sensorId SensorID for virtual sensor |
| 85 | + * @param sampleRate Polling rate for sensor in Hz |
| 86 | + * @param latency Latency in milliseconds |
| 87 | + * |
| 88 | + * @note For list of SensorID, see src/SensorID.h. Or see Table 79 in the <a href="https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bhi260ab-ds000.pdf">BHI260 datasheet</a> |
| 89 | + * |
| 90 | + */ |
43 | 91 | void configureSensor(SensorConfigurationPacket& config);
|
44 | 92 | void configureSensor(uint8_t sensorId, float sampleRate, uint32_t latency);
|
45 | 93 | uint8_t requestAck();
|
| 94 | + /** |
| 95 | + * @brief Return available sensor data within the FIFO buffer queue |
| 96 | + * |
| 97 | + * @return uint8_t The amount of data in bytes |
| 98 | + */ |
46 | 99 | uint8_t availableSensorData();
|
| 100 | + /** |
| 101 | + * @brief Return available long sensor data within the FIFO buffer queue |
| 102 | + * |
| 103 | + * @return uint8_t The amount of data in bytes |
| 104 | + */ |
47 | 105 | uint8_t availableSensorLongData();
|
| 106 | + /** |
| 107 | + * @brief Read sensor data from the top element of the queue |
| 108 | + * |
| 109 | + * @param data Structure including sensorID, sampleRate and latency |
| 110 | + */ |
48 | 111 | bool readSensorData(SensorDataPacket &data);
|
| 112 | + /** |
| 113 | + * @brief Read long sensor data from the top element of the queue |
| 114 | + * |
| 115 | + * @param data Structure including sensorID, sampleRate and latency |
| 116 | + */ |
49 | 117 | bool readSensorLongData(SensorLongDataPacket &data);
|
50 |
| - |
| 118 | + /** |
| 119 | + * @brief Parse XYZ Cartesian data from a given data packet |
| 120 | + * |
| 121 | + * @param data data packet including SensorID |
| 122 | + * @param vector vector with XYZ |
| 123 | + */ |
51 | 124 | void parse(SensorDataPacket& data, DataXYZ& vector);
|
| 125 | + /** |
| 126 | + * @brief Parse orientation from a given data packet |
| 127 | + * |
| 128 | + * @param data Data packet including SensorID |
| 129 | + * @param vector Vector with heading, pitch and roll |
| 130 | + */ |
52 | 131 | void parse(SensorDataPacket& data, DataOrientation& vector);
|
| 132 | + /** |
| 133 | + * @brief Parse orientation with scale factor |
| 134 | + * |
| 135 | + * @param data Data packet including SensorID |
| 136 | + * @param vector Vector with heading, pitch and roll |
| 137 | + * @param scaleFactor scale factor for vector |
| 138 | + */ |
53 | 139 | void parse(SensorDataPacket& data, DataOrientation& vector, float scaleFactor);
|
54 | 140 |
|
55 | 141 | NiclaWiring getNiclaConnection();
|
|
0 commit comments