|
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 Establishes a connection with the client (Nicla Sense ME) using the given type of communication (ESLOV/BLE/As shield). |
| 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 niclaConnection 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 Requests new sensor data from the client (Nicla Sense ME) and saves it locally so it can be retrieved via `Sensor` objects. |
| 63 | + * |
| 64 | + * @param ms (optional) Time (in milliseconds) to wait before returning data. |
| 65 | + */ |
39 | 66 | void update();
|
| 67 | + /** |
| 68 | + * @brief Requests new sensor data from the client (Nicla Sense ME) and saves it locally so it can be retrieved via `Sensor` objects. The Nicla Sense ME's sensors are then put to sleep for the given amount of milliseconds. |
| 69 | + * |
| 70 | + * @param ms (optional) time to set Nicla Sense ME to sleep in milliseconds |
| 71 | + */ |
40 | 72 | void update(unsigned long ms); // Update and then sleep
|
41 | 73 |
|
42 | 74 | // Functions for controlling the BHY when PASSTHROUGH is DISABLED
|
| 75 | + /** |
| 76 | + * @brief Configures a sensor to be read using a given sample rate and latency. The configuration is packaged up in a `SensorConfigurationPacket` object. |
| 77 | + * |
| 78 | + * @param config Instance of @see SensorConfigurationPacket class, with sensorID, sampleRate and latency |
| 79 | + * |
| 80 | + * @code |
| 81 | + * #set virtual sensor SENSOR_ID_DEVICE_ORI_WU to have sample rate of 1 Hz and latency of 500 milliseconds |
| 82 | + * SensorConfigurationPacket config(70, 1, 500); |
| 83 | + * BHY2.configureSensor(config) |
| 84 | + * @endcode |
| 85 | + * |
| 86 | + * @note Alternatively, we can directly configure the virtual sensor without creating a SensorConfigurationPacket class |
| 87 | + * |
| 88 | + * @param sensorId SensorID for virtual sensor |
| 89 | + * @param sampleRate Polling rate for sensor in Hz |
| 90 | + * @param latency Latency in milliseconds |
| 91 | + * |
| 92 | + * @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> |
| 93 | + * |
| 94 | + */ |
43 | 95 | void configureSensor(SensorConfigurationPacket& config);
|
44 | 96 | void configureSensor(uint8_t sensorId, float sampleRate, uint32_t latency);
|
| 97 | + /** |
| 98 | + * @brief Recieve acknowledgement from Nicla board over ESLOV |
| 99 | + * |
| 100 | + * @return uint8_t One byte of data read from the I2C bus. |
| 101 | + */ |
45 | 102 | uint8_t requestAck();
|
| 103 | + /** |
| 104 | + * @brief Return available sensor data within the FIFO buffer queue |
| 105 | + * |
| 106 | + * @return uint8_t Amount of bytes. |
| 107 | + */ |
46 | 108 | uint8_t availableSensorData();
|
| 109 | + /** |
| 110 | + * @brief Return available long sensor data within the FIFO buffer queue |
| 111 | + * |
| 112 | + * @return uint8_t Returns the amount of 16 bit chunks of the available sensor data. |
| 113 | + */ |
47 | 114 | uint8_t availableSensorLongData();
|
| 115 | + /** |
| 116 | + * @brief Read sensor data from the top element of the queue |
| 117 | + * |
| 118 | + * @param data SensorDataPacket object including SensorID, size, and data payload |
| 119 | + */ |
48 | 120 | bool readSensorData(SensorDataPacket &data);
|
| 121 | + /** |
| 122 | + * @brief Read long sensor data from the top element of the queue |
| 123 | + * |
| 124 | + * @param data SensorDataPacket object including SensorID, size , and data payload |
| 125 | + */ |
49 | 126 | bool readSensorLongData(SensorLongDataPacket &data);
|
50 |
| - |
| 127 | + /** |
| 128 | + * @brief Parse XYZ Cartesian data from `SensorDataPacket` and store within `DataXYZ` vector |
| 129 | + * |
| 130 | + * @param data SensorDataPacket object including SensorID, size, and data payload |
| 131 | + * @param vector DataXYZ vector with XYZ values stores as int16_t |
| 132 | + */ |
51 | 133 | void parse(SensorDataPacket& data, DataXYZ& vector);
|
| 134 | + /** |
| 135 | + * @brief Parse orientation data from `SensorDataPacket` and store within `DataOrientation` vector. Optional argument for scale factor |
| 136 | + * |
| 137 | + * @param data SensorDataPacket object including SensorID, size, and data payload |
| 138 | + * @param vector DataOrientation vector with heading, pitch and roll stored as float |
| 139 | + * @param scaleFactor (optional) scale factor for vector. Defined by format "Euler". See section 15.1.2 in datasheet. |
| 140 | + */ |
52 | 141 | void parse(SensorDataPacket& data, DataOrientation& vector);
|
53 | 142 | void parse(SensorDataPacket& data, DataOrientation& vector, float scaleFactor);
|
54 | 143 |
|
|
0 commit comments