Vielen dank für Euren Input.
Habe jetzt mal bei '0' angefangen.
Im Projekt habe ich jetzt eine ino und ein .h Datei.
Die sehen so aus:
h-Datei
#include <Bluepad32.h>
#include <uni.h>
#include <Arduino.h>
class XboxController {
private:
bool initOk;
unsigned long lastUpdate;
//BP32.forgetBluetoothKeys();
ControllerPtr myControllers[1];// maximal 1 Controller darf sich verbinden
// This callback gets called any time a new gamepad is connected.
// Up to 4 gamepads can be connected at the same time.
void onConnectedController(ControllerPtr ctl) {
bool foundEmptySlot = false;
for (int i = 0; i < BP32_MAX_GAMEPADS; i++) {
if (myControllers[i] == nullptr) {
Serial.printf("CALLBACK: Controller is connected, index=%d\n", i);
// Additionally, you can get certain gamepad properties like:
// Model, VID, PID, BTAddr, flags, etc.
ControllerProperties properties = ctl->getProperties();
Serial.printf("Controller model: %s, VID=0x%04x, PID=0x%04x\n", ctl->getModelName().c_str(), properties.vendor_id,
properties.product_id);
const uint8_t* addr = properties.btaddr;
Serial.printf("BD Addr: %2X:%2X:%2X:%2X:%2X:%2X\n", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
myControllers[i] = ctl;
foundEmptySlot = true;
break;
}
};
if (!foundEmptySlot) {
Serial.println("CALLBACK: Controller connected, but could not found empty slot");
};
};//onConnectedController
void onDisconnectedController(ControllerPtr ctl) {
bool foundController = false;
for (int i = 0; i < BP32_MAX_GAMEPADS; i++) {
if (myControllers[i] == ctl) {
Serial.printf("CALLBACK: Controller disconnected from index=%d\n", i);
myControllers[i] = nullptr;
foundController = true;
break;
}
}
if (!foundController) {
Serial.println("CALLBACK: Controller disconnected, but not found in myControllers");
}
};//onDisconnectedController
void processControllers() {
for (auto myController : this->myControllers) {
if (myController && myController->isConnected() ){
if( myController->hasData() && myController->isGamepad()) {
processGamepad(myController);
};
};
};
};
void processGamepad(ControllerPtr ctl) {
// There are different ways to query whether a button is pressed.
// By query each button individually:
// a(), b(), x(), y(), l1(), etc...
if (ctl->a()) {
//maxLimit = 150;
// colorIdx++;
};
if (ctl->y()) {
// Turn on the 4 LED. Each bit represents one LED.
//maxLimit = 0;
};
if (ctl->x() /*|| getUpdate*/) {
//maxLimit = 110;
};
// Another way to query controller data is by getting the buttons() function.
// See how the different "dump*" functions dump the Controller info.
//dumpGamepad(ctl);
};
public:
XboxController(){
initOk = false;
};
void setup(){
bd_addr_t controller_addr;
// Parse human-readable Bluetooth address.
//sscanf_bd_addr(controller_addr_string, controller_addr);
Serial.printf("Firmware: %s\n", BP32.firmwareVersion());
const uint8_t* addr = BP32.localBdAddress();
Serial.printf("BD Addr: %2X:%2X:%2X:%2X:%2X:%2X\n", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
// Setup the Bluepad32 callbacks
BP32.setup(&XboxController::onConnectedController, &XboxController::onDisconnectedController);
// "forgetBluetoothKeys()" should be called when the user performs
// a "device factory reset", or similar.
// Calling "forgetBluetoothKeys" in setup() just as an example.
// Forgetting Bluetooth keys prevents "paired" gamepads to reconnect.
// But it might also fix some connection / re-connection issues.
//BP32.forgetBluetoothKeys();
};
void setBtAdress(const char * controller_addr_string){
BP32.forgetBluetoothKeys();
// Somewhere in your "setup"
bd_addr_t controller_addr;
// Parse human-readable Bluetooth address.
sscanf_bd_addr(controller_addr_string, controller_addr);
// Notice that this address will be added in the Non-volatile-storage (NVS).
// If the device reboots, the address will still be stored.
// Adding a duplicate value will do nothing.
// You can add up to four entries in the allowlist.
uni_bt_allowlist_add_addr(controller_addr);
// Finally, enable the allowlist.
// Similar to the "add_addr", its value gets stored in the NVS.
uni_bt_allowlist_set_enabled(true);
};
unsigned long update(){
bool dataUpdated = BP32.update();
if (dataUpdated){//*
this->lastUpdate = millis();
processControllers();
};
return (this->lastUpdate - millis() );
};
};
INO-Datei
#include <C:\Users\User1796\Documents\Arduino\NewRcEsp32\Controller.h>
XboxController myXboxContrl;
unsigned long ctrSilenceTime;
void setup() {
myXboxContrl.setup();
ctrSilenceTime = 0;
// put your setup code here, to run once:
}
void loop() {
ctrSilenceTime = myXboxContrl.update();
// put your main code here, to run repeatedly:
}
Allerdings kommt der Fehler:
Compilation error: no matching function for call to 'Bluepad32::setup(void (XboxController::)(ControllerPtr), void (XboxController::)(ControllerPtr))'
und
In file included from C:\Users\User1796\AppData\Local\Arduino15\packages\esp32-bluepad32\hardware\esp32\4.1.0/tools/sdk/esp32s3/include/bluepad32_arduino/include/Bluepad32.h:7,
from C:\Users\User1796\Documents\Arduino\NewRcEsp32\Controller.cpp:1:
C:\Users\User1796\AppData\Local\Arduino15\packages\esp32-bluepad32\hardware\esp32\4.1.0/tools/sdk/esp32s3/include/bluepad32_arduino/include/ArduinoBluepad32.h:68:10: note: candidate: 'void Bluepad32::setup(const ControllerCallback&, const ControllerCallback&)'
void setup(const ControllerCallback& onConnect, const ControllerCallback& onDisconnect);
^~~~~
und
C:\Users\User1796\AppData\Local\Arduino15\packages\esp32-bluepad32\hardware\esp32\4.1.0/tools/sdk/esp32s3/include/bluepad32_arduino/include/ArduinoBluepad32.h:68:10: note: candidate: 'void Bluepad32::setup(const ControllerCallback&, const ControllerCallback&)'
void setup(const ControllerCallback& onConnect, const ControllerCallback& onDisconnect);
^~~~~
Also habe ich noch ein Problem bei der Übergabe der Referenz auf die Funktionen an die Unterfunktion BP32.setup(&XboxController::onConnectedController, &XboxController::onDisconnectedController);.
Hier noch der Beispielcode: BP32_Controler_Example_Line_48
Wie kann ich den Konflikt lösen?