mirror of
https://github.com/lemmingDev/ESP32-BLE-Gamepad.git
synced 2026-03-21 07:26:57 +01:00
* added support for start and select button * Added the things I forgot * changed header * edited the main file to add support for the different special buttons * added the press and release functions * added stuff to make it more complete. not done yet * this should do it * added back button * made the indentation consistent * small commit so i can continue on my other pc * finished the header for the config class * started working on converting existing code with new config class * replaced all _include variable with calls to the config class * fixed constructor * removed setAutoReport function * fixed a bunch of dumb mistakes * fixed a bunch of dumb mistakes * made the indentation consistent * small commit so i can continue on my other pc * finished the header for the config class * started working on converting existing code with new config class * replaced all _include variable with calls to the config class * removed setAutoReport function * fixed a bunch of dumb mistakes * added report id to list of configurable options * actually finished all the getters and setters from the config class * finished the configuration class * forgot controllertype config * updated the examples * added my own example * added home test to example * ran an autoformatter * added a comment (examples) * more readable copy-by-value * fixed circular dependancy problem * spelling mistake Co-authored-by: Hagedoorn, J.P. (pieter) <j.p.hagedoorn@students.uu.nl>
114 lines
3.7 KiB
C++
114 lines
3.7 KiB
C++
/*
|
|
* Driving controller test
|
|
*/
|
|
|
|
#include <Arduino.h>
|
|
#include <BleGamepad.h>
|
|
|
|
#define numOfButtons 10
|
|
#define numOfHatSwitches 0
|
|
#define enableX false
|
|
#define enableY false
|
|
#define enableZ false
|
|
#define enableRX false
|
|
#define enableRY false
|
|
#define enableRZ false
|
|
#define enableSlider1 false
|
|
#define enableSlider2 false
|
|
#define enableRudder false
|
|
#define enableThrottle false
|
|
#define enableAccelerator true
|
|
#define enableBrake true
|
|
#define enableSteering true
|
|
|
|
BleGamepad bleGamepad("BLE Driving Controller", "lemmingDev", 100);
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
Serial.println("Starting BLE work!");
|
|
|
|
// Setup controller with 10 buttons, accelerator, brake and steering
|
|
BleGamepadConfiguration bleGamepadConfig;
|
|
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.setWhichSimulationControls(enableRudder, enableThrottle, enableAccelerator, enableBrake, enableSteering); // Can also be done per-control individually. All are false by default
|
|
bleGamepadConfig.setHatSwitchCount(numOfHatSwitches); // 1 by default
|
|
|
|
bleGamepad.begin(bleGamepadConfig);
|
|
|
|
// changing bleGamepadConfig after the begin function has no effect, unless you call the begin function again
|
|
|
|
// Set accelerator and brake to min
|
|
bleGamepad.setAccelerator(-32767);
|
|
bleGamepad.setBrake(-32767);
|
|
|
|
// Set steering to center
|
|
bleGamepad.setSteering(0);
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
if (bleGamepad.isConnected())
|
|
{
|
|
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);
|
|
}
|
|
|
|
Serial.println("Move steering from center to max");
|
|
for (int i = 0; i > -32767; i -= 256)
|
|
{
|
|
bleGamepad.setSteering(i);
|
|
bleGamepad.sendReport();
|
|
delay(10);
|
|
}
|
|
|
|
Serial.println("Move steering from min to max");
|
|
for (int i = -32767; i < 32767; i += 256)
|
|
{
|
|
bleGamepad.setSteering(i);
|
|
bleGamepad.sendReport();
|
|
delay(10);
|
|
}
|
|
|
|
Serial.println("Move steering from max to center");
|
|
for (int i = 32767; i > 0; i -= 256)
|
|
{
|
|
bleGamepad.setSteering(i);
|
|
bleGamepad.sendReport();
|
|
delay(10);
|
|
}
|
|
bleGamepad.setSteering(0);
|
|
bleGamepad.sendReport();
|
|
|
|
Serial.println("Move accelerator from min to max");
|
|
// for(int i = 32767 ; i > -32767 ; i -= 256) //Use this for loop setup instead if accelerator is reversed
|
|
for (int i = -32767; i < 32767; i += 256)
|
|
{
|
|
bleGamepad.setAccelerator(i);
|
|
bleGamepad.sendReport();
|
|
delay(10);
|
|
}
|
|
bleGamepad.setAccelerator(-32767);
|
|
bleGamepad.sendReport();
|
|
|
|
Serial.println("Move brake from min to max");
|
|
for (int i = -32767; i < 32767; i += 256)
|
|
{
|
|
bleGamepad.setBrake(i);
|
|
bleGamepad.sendReport();
|
|
delay(10);
|
|
}
|
|
bleGamepad.setBrake(-32767);
|
|
bleGamepad.sendReport();
|
|
}
|
|
} |