-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.cpp
103 lines (80 loc) · 2.88 KB
/
controller.cpp
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
/*
* controller.cpp
*
* Simple HID abstraction to expose 3 pedal axis
*/
#include "controller.h"
#include "HID.h"
#define REPORT_ID 0x04
Controller::Controller(void) {
static const uint8_t ReportDescriptor[] PROGMEM = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x04, // USAGE (Joystick)
0xA1, 0x01, // COLLECTION (Application)
0x85, REPORT_ID, // REPORT_ID
0x05, 0x02, // USAGE_PAGE (Simulation Controls)
0x16, 0x00, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xFF, 0x03, // LOGICAL_MAXIMUM (1023)
0x75, 0x10, // REPORT_SIZE (16)
0x95, 0x02, // REPORT_COUNT (2)
0xA1, 0x00, // COLLECTION (Physical)
0x09, 0xC4, // USAGE (Accelerator Y)
0x09, 0xC5, // USAGE (Brake Rz)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xC0, // END_COLLECTION
// for some reason, the HID clutch is not picked up
// so we have to resort to using the X axis
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x01, // USAGE (pointer)
0x75, 0x10, // REPORT_SIZE (16)
0xA1, 0x00, // COLLECTION (Physical)
0x16, 0x00, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xFF, 0x03, // LOGICAL_MAXIMUM (1023)
0x95, 0x01, // REPORT_COUNT (1)
0x09, 0x30, // USAGE (X) - clutch
0x81, 0x02, // INPUT (Data,Var,Abs)
// rudder
0x16, 0x01, 0x00, // LOGICAL_MINIMUM (-511)
0x26, 0xFF, 0x03, // LOGICAL_MAXIMUM (512)
0x95, 0x01, // REPORT_COUNT (1)
0x09, 0x32, // USAGE (Z) - rudder (Y is accelerator)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xC0, // END_COLLECTION
0xC0 // END_COLLECTION
};
static HIDSubDescriptor descriptor(ReportDescriptor, sizeof(ReportDescriptor));
HID().AppendDescriptor(&descriptor);
changed = false;
}
void Controller::begin() {
changed = false;
}
void Controller::end() {
if(changed) {
HID().SendReport(REPORT_ID, &report, sizeof(report_struct));
}
}
void Controller::setAccelerator(uint16_t v) {
if(report.accelerator != v) {
report.accelerator = v;
changed = true;
}
}
void Controller::setBrake(uint16_t v) {
if(report.brake != v) {
report.brake = v;
changed = true;
}
}
void Controller::setClutch(uint16_t v) {
if(report.clutch != v) {
report.clutch = v;
changed = true;
}
}
void Controller::setRudder(uint16_t v) {
if(report.rudder != v) {
report.rudder = v;
changed = true;
}
}