@@ -59,21 +59,23 @@ static const uint8_t _hidReportDescriptor[] = {
59
59
REPORT_SIZE (1 ), 0x08 , // REPORT_SIZE (8)
60
60
REPORT_COUNT (1 ), 0x02 , // REPORT_COUNT (2)
61
61
HIDINPUT (1 ), 0x02 , // INPUT (Data, Variable, Absolute) ;2 bytes rX, rY
62
-
63
- USAGE_PAGE (1 ), 0x01 , // USAGE_PAGE (Generic Desktop)
64
- USAGE (1 ), 0x39 , // USAGE (Hat switch)
65
- USAGE (1 ), 0x39 , // USAGE (Hat switch)
66
- LOGICAL_MINIMUM (1 ), 0x01 , // LOGICAL_MINIMUM (1)
62
+
63
+ USAGE_PAGE (1 ), 0x01 , // USAGE_PAGE (Generic Desktop)
64
+ USAGE (1 ), 0x39 , // USAGE (Hat switch)
65
+ USAGE (1 ), 0x39 , // USAGE (Hat switch)
66
+ LOGICAL_MINIMUM (1 ), 0x01 , // LOGICAL_MINIMUM (1)
67
67
LOGICAL_MAXIMUM (1 ), 0x08 , // LOGICAL_MAXIMUM (8)
68
- REPORT_SIZE (1 ), 0x04 , // REPORT_SIZE (4)
69
- REPORT_COUNT (1 ), 0x02 , // REPORT_COUNT (2)
70
- HIDINPUT (1 ), 0x02 , // INPUT (Data, Variable, Absolute) ;1 byte Hat1, Hat2
71
-
72
- END_COLLECTION (0 ), // END_COLLECTION
73
- END_COLLECTION (0 ) // END_COLLECTION
68
+ REPORT_SIZE (1 ), 0x04 , // REPORT_SIZE (4)
69
+ REPORT_COUNT (1 ), 0x02 , // REPORT_COUNT (2)
70
+ HIDINPUT (1 ), 0x02 , // INPUT (Data, Variable, Absolute) ;1 byte Hat1, Hat2
71
+
72
+ END_COLLECTION (0 ), // END_COLLECTION
73
+ END_COLLECTION (0 ) // END_COLLECTION
74
74
};
75
75
76
- BleGamepad::BleGamepad (std::string deviceName, std::string deviceManufacturer, uint8_t batteryLevel) : _buttons(0 )
76
+ BleGamepad::BleGamepad (std::string deviceName, std::string deviceManufacturer, uint8_t batteryLevel) :
77
+ _buttons(0 ),
78
+ hid(0 )
77
79
{
78
80
this ->deviceName = deviceName;
79
81
this ->deviceManufacturer = deviceManufacturer;
@@ -96,16 +98,16 @@ void BleGamepad::setAxes(signed char x, signed char y, signed char z, signed cha
96
98
{
97
99
uint8_t m[9 ];
98
100
m[0 ] = _buttons;
99
- m[1 ] = (_buttons >> 8 );
101
+ m[1 ] = (_buttons >> 8 );
100
102
m[2 ] = x;
101
103
m[3 ] = y;
102
104
m[4 ] = z;
103
105
m[5 ] = rZ;
104
- m[6 ] = (signed char )(rX - 128 );
105
- m[7 ] = (signed char )(rY - 128 );
106
- m[8 ] = hat;
107
- if (m[6 ]== -128 ){ m[6 ] = -127 ;}
108
- if (m[7 ]== -128 ){ m[7 ] = -127 ;}
106
+ m[6 ] = (signed char )(rX - 128 );
107
+ m[7 ] = (signed char )(rY - 128 );
108
+ m[8 ] = hat;
109
+ if (m[6 ] == -128 ) { m[6 ] = -127 ; }
110
+ if (m[7 ] == -128 ) { m[7 ] = -127 ; }
109
111
this ->inputGamepad ->setValue (m, sizeof (m));
110
112
this ->inputGamepad ->notify ();
111
113
}
@@ -143,6 +145,8 @@ bool BleGamepad::isConnected(void) {
143
145
144
146
void BleGamepad::setBatteryLevel (uint8_t level) {
145
147
this ->batteryLevel = level;
148
+ if (hid != 0 )
149
+ this ->hid ->setBatteryLevel (this ->batteryLevel );
146
150
}
147
151
148
152
void BleGamepad::taskServer (void * pvParameter) {
0 commit comments