-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathControlStick.h
133 lines (107 loc) · 3.88 KB
/
ControlStick.h
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#ifndef _CONTROLSTICK_H_
#define _CONTROLSTICK_H_
#include <Arduino.h>
#include <NimBLEDevice.h>
/*
*****************************************************************************************
* CONSTANTS
*****************************************************************************************
*/
/*
*****************************************************************************************
* MACROS & STRUCTURES
*****************************************************************************************
*/
/*
*****************************************************************************************
* CLASS
*****************************************************************************************
*/
class StickCallback {
public:
StickCallback() {}
virtual void onConnect() {}
virtual void onDisconnect() {}
virtual void onStickChanged(int axisX, int axisY, int axisZ, int axisRZ, int axisLT, int axisRT, int dpad, int btns) {}
};
class AdvertisedDeviceCallbacks;
class BLEJoyClientCallback;
class ControlStick {
public:
enum {
BTN_A = 0,
BTN_B,
BTN_MENU,
BTN_X,
BTN_Y,
BTN_RSV1,
BTN_L1,
BTN_R1,
BTN_L2 = 8,
BTN_R2,
BTN_SEL,
BTN_START,
BTN_POWER,
BTN_LTHUMB,
BTN_RTHUMB,
BTN_RSV3,
BTN_DPAD_UP = 16,
BTN_DPAD_RIGHT,
BTN_DPAD_DOWN,
BTN_DPAD_LEFT
} BTN_T;
ControlStick();
virtual ~ControlStick() { }
void add(BLEAddress* addr, BLEUUID uuidService, BLEUUID uuidCharacteristic, notify_callback cb);
void begin();
bool connect();
bool isConnecting() { return _isConnecting; }
bool isConnected() { return _isConnected; }
void rescan();
void stop();
void addSupportedDevices();
void setStickCallback(StickCallback *callback) { _pStickCallback = callback; }
friend class AdvertisedDeviceCallbacks;
friend class BLEJoyClientCallback;
protected:
std::vector <BLEAddress*> _reqDevAddrs;
std::vector <BLEUUID> _uuidServices;
std::vector <BLEUUID> _uuidCharacteristics;
std::vector <notify_callback> _notifyCallbacks;
BLEAddress* _pServerAddress;
boolean _isConnecting;
boolean _isConnected;
BLERemoteCharacteristic* _pRemoteCharacteristic;
StickCallback* _pStickCallback;
void cbControlStickBLE(NimBLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify);
void cbFlyPadBLE(NimBLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify);
void cbGameSirT1DBLE(NimBLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify);
private:
int getBit(int val, int bit) { return ((val >> bit) & 1); }
int setBit(int val, int bit) { return (val << bit); }
BLEUUID _uuidFoundService;
int _nFoundIdx;
int _nConnTryCtr;
NimBLEClient* _pClient;
};
#if 0
class JoystickBLE : public ControlStick {
public:
// this is the service UUID of the VR Control handheld mouse/joystick device (HID)
//"00001812-0000-1000-8000-00805f9b34fb"
// this characteristic UUID works for joystick & triggers (report)
//"00002A4D-0000-1000-8000-00805f9b34fb"
JoystickBLE(BLEUUID uuidService = BLEUUID("1812"), BLEUUID uuidCharacteristic = BLEUUID("2A4D")) : ControlStick(uuidService, uuidCharacteristic) {
}
~JoystickBLE() {
}
};
class FlyPadBLE : public ControlStick {
public:
FlyPadBLE(BLEUUID uuidService = BLEUUID("9e35fa00-4344-44d4-a2e2-0c7f6046878b"), BLEUUID uuidCharacteristic = BLEUUID("9e35fa01-4344-44d4-a2e2-0c7f6046878b")) : ControlStick(uuidService, uuidCharacteristic) {
}
~FlyPadBLE() {
}
};
#endif
#endif