... | ... | @@ -14,8 +14,8 @@ In particular, the `SensorSampler` class maintains a `map<Sensor*, function<void |
|
|
Every time the `sampleAndCallback()` method of the `SensorSampler` is called, the sampler cycles through all its sensors, samples them and calls their corresponding callback, where these samples can be processed and dispatched.
|
|
|
|
|
|
Since `SensorSampler` is a virtual class, two sub-classes exist:
|
|
|
* `SimpleSensorSampler`: its type is `SIMPLE_SAMPLER`. In order to perform a sampling it calls the sensor's `onSimpleUpdate()` method.
|
|
|
* `DMASensorSampler`: its type is `DMA_SAMPLER`. It only manages sensors that use DMA. In order to perform a sampling it calls the sensor's `onDMAUpdate()` method.
|
|
|
* **SimpleSensorSampler**: its type is `SIMPLE_SAMPLER`. In order to perform a sampling it calls the sensor's `onSimpleUpdate()` method.
|
|
|
* **DMASensorSampler**: its type is `DMA_SAMPLER`. It only manages sensors that use DMA. In order to perform a sampling it calls the sensor's `onDMAUpdate()` method.
|
|
|
|
|
|
### Sensor Manager
|
|
|
In order to add a sensor to the `SensorManager`, the `addSensor()` method is provided: simply pass it the sensor, the required sampling frequency, the callback function and the sampler type (that has default value equal to `SIMPLE_SAMPLER`).
|
... | ... | @@ -45,17 +45,16 @@ For simplicity, each arrow in the diagram describes an action and reports the ph |
|
|
|
|
|
## Example
|
|
|
#### Step 1: Creating a sensor
|
|
|
This example refers to the `TestSensor` class defined in [Sensor](Sensor).
|
|
|
This example refers to the `TestSensor` class defined in [Sensor.h](Sensor).
|
|
|
For more details see how to create a sensor, visit that page.
|
|
|
|
|
|
#### Step 2: Sampling the sensor
|
|
|
Include needed modules, define your sensor and the `SensorManager`.
|
|
|
```cpp
|
|
|
#include <miosix.h>
|
|
|
#include <sensors/SensorManager.h>
|
|
|
#include <sensors`SensorManager`.h>
|
|
|
#include "TestSensor.h"
|
|
|
|
|
|
SensorManager sensor_manager;
|
|
|
`SensorManager` sensor_manager;
|
|
|
TestSensor* sensor;
|
|
|
```
|
|
|
Define the callback that will be passed to the `SensorSampler`, along with the sensor.
|
... | ... | |