Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions BleGamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ BleGamepad::BleGamepad(std::string deviceName, std::string deviceManufacturer, u
_rZ(0),
_slider1(0),
_slider2(0),
_dial(0),
_rudder(0),
_throttle(0),
_accelerator(0),
Expand Down Expand Up @@ -432,6 +433,13 @@ void BleGamepad::begin(BleGamepadConfiguration *config)
tempHidReportDescriptor[hidReportDescriptorSize++] = 0x36;
}

if (configuration.getIncludeDial())
{
// USAGE (Dial)
tempHidReportDescriptor[hidReportDescriptorSize++] = 0x09;
tempHidReportDescriptor[hidReportDescriptorSize++] = 0x37;
}

// INPUT (Data,Var,Abs)
tempHidReportDescriptor[hidReportDescriptorSize++] = 0x81;
tempHidReportDescriptor[hidReportDescriptorSize++] = 0x02;
Expand Down Expand Up @@ -981,6 +989,12 @@ void BleGamepad::sendReport(void)
m[currentReportIndex++] = (_slider2 >> 8);
}

if (configuration.getIncludeDial())
{
m[currentReportIndex++] = _dial;
m[currentReportIndex++] = (_dial >> 8);
}

if (configuration.getIncludeRudder())
{
m[currentReportIndex++] = _rudder;
Expand Down Expand Up @@ -1516,6 +1530,21 @@ void BleGamepad::setSlider2(int16_t slider2)
}
}

void BleGamepad::setDial(int16_t dial)
{
if (dial == -32768)
{
dial = -32767;
}

_dial = dial;

if (configuration.getAutoReport())
{
sendReport();
}
}

void BleGamepad::setRudder(int16_t rudder)
{
if (rudder == -32768)
Expand Down
2 changes: 2 additions & 0 deletions BleGamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class BleGamepad
int16_t _rZ;
int16_t _slider1;
int16_t _slider2;
int16_t _dial;
int16_t _rudder;
int16_t _throttle;
int16_t _accelerator;
Expand Down Expand Up @@ -126,6 +127,7 @@ class BleGamepad
void setSlider(int16_t slider = 0);
void setSlider1(int16_t slider1 = 0);
void setSlider2(int16_t slider2 = 0);
void setDial(int16_t dial = 0);
void setRudder(int16_t rudder = 0);
void setThrottle(int16_t throttle = 0);
void setAccelerator(int16_t accelerator = 0);
Expand Down
3 changes: 3 additions & 0 deletions BleGamepadConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ BleGamepadConfiguration::BleGamepadConfiguration() : _controllerType(CONTROLLER_
_whichSpecialButtons{false, false, false, false, false, false, false, false},
_whichAxes{true, true, true, true, true, true, true, true},
_whichSimulationControls{false, false, false, false, false},
_includeDial(false),
_includeGyroscope(false),
_includeAccelerometer(false),
_vid(0xe502),
Expand Down Expand Up @@ -117,6 +118,7 @@ bool BleGamepadConfiguration::getIncludeRyAxis() { return _whichAxes[RY_AXIS]; }
bool BleGamepadConfiguration::getIncludeRzAxis() { return _whichAxes[RZ_AXIS]; }
bool BleGamepadConfiguration::getIncludeSlider1() { return _whichAxes[SLIDER1]; }
bool BleGamepadConfiguration::getIncludeSlider2() { return _whichAxes[SLIDER2]; }
bool BleGamepadConfiguration::getIncludeDial() { return _includeDial; }
const bool *BleGamepadConfiguration::getWhichAxes() const { return _whichAxes; }
bool BleGamepadConfiguration::getIncludeRudder() { return _whichSimulationControls[RUDDER]; }
bool BleGamepadConfiguration::getIncludeThrottle() { return _whichSimulationControls[THROTTLE]; }
Expand Down Expand Up @@ -190,6 +192,7 @@ void BleGamepadConfiguration::setIncludeRxAxis(bool value) { _whichAxes[RX_AXIS]
void BleGamepadConfiguration::setIncludeRyAxis(bool value) { _whichAxes[RY_AXIS] = value; }
void BleGamepadConfiguration::setIncludeSlider1(bool value) { _whichAxes[SLIDER1] = value; }
void BleGamepadConfiguration::setIncludeSlider2(bool value) { _whichAxes[SLIDER2] = value; }
void BleGamepadConfiguration::setIncludeDial(bool value) { _includeDial = value; }
void BleGamepadConfiguration::setIncludeRudder(bool value) { _whichSimulationControls[RUDDER] = value; }
void BleGamepadConfiguration::setIncludeThrottle(bool value) { _whichSimulationControls[THROTTLE] = value; }
void BleGamepadConfiguration::setIncludeAccelerator(bool value) { _whichSimulationControls[ACCELERATOR] = value; }
Expand Down
3 changes: 3 additions & 0 deletions BleGamepadConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class BleGamepadConfiguration
bool _whichSpecialButtons[POSSIBLESPECIALBUTTONS];
bool _whichAxes[POSSIBLEAXES];
bool _whichSimulationControls[POSSIBLESIMULATIONCONTROLS];
bool _includeDial;
bool _includeGyroscope;
bool _includeAccelerometer;
uint16_t _vid;
Expand Down Expand Up @@ -273,6 +274,7 @@ class BleGamepadConfiguration
bool getIncludeRzAxis();
bool getIncludeSlider1();
bool getIncludeSlider2();
bool getIncludeDial();
const bool *getWhichAxes() const;
bool getIncludeRudder();
bool getIncludeThrottle();
Expand Down Expand Up @@ -323,6 +325,7 @@ class BleGamepadConfiguration
void setIncludeRzAxis(bool value);
void setIncludeSlider1(bool value);
void setIncludeSlider2(bool value);
void setIncludeDial(bool value);
void setWhichAxes(bool xAxis, bool yAxis, bool zAxis, bool rxAxis, bool ryAxis, bool rzAxis, bool slider1, bool slider2);
void setIncludeRudder(bool value);
void setIncludeThrottle(bool value);
Expand Down