forked from WEARTHaptics/WEART-SDK-Cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeArtAnalogSensorData.cpp
44 lines (35 loc) · 1.1 KB
/
WeArtAnalogSensorData.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* WEART - Raw Analog Sensor Data thimble TD
* https://www.weart.it/
*/
#ifndef WEART_CMAKE_COMPILATION
#include "pch.h"
#endif
#include "WeArtAnalogSensorData.h"
#include "WeArtController.h"
WeArtAnalogSensorData::WeArtAnalogSensorData(HandSide side, ActuationPoint actuation)
: WeArtMessageListener({ AnalogSensorsData::ID }) {
handSide = side;
actuationPoint = actuation;
}
WeArtAnalogSensorData::Sample WeArtAnalogSensorData::GetLastSample() {
return lastSample;
}
void WeArtAnalogSensorData::AddSampleCallback(std::function<void(Sample)> callback) {
callbacks.push_back(callback);
}
void WeArtAnalogSensorData::OnMessageReceived(WeArtMessage* msg) {
AnalogSensorsData* rawSensorsData = static_cast<AnalogSensorsData*>(msg);
if (rawSensorsData == nullptr)
return;
if (rawSensorsData->getHand() != handSide)
return;
if (!rawSensorsData->hasSensor(actuationPoint))
return;
Sample sample;
sample.timestamp = rawSensorsData->timestamp();
sample.data = rawSensorsData->getSensor(actuationPoint);
lastSample = sample;
for (std::function<void(Sample)> callback : callbacks)
callback(sample);
}