-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovementDial.cpp
More file actions
44 lines (35 loc) · 1.1 KB
/
MovementDial.cpp
File metadata and controls
44 lines (35 loc) · 1.1 KB
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
#include "Types.h"
#include "SpinningDial.h"
#include <juce_gui_basics/juce_gui_basics.h>
#include "JoyConBridge/src/JoyConBridge/JoyCon.h"
class MovementDial : public SpinningDial, public juce::Timer
{
public:
using DataGetter = std::function<SensorDataFloat()>;
MovementDial(DataGetter dg) : dataGetter(std::move(dg))
{
startTimer(30);
}
~MovementDial() override
{
stopTimer(); // Stop the timer when the object is destroyed
}
float sumSensorData(SensorDataFloat sd)
{
float* start = &sd.accelerometer[0];
float* end = start + 6;
return std::accumulate(start, end, float(0));
}
// The timerCallback polls the sensor data and updates the dial
void timerCallback() override
{
// Fetch sensor data from the assigned JoyCon
SensorDataFloat data = dataGetter();
// Update the angle based on sensor data
float newAngle = sumSensorData(data) / 8000.0f;
// Update the dial's angle
setAngle(newAngle);
}
private:
DataGetter dataGetter; // Function to get specific JoyCon data
};