-
Notifications
You must be signed in to change notification settings - Fork 21
/
example.c
35 lines (29 loc) · 1.27 KB
/
example.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
#include "steamcontroller.h"
#include <stdio.h>
int main() {
SteamControllerDeviceEnum *pEnum = SteamController_EnumControllerDevices();
while (pEnum) {
SteamControllerEvent event;
SteamControllerDevice *pDevice = SteamController_Open(pEnum);
if (pDevice) {
for(;;) {
uint8_t res = SteamController_ReadEvent(pDevice, &event);
if (res == STEAMCONTROLLER_EVENT_CONNECTION && event.connection.details == STEAMCONTROLLER_CONNECTION_EVENT_DISCONNECTED) {
fprintf(stderr, "Device %p is not connected (anymore), trying next one...\n", pDevice);
break;
}
if (res == STEAMCONTROLLER_EVENT_CONNECTION && event.connection.details == STEAMCONTROLLER_CONNECTION_EVENT_CONNECTED) {
fprintf(stderr, "Device %p is connected, configuring...\n", pDevice);
SteamController_Configure(pDevice, STEAMCONTROLLER_CONFIG_SEND_BATTERY_STATUS|STEAMCONTROLLER_CONFIG_SEND_GYRO);
}
if (res == 1) {
// just print the value of the left touch pad / stick position
fprintf(stderr, "% 6hd % 6hd\n", event.update.leftXY.x, event.update.leftXY.y);
}
}
SteamController_Close(pDevice);
}
pEnum = SteamController_NextControllerDevice(pEnum);
}
return 0;
}