Skip to content

Commit

Permalink
Fix compile warnings and axes order
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmingDev authored Feb 1, 2025
1 parent 0065833 commit 2ed0c15
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 43 deletions.
18 changes: 9 additions & 9 deletions BleGamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ uint8_t tempHidReportDescriptor[150];
int hidReportDescriptorSize = 0;
uint8_t reportSize = 0;
uint8_t numOfButtonBytes = 0;
static uint16_t vid;
static uint16_t pid;
static uint16_t guidVersion;
static int16_t axesMin;
static int16_t axesMax;
static int16_t simulationMin;
static int16_t simulationMax;
static int16_t motionMin;
static int16_t motionMax;
uint16_t vid;
uint16_t pid;
uint16_t guidVersion;
int16_t axesMin;
int16_t axesMax;
int16_t simulationMin;
int16_t simulationMax;
int16_t motionMin;
int16_t motionMax;

std::string modelNumber;
std::string softwareRevision;
Expand Down
4 changes: 2 additions & 2 deletions examples/DrivingControllerTest/DrivingControllerTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#define enableX false
#define enableY false
#define enableZ false
#define enableRZ false
#define enableRX false
#define enableRY false
#define enableRZ false
#define enableSlider1 false
#define enableSlider2 false
#define enableRudder false
Expand Down Expand Up @@ -41,7 +41,7 @@ void setup()
bleGamepadConfig.setAutoReport(false);
bleGamepadConfig.setControllerType(CONTROLLER_TYPE_GAMEPAD); // CONTROLLER_TYPE_JOYSTICK, CONTROLLER_TYPE_GAMEPAD (DEFAULT), CONTROLLER_TYPE_MULTI_AXIS
bleGamepadConfig.setButtonCount(numOfButtons);
bleGamepadConfig.setWhichAxes(enableX, enableY, enableZ, enableRX, enableRY, enableRZ, enableSlider1, enableSlider2); // Can also be done per-axis individually. All are true by default
bleGamepadConfig.setWhichAxes(enableX, enableY, enableZ, enableRZ, enableRX, enableRY, enableSlider1, enableSlider2); // Can also be done per-axis individually. All are true by default
bleGamepadConfig.setWhichSimulationControls(enableRudder, enableThrottle, enableAccelerator, enableBrake, enableSteering); // Can also be done per-control individually. All are false by default
bleGamepadConfig.setHatSwitchCount(numOfHatSwitches); // 1 by default
bleGamepadConfig.setSimulationMin(simMin);
Expand Down
2 changes: 1 addition & 1 deletion examples/FlightControllerTest/FlightControllerTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void setup()
bleGamepadConfig.setButtonCount(numOfButtons);
bleGamepadConfig.setIncludeStart(true);
bleGamepadConfig.setIncludeSelect(true);
bleGamepadConfig.setWhichAxes(enableX, enableY, enableZ, enableRX, enableRY, enableRZ, enableSlider1, enableSlider2); // Can also be done per-axis individually. All are true by default
bleGamepadConfig.setWhichAxes(enableX, enableY, enableZ, enableRZ, enableRX, enableRY, enableSlider1, enableSlider2); // Can also be done per-axis individually. All are true by default
bleGamepadConfig.setWhichSimulationControls(enableRudder, enableThrottle, enableAccelerator, enableBrake, enableSteering); // Can also be done per-control individually. All are false by default
bleGamepadConfig.setHatSwitchCount(numOfHatSwitches); // 1 by default
// Some non-Windows operating systems and web based gamepad testers don't like min axis set below 0, so 0 is set by default
Expand Down
2 changes: 1 addition & 1 deletion examples/Keypad4x4/Keypad4x4.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void setup()
{
BleGamepadConfiguration bleGamepadConfig;
bleGamepadConfig.setAutoReport(false); // Disable auto reports --> You then need to force HID updates with bleGamepad.sendReport()
bleGamepad.begin(); // Begin library with default buttons/hats/axes
bleGamepad.begin(&bleGamepadConfig); // Begin library with set values

// changing bleGamepadConfig after the begin function has no effect, unless you call the begin function again
}
Expand Down
60 changes: 30 additions & 30 deletions examples/MotionController/MotionController.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <Arduino.h>
#include <BleGamepad.h>

#define numOfButtons 10
#define numOfButtons 28
#define numOfHatSwitches 0
#define enableX false
#define enableY false
Expand All @@ -36,11 +36,11 @@
#define enableSlider1 false
#define enableSlider2 false

int16_t motionMin = 0x8000; // -32767 --> Some non-Windows operating systems and web based gamepad testers don't like min axis set below 0, so 0 is set by default
int16_t motionCenter = 0x00;
//int16_t motionMin = 0x00; // Set motionulation minimum axes to zero.
//int16_t motionCenter = 0x3FFF;
int16_t motionMax = 0x7FFF; // 32767 --> int16_t - 16 bit signed integer - Can be in decimal or hexadecimal
int16_t motMin = 0x8000; // -32767 --> Some non-Windows operating systems and web based gamepad testers don't like min axis set below 0, so 0 is set by default
int16_t motCenter = 0x00;
//int16_t motMin = 0x00; // Set motionulation minimum axes to zero.
//int16_t motCenter = 0x3FFF;
int16_t motMax = 0x7FFF; // 32767 --> int16_t - 16 bit signed integer - Can be in decimal or hexadecimal
int16_t stepAmount = 0xFF; // 255
uint16_t delayAmount = 25;

Expand All @@ -54,20 +54,20 @@ void setup()
// Setup controller with 10 buttons, gyroscope and accelerometer
BleGamepadConfiguration bleGamepadConfig;
bleGamepadConfig.setAutoReport(false);
bleGamepadConfig.setControllerType(CONTROLLER_TYPE_GAMEPAD); // CONTROLLER_TYPE_JOYSTICK, CONTROLLER_TYPE_GAMEPAD (DEFAULT), CONTROLLER_TYPE_MULTI_AXIS
bleGamepadConfig.setControllerType(CONTROLLER_TYPE_MULTI_AXIS); // CONTROLLER_TYPE_JOYSTICK, CONTROLLER_TYPE_GAMEPAD (DEFAULT), CONTROLLER_TYPE_MULTI_AXIS
bleGamepadConfig.setButtonCount(numOfButtons);
bleGamepadConfig.setWhichAxes(enableX, enableY, enableZ, enableRX, enableRY, enableRZ, enableSlider1, enableSlider2); // Can also be done per-axis individually. All are true by default
bleGamepadConfig.setWhichAxes(enableX, enableY, enableZ, enableRZ, enableRX, enableRY, enableSlider1, enableSlider2); // Can also be done per-axis individually. All are true by default
bleGamepadConfig.setHatSwitchCount(numOfHatSwitches); // 1 by default
bleGamepadConfig.setIncludeGyroscope(true);
bleGamepadConfig.setIncludeAccelerometer(true);
bleGamepadConfig.setMotionMin(motionMin);
bleGamepadConfig.setMotionMax(motionMax);
bleGamepadConfig.setMotionMin(motMin);
bleGamepadConfig.setMotionMax(motMax);

bleGamepad.begin(&bleGamepadConfig);
// Changing bleGamepadConfig after the begin function has no effect, unless you call the begin function again

// Set gyroscope and accelerometer to center (first 3 are gyroscope, last 3 are accelerometer)
bleGamepad.setMotionControls(motionCenter, motionCenter, motionCenter, motionCenter, motionCenter, motionCenter);
bleGamepad.setMotionControls(motCenter, motCenter, motCenter, motCenter, motCenter, motCenter);

bleGamepad.sendReport();
}
Expand All @@ -76,70 +76,70 @@ void loop()
{
if (bleGamepad.isConnected())
{
// BUTTONS
Serial.println("Press all buttons one by one");
for (int i = 1; i <= numOfButtons; i += 1)
{
bleGamepad.press(i);
bleGamepad.sendReport();
delay(100);
bleGamepad.release(i);
bleGamepad.sendReport();
delay(25);
}
// // BUTTONS
// Serial.println("Press all buttons one by one");
// for (int i = 1; i <= numOfButtons; i += 1)
// {
// bleGamepad.press(i);
// bleGamepad.sendReport();
// delay(100);
// bleGamepad.release(i);
// bleGamepad.sendReport();
// delay(25);
// }

// GYROSCOPE
Serial.println("Move all 3 gyroscope axes from center to min");
for (int i = motionCenter; i > motionMin; i -= stepAmount)
for (int i = motCenter; i > motMin; i -= stepAmount)
{
bleGamepad.setGyroscope(i, i, i);
bleGamepad.sendReport();
delay(delayAmount);
}

Serial.println("Move all 3 gyroscope axes from min to max");
for (int i = motionMin; i < motionMax; i += stepAmount)
for (int i = motMin; i < motMax; i += stepAmount)
{
bleGamepad.setGyroscope(i, i, i);
bleGamepad.sendReport();
delay(delayAmount);
}

Serial.println("Move all 3 gyroscope axes from max to center");
for (int i = motionMax; i > motionCenter; i -= stepAmount)
for (int i = motMax; i > motCenter; i -= stepAmount)
{
bleGamepad.setGyroscope(i, i, i);
bleGamepad.sendReport();
delay(delayAmount);
}
bleGamepad.setGyroscope(motionCenter);
bleGamepad.setGyroscope(motCenter);
bleGamepad.sendReport();

// ACCELEROMETER
Serial.println("Move all 3 accelerometer axes from center to min");
for (int i = motionCenter; i > motionMin; i -= stepAmount)
for (int i = motCenter; i > motMin; i -= stepAmount)
{
bleGamepad.setAccelerometer(i, i, i);
bleGamepad.sendReport();
delay(delayAmount);
}

Serial.println("Move all 3 accelerometer axes from min to max");
for (int i = motionMin; i < motionMax; i += stepAmount)
for (int i = motMin; i < motMax; i += stepAmount)
{
bleGamepad.setAccelerometer(i, i, i);
bleGamepad.sendReport();
delay(delayAmount);
}

Serial.println("Move all 3 accelerometer axes from max to center");
for (int i = motionMax; i > motionCenter; i -= stepAmount)
for (int i = motMax; i > motCenter; i -= stepAmount)
{
bleGamepad.setAccelerometer(i, i, i);
bleGamepad.sendReport();
delay(delayAmount);
}
bleGamepad.setAccelerometer(motionCenter);
bleGamepad.setAccelerometer(motCenter);
bleGamepad.sendReport();
}
}

0 comments on commit 2ed0c15

Please sign in to comment.