... | ... | @@ -34,15 +34,38 @@ 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.
|
|
|
|
|
|
## Sensor Manager
|
|
|
In order to add a sensor to the `SensorManager`, the `addSensor()` method is provided: simply pass it the sensor, the callback function and the sampler type (it has default value equal to SIMPLE_SAMPLER).
|
|
|
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).
|
|
|
|
|
|
Every time a sensor is added, the `SensorManager` assigns it to a `SensorSampler`, according to the required sampling frequency and the sampling type, that can be either SIMPLE or DMA.
|
|
|
If a `SensorSampler` for that frequency and type doesn't exist, the `SensorManager` manages its creation.
|
|
|
|
|
|
Note that when a sensor is added, it is also initialized and its `selftest()` method is called. The sensor will be added only if both those functions return `true`.
|
|
|
Note that when a sensor is added, it is also initialized and its `selftest()` method is called.
|
|
|
The sensor will be added only if both those functions return `true`.
|
|
|
|
|
|
When `start()` is called, the `SensorManager` initializes the `TaskScheduler`: for each `SensorSampler`, it adds to the scheduler the `sampleAndCallback()` method to be called periodically according to the sampler's frequency.
|
|
|
|
|
|
## Example
|
|
|
|
|
|
TODO |
|
|
\ No newline at end of file |
|
|
```cpp
|
|
|
#include <miosix.h>
|
|
|
#include <sensors/SensorManager.h>
|
|
|
#include "utils/testutils/TestSensor.h"
|
|
|
|
|
|
SensorManager sensor_manager;
|
|
|
TestSensor* sensor = new TestSensor();
|
|
|
|
|
|
void testCallback() {
|
|
|
float data = *(sensor->testDataPtr());
|
|
|
TRACE("Test data : %f \n", data);
|
|
|
}
|
|
|
|
|
|
int main() {
|
|
|
|
|
|
uint32_t frequency = 10; // 10 Hz
|
|
|
std::function<void()> callback = std::bind(&testCallback);
|
|
|
|
|
|
sensor_manager.addSensor(sensor, frequency, callback, SIMPLE_SAMPLER);
|
|
|
|
|
|
sensor_manager.start();
|
|
|
}
|
|
|
``` |
|
|
\ No newline at end of file |