-
Notifications
You must be signed in to change notification settings - Fork 258
Expand file tree
/
Copy pathBleXInput.cpp
More file actions
39 lines (31 loc) · 1.1 KB
/
Copy pathBleXInput.cpp
File metadata and controls
39 lines (31 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
#include "BleXInput.h"
#include "BleReportUtils.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
void BleXInputReceiver::onWrite(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo &connInfo)
{
const NimBLEAttValue &value = pCharacteristic->getValue();
size_t len = value.size();
const uint8_t *raw = value.data();
size_t actualLen = 0;
const uint8_t *data = stripReportIdIfPresent(raw, len, sizeof(XInputOutputReport), actualLen);
if (actualLen < sizeof(XInputOutputReport))
{
return;
}
const XInputOutputReport *report = (const XInputOutputReport *)data;
leftTriggerMagnitude = report->leftTriggerMagnitude;
rightTriggerMagnitude = report->rightTriggerMagnitude;
weakMotor = report->weakMotorMagnitude;
strongMotor = report->strongMotorMagnitude;
if (report->dcEnableActuators & 0x0F)
{
rumbleFlag = true;
}
else if (report->weakMotorMagnitude == 0 && report->strongMotorMagnitude == 0)
{
rumbleFlag = false;
}
}
#endif // CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
#endif // CONFIG_BT_ENABLED