semf
analogdmasensor.h
Go to the documentation of this file.
1
10#ifndef SEMF_INPUT_SENSOR_ANALOGDMASENSOR_H_
11#define SEMF_INPUT_SENSOR_ANALOGDMASENSOR_H_
12
17
18namespace semf
19{
30template <typename T, size_t N_CHANNELS = 1>
32{
33public:
40 AnalogDmaSensor(AnalogInDma& analogInDma, T buffer[], size_t bufferSize);
41 explicit AnalogDmaSensor(const AnalogDmaSensor& other) = delete;
42 virtual ~AnalogDmaSensor() = default;
43
44 void update() override;
45 LastInBuffer<T>& buffer(size_t index) override;
46
47private:
49 void onDataAvailable();
50
52 AnalogInDma& m_analogInDma;
54 LastInDmaBuffer<T> m_buffers[N_CHANNELS];
56 T* m_data = nullptr;
58 size_t m_dataSize = 0;
60 SEMF_SLOT(m_onDataAvailableSlot, AnalogDmaSensor, *this, onDataAvailable);
61};
62
63template <typename T, size_t N_CHANNELS>
64AnalogDmaSensor<T, N_CHANNELS>::AnalogDmaSensor(AnalogInDma& analogInDma, T buffer[], size_t bufferSize)
65: m_analogInDma(analogInDma),
66 m_data(buffer),
67 m_dataSize(bufferSize)
68{
69 m_analogInDma.dataAvailable.connect(m_onDataAvailableSlot);
70 for (size_t i = 0; i < N_CHANNELS; i++)
71 {
72 m_buffers[i].setBuffer(buffer, bufferSize);
73 m_buffers[i].setPos(i);
74 m_buffers[i].setStride(N_CHANNELS);
75 }
76}
77template <typename T, size_t N_CHANNELS>
79{
80 m_analogInDma.start(reinterpret_cast<uint8_t*>(m_data), m_dataSize * sizeof(T));
81}
82
83template <typename T, size_t N_CHANNELS>
85{
86 return m_buffers[index];
87}
88
89template <typename T, size_t N_CHANNELS>
91{
92 for (size_t i = 0; i < N_CHANNELS; i++)
94}
95} /* namespace semf */
96#endif /* SEMF_INPUT_SENSOR_ANALOGDMASENSOR_H_ */
Provides data from an AnalogInDma to one to more Sensor objects.
void update() override
virtual ~AnalogDmaSensor()=default
AnalogDmaSensor(AnalogInDma &analogInDma, T buffer[], size_t bufferSize)
Constructor.
LastInBuffer< T > & buffer(size_t index) override
Returns the buffer, where the measurement data is stored in.
AnalogDmaSensor(const AnalogDmaSensor &other)=delete
Interface for using ADC (Analog to Digital Conversion) hardware in DMA (Direct Memory Access) mode.
Definition: analogindma.h:26
Signal dataAvailable
Definition: analogindma.h:40
Base class for sensor hardware like analog sensor. By calling update(), a measurement cycle gets trig...
The LastInBuffer class implements a kind of circular buffer.
Definition: lastinbuffer.h:40
The LastInDmaBuffer class implements a kind of circular buffer.
void connect(SlotBase< Arguments... > &slot)
Connect a method to the signal.
Definition: signal.h:94