-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovementIn.h
More file actions
103 lines (82 loc) · 2.92 KB
/
MovementIn.h
File metadata and controls
103 lines (82 loc) · 2.92 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#pragma once
// Forward declare EnvironmentalInstrumentsAudioProcessor
class EnvironmentalInstrumentsAudioProcessor;
#include "Types.h"
#include "JoyConBridge/src/JoyConBridge/JoyCon.h"
#include "JoyConBridge/src/JoyConBridge/protocol.h"
using JoyCon = joy_con_bridge::JoyCon;
using SensorData = joy_con_bridge::protocol::SensorData;
using ButtonsState = joy_con_bridge::ButtonsState;
#include <memory>
#include <thread>
#include <atomic>
#include <utility>
#include <juce_core/juce_core.h> // For juce::Thread and other utilities
class MovementIn {
public:
MovementIn(EnvironmentalInstrumentsAudioProcessor&);
~MovementIn();
void startPolling();
void stopPolling();
std::pair<SensorDataFloat, SensorDataFloat> getJoyConData();
SensorDataFloat getLeftJoyConData();
SensorDataFloat getRightJoyConData();
ButtonsState getLeftJoyConButtons();
ButtonsState getRightJoyConButtons();
bool outputMuted();
bool waitForUnmute();
private:
void connectJoyCon();
std::unique_ptr<JoyCon> leftJoyCon;
std::mutex leftJoyConLock;
std::unique_ptr<JoyCon> rightJoyCon;
std::mutex rightJoyConLock;
EnvironmentalInstrumentsAudioProcessor& processorRef;
std::thread connectionThread; // For JoyCon connection handling
std::thread dataPollingThread; // For movement data polling
void pollForJoyCons(); // Handle JoyCon connection
void pollForMovementData(); // Handle real-time JoyCon data polling
void processMuteButton(bool buttonDepressed);
struct AxisCalibration {
const float coeff;
const int16_t offset;
};
struct Calib {
const struct {
AxisCalibration x;
AxisCalibration y;
AxisCalibration z;
} accel;
const struct {
AxisCalibration x;
AxisCalibration y;
AxisCalibration z;
} gyro;
};
const Calib calibL = {
{ {1.0f, 162}, {1.0f, -197}, {1.0f, 356} }, // accel
{ {0.8719269644603848f, -18}, {0.8719269644603848f, 12}, {0.8719269644603848f, 17} } // gyro
};
const Calib calibR = {
{ {1.0f, -78}, {1.0f, -53}, {1.0f, 306} }, // accel
{ {0.8719269644603848f, 0}, {0.8719269644603848f, -11}, {0.8719269644603848f, 44} } // gyro
};
const SensorDataFloat zeroL = {
{167, 197, 3810},
{20.05432018258885f, -10.463123573524618f, 46.21212911640039f}
};
const SensorDataFloat zeroR = {
{260.5, 30, -4311},
{0.0f, 9.591196609064232f, -38.36478643625693f}
};
SensorDataFloat calibrateSensorData(const SensorData& data, const Calib& calib);
SensorData leftJoyConData = {};
SensorData rightJoyConData = {};
ButtonsState leftJoyConButtons = {};
ButtonsState rightJoyConButtons = {};
std::mutex dataMutex;
bool muteOutput = true;
std::mutex muteMutex;
std::atomic<bool> shouldStop{ false };
std::condition_variable signpost;
};