Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Defina o endereço MAC do controle autorizado (use o seu)
- const uint8_t allowed_btaddr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- int LED_pin = 2; // ESP32 WROOM 32 normalmente pino 2 ou 15, ESP32 C3 normalmente o pino 8,
- // ...
- 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);
- 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);
- Serial.print("Controller BTAddr: ");
- for (int i = 0; i < 6; i++) {
- Serial.printf("%02X", properties.btaddr[i]);
- if (i < 5) Serial.print(":");
- }
- Serial.println();
- //Verificando se o controle está autorizado:
- bool isAllowed = true;
- for (int j = 0; j < 6; j++) {
- if (properties.btaddr[j] != allowed_btaddr[j]) {
- isAllowed = false;
- break;
- }
- }
- if (!isAllowed) {
- Serial.println("Controller Not Allowed! Disconnecting...");
- ctl->disconnect();
- conectado = false;
- return; // Sai da função sem adicionar ao array
- }
- myControllers[i] = ctl;
- foundEmptySlot = true;
- digitalWrite(LED_pin, HIGH); // Liga o LED do ESP para indicar controle conectado
- conectado = true;
- break;
- }
- }
- if (!foundEmptySlot) {
- Serial.println("CALLBACK: Controller connected, but could not found empty slot");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement