-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathsteamcontroller_wireless.c
63 lines (53 loc) · 2.23 KB
/
steamcontroller_wireless.c
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
#include "steamcontroller.h"
#include "common.h"
/**
* Get the current connection state of a wireless dongle.
*/
bool SCAPI SteamController_QueryWirelessState(const SteamControllerDevice *pDevice, uint8_t *state) {
SteamController_HIDFeatureReport featureReport;
memset(&featureReport, 0, sizeof(featureReport));
featureReport.featureId = STEAMCONTROLLER_DONGLE_GET_WIRELESS_STATE;
if (!SteamController_HIDGetFeatureReport(pDevice, &featureReport)) {
fprintf(stderr, "DONGLE_GET_WIRELESS_STATE (get) failed for controller %p\n", pDevice);
return false;
}
*state = featureReport.data[0];
return true;
}
/**
* Set wireless dongle to accept wireless controllers.
* @param pController Controller object to use.
* @param enable If true enable pairing.
* @param deviceType Type of device to connect to. Only known value is 0x3c for steam wireless controller.
* If set to 0, defaults to 0x3c.
* @todo Find out what arg3 does.
*/
bool SCAPI SteamController_EnablePairing(const SteamControllerDevice *pDevice, bool enable, uint8_t deviceType) {
SteamController_HIDFeatureReport featureReport;
memset(&featureReport, 0, sizeof(featureReport));
featureReport.featureId = STEAMCONTROLLER_ENABLE_PAIRING;
featureReport.dataLen = 2;
featureReport.data[0] = enable ? 1 : 0;
featureReport.data[1] = enable ? (deviceType ? deviceType : 0x3c) : 0;
if (!SteamController_HIDSetFeatureReport(pDevice, &featureReport)) {
fprintf(stderr, "ENABLE_PAIRING failed for controller %p\n", pDevice);
return false;
}
return true;
}
/**
* Accept pairing connection.
* A pairing event will be sent when a controller connects.
*/
bool SCAPI SteamController_CommitPairing(const SteamControllerDevice *pDevice, bool connect) {
SteamController_HIDFeatureReport featureReport;
memset(&featureReport, 0, sizeof(featureReport));
featureReport.featureId = connect ?
STEAMCONTROLLER_COMMIT_DEVICE :
STEAMCONTROLLER_DISCONNECT_DEVICE;
if (!SteamController_HIDSetFeatureReport(pDevice, &featureReport)) {
fprintf(stderr, "COMMIT_DEVICE/DISCONNECT_DEVICE failed for controller %p\n", pDevice);
return false;
}
return true;
}