-
Notifications
You must be signed in to change notification settings - Fork 5
/
DualShock4.ino
55 lines (47 loc) · 1.67 KB
/
DualShock4.ino
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
#include "DS4Controller.h"
DS4Controller DS4Instance;
DS4DataExt LastestState;
unsigned long lastOutputReport = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(1000);
BluetoothHID.Init();
// Register device
BluetoothHID.RegisterDevice(&DS4Instance);
// If DS4 in pairing mode, scan and connect, sometime issues occur when connecting while
// scanning so should only be called when pairing is needed
BluetoothHID.ScanAndConnectHIDDevice();
// Core 0 only for BT, do all processing in core 1 if needed e.g.
// xTaskCreatePinnedToCore(&task, "DS4 Task", 16 * 1024, NULL, 5, NULL, 1);
Serial.println("Started");
}
void loop() {
// put your main code here, to run repeatedly:
if (DS4Instance.GetState() == BTHIDState::Connected) {
if (DS4Instance.HasNewReport()) {
switch (DS4Instance.GetReportingState()) {
case DS4ReportingState::Standard: {
DS4Instance.SetExtendedReporting();
vTaskDelay(50 / portTICK_PERIOD_MS);
break;
}
case DS4ReportingState::Extended: {
DS4Instance.GetLatestInputReport(&LastestState);
//Serial.println(LastestState.LeftX);
// Slow update if needed
if ((millis() - lastOutputReport) > 5) {
DS4Instance.SetLED(LastestState.LeftX, LastestState.LeftY, LastestState.RightX, false);
DS4Instance.SetRumble(LastestState.LT, LastestState.RT, false);
DS4Instance.UpdateState();
lastOutputReport = millis();
}
break;
}
default:
break;
}
}
}
vTaskDelay(5 / portTICK_PERIOD_MS);
}