Skip to content

Commit b825610

Browse files
authored
Merge pull request #3 from grafmar/master
Battery level fix
2 parents 32306c3 + e264be2 commit b825610

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

BleGamepad.cpp

+22-18
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,23 @@ static const uint8_t _hidReportDescriptor[] = {
5959
REPORT_SIZE(1), 0x08, // REPORT_SIZE (8)
6060
REPORT_COUNT(1), 0x02, // REPORT_COUNT (2)
6161
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)
6767
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
7474
};
7575

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)
7779
{
7880
this->deviceName = deviceName;
7981
this->deviceManufacturer = deviceManufacturer;
@@ -96,16 +98,16 @@ void BleGamepad::setAxes(signed char x, signed char y, signed char z, signed cha
9698
{
9799
uint8_t m[9];
98100
m[0] = _buttons;
99-
m[1] = (_buttons >> 8);
101+
m[1] = (_buttons >> 8);
100102
m[2] = x;
101103
m[3] = y;
102104
m[4] = z;
103105
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; }
109111
this->inputGamepad->setValue(m, sizeof(m));
110112
this->inputGamepad->notify();
111113
}
@@ -143,6 +145,8 @@ bool BleGamepad::isConnected(void) {
143145

144146
void BleGamepad::setBatteryLevel(uint8_t level) {
145147
this->batteryLevel = level;
148+
if (hid != 0)
149+
this->hid->setBatteryLevel(this->batteryLevel);
146150
}
147151

148152
void BleGamepad::taskServer(void* pvParameter) {

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This library allows you to make the ESP32 act as a Bluetooth Gamepad and control
99
- [x] Button release (14 buttons)
1010
- [x] Axes movement (6 axes (x, y, z, rZ, rX, rY) --> (Left Thumb X, Left Thumb Y, Right Thumb X, Right Thumb Y, Left Trigger, Right Trigger)))
1111
- [x] Point of view hat (d-pad)
12-
- [ ] Report optional battery level to host
12+
- [x] Report optional battery level to host (basically works, but it doesn't show up in Android's status bar)
1313
- [x] Customize Bluetooth device name/manufacturer
1414
- [x] Compatible with Windows
1515
- [ ] Compatible with Android (Untested)

0 commit comments

Comments
 (0)