... | ... | @@ -113,6 +113,7 @@ class TestSensor : public virtual Sensor |
|
|
```
|
|
|
|
|
|
### Step 2: Sampling the sensor
|
|
|
Include needed modules, define your sensor and the `SensorManager`.
|
|
|
```cpp
|
|
|
#include <miosix.h>
|
|
|
#include <sensors/SensorManager.h>
|
... | ... | @@ -120,14 +121,20 @@ class TestSensor : public virtual Sensor |
|
|
|
|
|
SensorManager sensor_manager;
|
|
|
TestSensor* sensor;
|
|
|
|
|
|
```
|
|
|
Define the callback that will be passed to the `SensorSampler`, along with the sensor.
|
|
|
Inside the callback you can get the sampled data from the sensor and perform operations on it.
|
|
|
```cpp
|
|
|
void testCallback() {
|
|
|
// get the sampled data and
|
|
|
// perform whatever action you want
|
|
|
float data = sensor->getData();
|
|
|
printf("Test data : %f \n", data);
|
|
|
}
|
|
|
```
|
|
|
You use use `std::bind()` in order to bind your callback to an `std::function<void()>>` object.
|
|
|
Select the required frequency for the sampling and add the sensor and the callback to the `SensorManager`.
|
|
|
|
|
|
You can now start the `SensorManager`.
|
|
|
```cpp
|
|
|
int main() {
|
|
|
|
|
|
uint32_t frequency = 10; // 10 Hz
|
... | ... | |