-
-
Notifications
You must be signed in to change notification settings - Fork 27
[AE-51] Add documentation for BHY2Host #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,35 +21,121 @@ | |||||||
| #endif | ||||||||
|
|
||||||||
|
|
||||||||
|
|
||||||||
| /** | ||||||||
| * @brief Enumeration for defining wiring configuration over ESLOV, Shield or BLE. | ||||||||
| * | ||||||||
| * For NICLA_AS_SHIELD configuration, see https://docs.arduino.cc/tutorials/nicla-sense-me/use-as-mkr-shield | ||||||||
| * | ||||||||
| */ | ||||||||
| enum NiclaWiring { | ||||||||
| NICLA_VIA_ESLOV = 0, | ||||||||
| NICLA_AS_SHIELD, | ||||||||
| NICLA_VIA_BLE | ||||||||
| }; | ||||||||
|
|
||||||||
|
|
||||||||
| /** | ||||||||
| * @brief Main class for initialising communication with sensors | ||||||||
| */ | ||||||||
| class Arduino_BHY2Host { | ||||||||
| public: | ||||||||
| Arduino_BHY2Host(); | ||||||||
| virtual ~Arduino_BHY2Host(); | ||||||||
|
|
||||||||
| // Necessary API. Update function should be continuously polled if PASSTHORUGH is ENABLED | ||||||||
| /** | ||||||||
| * @brief | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| * | ||||||||
| * @param passthrough Enable Serial port at 115200 bps | ||||||||
| * @param niclaConnection Configuration for set @ref NiclaWiring state | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| * @return true Connection successful to the Nicla board | ||||||||
| * @return false Connection unsuccessful to the Nicla board | ||||||||
|
Comment on lines
+50
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to our style guide we should use a single @return statement. |
||||||||
| */ | ||||||||
| bool begin(bool passthrough = false, NiclaWiring niclaConnection = NICLA_VIA_ESLOV); | ||||||||
| /** | ||||||||
| * @brief Pings sensor | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| * | ||||||||
| * @note Sensor must be continuously polled to prevent sleep | ||||||||
| */ | ||||||||
| void update(); | ||||||||
| /** | ||||||||
| * @brief Pings sensor and then sleep | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| * | ||||||||
| * @note Delay does not stall microcontroller to sleep. See https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay | ||||||||
| */ | ||||||||
| void update(unsigned long ms); // Update and then sleep | ||||||||
|
|
||||||||
| // Functions for controlling the BHY when PASSTHROUGH is DISABLED | ||||||||
| /** | ||||||||
| * @brief Poll Bosch method | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| * | ||||||||
| * @param config Sensor configuration | ||||||||
| */ | ||||||||
| void configureSensor(SensorConfigurationPacket& config); | ||||||||
| /** | ||||||||
| * @brief Setup virtual sensors on the BHI260 | ||||||||
| * | ||||||||
| * @param sensorId Sensor ID for sensor | ||||||||
| * @param sampleRate Polling rate for sensor | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aliphys Please double check the unit of this. |
||||||||
| * @param latency Latency in milliseconds | ||||||||
| * | ||||||||
| * @note For list of SensorID, see src/SensorID.h | ||||||||
| */ | ||||||||
| void configureSensor(uint8_t sensorId, float sampleRate, uint32_t latency); | ||||||||
| /** | ||||||||
| * @brief Recieve acknowledgement from Nicla board over ESLOV | ||||||||
| * | ||||||||
| * @return uint8_t Data read from I2C bus | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| */ | ||||||||
| uint8_t requestAck(); | ||||||||
| /** | ||||||||
| * @brief Return available sensor data | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| * | ||||||||
| * @return uint8_t | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| */ | ||||||||
| uint8_t availableSensorData(); | ||||||||
| /** | ||||||||
| * @brief Return available long sensor data | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| * | ||||||||
| * @return uint8_t | ||||||||
| */ | ||||||||
| uint8_t availableSensorLongData(); | ||||||||
| /** | ||||||||
| * @brief Read sensor data | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and saves it into a SensorDataPacket that is passed by reference. |
||||||||
| * | ||||||||
| * @param data | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How to construct a data packet? |
||||||||
| * @return true | ||||||||
| * @return false | ||||||||
|
Comment on lines
+106
to
+107
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does the success / error case refer to? Success in parsing the data? |
||||||||
| */ | ||||||||
| bool readSensorData(SensorDataPacket &data); | ||||||||
| /** | ||||||||
| * @brief Read long sensor data | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as for readSensorData() |
||||||||
| * | ||||||||
| * @param data | ||||||||
| * @return true | ||||||||
| * @return false | ||||||||
| */ | ||||||||
| bool readSensorLongData(SensorLongDataPacket &data); | ||||||||
|
|
||||||||
| /** | ||||||||
| * @brief Parse XYZ Cartesian data | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it takes the SensorDataPacket data, parses it and then saves it to the DataXYZ vector? |
||||||||
| * | ||||||||
| * @param data Data packet including SensorID | ||||||||
| * @param vector vector with XYZ | ||||||||
| */ | ||||||||
| void parse(SensorDataPacket& data, DataXYZ& vector); | ||||||||
| /** | ||||||||
| * @brief Parse orientation | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. How does it construct the vector data? Does it use data as input, parses it and then write the values to vector? |
||||||||
| * | ||||||||
| * @param data Data packet including SensorID | ||||||||
| * @param vector Vector with heading, pitch and roll | ||||||||
| */ | ||||||||
| void parse(SensorDataPacket& data, DataOrientation& vector); | ||||||||
| /** | ||||||||
| * @brief Parse orientation with scale factor | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When do I need a scale factor? |
||||||||
| * | ||||||||
| * @param data Data packet including SensorID | ||||||||
| * @param vector Vector with heading, pitch and roll | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do I access them? vector.heading vector.pitch vector.roll ? |
||||||||
| * @param scaleFactor scale factor for vector | ||||||||
| */ | ||||||||
| void parse(SensorDataPacket& data, DataOrientation& vector, float scaleFactor); | ||||||||
|
|
||||||||
| NiclaWiring getNiclaConnection(); | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,18 +6,45 @@ | |
| #include "DFUTypes.h" | ||
| #include "ArduinoBLE.h" | ||
|
|
||
| /** | ||
| * @brief Class for handling BLE communication for both sensor data transfer and DFU | ||
| * | ||
| */ | ||
|
|
||
| class BLEHandler { | ||
| public: | ||
| BLEHandler(); | ||
| virtual ~BLEHandler(); | ||
|
|
||
| /** | ||
| * @brief Start BLE connection to the Nicla board | ||
| * | ||
| * @return true Connection successful to the Nicla board | ||
| * @return false Connection unsuccessful to the Nicla board | ||
| */ | ||
| bool begin(); | ||
| /** | ||
| * @brief Poll data over Bluetooth | ||
| * | ||
| */ | ||
| void update(); | ||
| /** | ||
| * @brief Disconnect BLE connection between host and Nicla board | ||
| * | ||
| */ | ||
| void end(); | ||
|
|
||
| /** | ||
| * @brief Specify which sensor to poll data from on the Nicla Sense ME | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems more like it sends out sensor configuration data to the client, doesn't it? |
||
| * | ||
| * @param config Configuration for the Sensor including sensor ID, sample rate and latency | ||
| */ | ||
| void writeConfigPacket(SensorConfigurationPacket& config); | ||
|
|
||
| private: | ||
| /** | ||
| * @brief The Arduino_BHY2Host class can accces both private and public methods of BLEHandler | ||
| * | ||
| */ | ||
| friend class Arduino_BHY2Host; | ||
|
Comment on lines
+44
to
48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not strictuly necessary as this is a regular C++ feature. |
||
|
|
||
| static void receivedSensorData(BLEDevice central, BLECharacteristic characteristic); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,13 +13,22 @@ | |||||
|
|
||||||
| #define I2C_INT_PIN (0) | ||||||
|
|
||||||
| /** | ||||||
| * @brief Enumerator for ESLOV operational state | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are they used for? |
||||||
| * | ||||||
| */ | ||||||
| enum EslovOpcode { | ||||||
| ESLOV_DFU_INTERNAL_OPCODE, | ||||||
| ESLOV_DFU_EXTERNAL_OPCODE, | ||||||
| ESLOV_SENSOR_CONFIG_OPCODE, | ||||||
| ESLOV_SENSOR_STATE_OPCODE | ||||||
| ESLOV_DFU_INTERNAL_OPCODE, /*!< ESLOV DFU ANNA-B112 */ | ||||||
| ESLOV_DFU_EXTERNAL_OPCODE, /*!< ESLOV DFU BHY260 */ | ||||||
| ESLOV_SENSOR_CONFIG_OPCODE, /*!< ESLOV Sensor Configuration */ | ||||||
| ESLOV_SENSOR_STATE_OPCODE /*!< ESLOV Sensor State */ | ||||||
| }; | ||||||
|
|
||||||
|
|
||||||
| /** | ||||||
| * @brief Enumeration for Host-Nicla configuration | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference between these and the normal Opcodes? |
||||||
| * | ||||||
| */ | ||||||
| enum HostOpcode { | ||||||
| HOST_DFU_INTERNAL_OPCODE = ESLOV_DFU_INTERNAL_OPCODE, | ||||||
| HOST_DFU_EXTERNAL_OPCODE = ESLOV_DFU_EXTERNAL_OPCODE, | ||||||
|
|
@@ -28,6 +37,11 @@ enum HostOpcode { | |||||
| HOST_READ_LONG_SENSOR_OPCODE | ||||||
| }; | ||||||
|
|
||||||
|
|
||||||
| /** | ||||||
| * @brief Enumeration for various states over ESLOV | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used to regulate what exactly? |
||||||
| * | ||||||
| */ | ||||||
| enum EslovState { | ||||||
| ESLOV_AVAILABLE_SENSOR_STATE = 0x00, | ||||||
| ESLOV_READ_SENSOR_STATE = 0x01, | ||||||
|
|
@@ -43,19 +57,80 @@ class EslovHandler { | |||||
| EslovHandler(); | ||||||
| virtual ~EslovHandler(); | ||||||
|
|
||||||
| /** | ||||||
| * @brief Start I2C communication with Nicla Sense ME Board | ||||||
| * | ||||||
| * @param passthrough Enable Serial port at 115200 bps | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What data is passed through to where and which serial port is opened the client one or host one? |
||||||
| * | ||||||
| * @return true I2C communication initialised successfully. | ||||||
| * @return false Failure in starting communication over ESLOV protocol. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ESLOV is not a protocol |
||||||
| */ | ||||||
| bool begin(bool passthrough); | ||||||
| /** | ||||||
| * @brief When Serial port is avaliable, then based on the defined opcode write data | ||||||
| * | ||||||
| */ | ||||||
| void update(); | ||||||
|
|
||||||
| /** | ||||||
| * @brief Send DFU data over ESLOV. On the last packet, the built-in LED is pulled down. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the LED pulled down (turned off)? |
||||||
| * | ||||||
| * @param data data to be send for DFU | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * @param length total length of data to be sent | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. length in bytes I assume? |
||||||
| */ | ||||||
| void writeDfuPacket(uint8_t *data, uint8_t length); | ||||||
| /** | ||||||
| * @brief Configure the Nicla device to run in a specific state | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are these states used for? |
||||||
| * | ||||||
| * @param state Configuration passed to Nicla based on @ref EslovState enumerator | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| */ | ||||||
| void writeStateChange(EslovState state); | ||||||
| /** | ||||||
| * @brief Specify which sensor to poll data from on the Nicla Sense ME | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it only to enable / disable the sensors? Also to configure latency and sample rate, no? |
||||||
| * | ||||||
| * @param config Configuration for the Sensor including sensor ID, sample rate and latency | ||||||
| */ | ||||||
| void writeConfigPacket(SensorConfigurationPacket& config); | ||||||
| /** | ||||||
| * @brief Recieve acknowledgement from Nicla board over ESLOV | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * | ||||||
| * @return uint8_t Data read from I2C bus | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does the returned number stand for? |
||||||
| */ | ||||||
| uint8_t requestPacketAck(); | ||||||
| /** | ||||||
| * @brief Obtain data sent over ESLOV to the host board | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Requests only the available bytes, no? |
||||||
| * | ||||||
| * @return uint8_t Data read from I2C bus | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it return the data or the number of bytes available? |
||||||
| */ | ||||||
| uint8_t requestAvailableData(); | ||||||
| /** | ||||||
| * @brief Obtain long data sent over ESLOV to the host board | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as for requestAvailableData() |
||||||
| * | ||||||
| * @return uint8_t Data read from I2C bus | ||||||
| */ | ||||||
| uint8_t requestAvailableLongData(); | ||||||
| /** | ||||||
| * @brief Request data from the Nicla board | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is for a specific sensor, right? So do I need to pass the sensor ID or how does this work? |
||||||
| * | ||||||
| * @param sData | ||||||
| * @return true Request successful | ||||||
| * @return false Request unsuccessful | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Transmission error only or also configuration error? |
||||||
| */ | ||||||
| bool requestSensorData(SensorDataPacket &sData); | ||||||
| /** | ||||||
| * @brief Request long data from the Nicla board | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as for requestSensorData() |
||||||
| * | ||||||
| * @param sData | ||||||
| * @return true Request successful | ||||||
| * @return false Request unsuccessful | ||||||
| */ | ||||||
| bool requestSensorLongData(SensorLongDataPacket &sData); | ||||||
|
|
||||||
| protected: | ||||||
| /** | ||||||
| * @brief Nicla Sense ME is mounted as a Shield | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does the function do? Does it set some pins, change some configuration, ...? |
||||||
| * | ||||||
| */ | ||||||
| void niclaAsShield(); | ||||||
|
|
||||||
| private: | ||||||
|
|
@@ -68,6 +143,10 @@ class EslovHandler { | |||||
| bool _dfuLedOn; | ||||||
|
|
||||||
| private: | ||||||
| /** | ||||||
| * @brief The Arduino_BHY2Host class can accces both private and public methods of EslovHandler | ||||||
| * | ||||||
| */ | ||||||
| friend class Arduino_BHY2Host; | ||||||
|
|
||||||
| void flushWire(); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brief description missing