Skip to content

Commit 175bf4e

Browse files
v3.7.0-rc.0c
Renames example->Bluepad32 to example-Bluepad32_ESP32 to avoid conflict with the Bluepad32 NINA library
1 parent a66a4f2 commit 175bf4e

File tree

6 files changed

+331
-0
lines changed

6 files changed

+331
-0
lines changed

bluepad32_files/libraries/Bluepad32_ESP32/examples/Controller/.skip.esp32s2

Whitespace-only changes.
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#include <Bluepad32.h>
2+
3+
GamepadPtr myGamepads[BP32_MAX_GAMEPADS];
4+
5+
// This callback gets called any time a new gamepad is connected.
6+
// Up to 4 gamepads can be connected at the same time.
7+
void onConnectedGamepad(GamepadPtr gp) {
8+
bool foundEmptySlot = false;
9+
for (int i = 0; i < BP32_MAX_GAMEPADS; i++) {
10+
if (myGamepads[i] == nullptr) {
11+
Serial.printf("CALLBACK: Gamepad is connected, index=%d\n", i);
12+
// Additionally, you can get certain gamepad properties like:
13+
// Model, VID, PID, BTAddr, flags, etc.
14+
GamepadProperties properties = gp->getProperties();
15+
Serial.printf("Gamepad model: %s, VID=0x%04x, PID=0x%04x\n", gp->getModelName().c_str(), properties.vendor_id,
16+
properties.product_id);
17+
myGamepads[i] = gp;
18+
foundEmptySlot = true;
19+
break;
20+
}
21+
}
22+
if (!foundEmptySlot) {
23+
Serial.println("CALLBACK: Gamepad connected, but could not found empty slot");
24+
}
25+
}
26+
27+
void onDisconnectedGamepad(GamepadPtr gp) {
28+
bool foundGamepad = false;
29+
30+
for (int i = 0; i < BP32_MAX_GAMEPADS; i++) {
31+
if (myGamepads[i] == gp) {
32+
Serial.printf("CALLBACK: Gamepad is disconnected from index=%d\n", i);
33+
myGamepads[i] = nullptr;
34+
foundGamepad = true;
35+
break;
36+
}
37+
}
38+
39+
if (!foundGamepad) {
40+
Serial.println("CALLBACK: Gamepad disconnected, but not found in myGamepads");
41+
}
42+
}
43+
44+
// Arduino setup function. Runs in CPU 1
45+
void setup() {
46+
Serial.begin(115200);
47+
Serial.printf("Firmware: %s\n", BP32.firmwareVersion());
48+
49+
// Setup the Bluepad32 callbacks
50+
BP32.setup(&onConnectedGamepad, &onDisconnectedGamepad);
51+
52+
// "forgetBluetoothKeys()" should be called when the user performs
53+
// a "device factory reset", or similar.
54+
// Calling "forgetBluetoothKeys" in setup() just as an example.
55+
// Forgetting Bluetooth keys prevents "paired" gamepads to reconnect.
56+
// But might also fix some connection / re-connection issues.
57+
BP32.forgetBluetoothKeys();
58+
}
59+
60+
// Arduino loop function. Runs in CPU 1
61+
void loop() {
62+
// This call fetches all the gamepad info from the NINA (ESP32) module.
63+
// Just call this function in your main loop.
64+
// The gamepads pointer (the ones received in the callbacks) gets updated
65+
// automatically.
66+
BP32.update();
67+
68+
// It is safe to always do this before using the gamepad API.
69+
// This guarantees that the gamepad is valid and connected.
70+
for (int i = 0; i < BP32_MAX_GAMEPADS; i++) {
71+
GamepadPtr myGamepad = myGamepads[i];
72+
73+
if (myGamepad && myGamepad->isConnected()) {
74+
// There are different ways to query whether a button is pressed.
75+
// By query each button individually:
76+
// a(), b(), x(), y(), l1(), etc...
77+
if (myGamepad->a()) {
78+
static int colorIdx = 0;
79+
// Some gamepads like DS4 and DualSense support changing the color LED.
80+
// It is possible to change it by calling:
81+
switch (colorIdx % 3) {
82+
case 0:
83+
// Red
84+
myGamepad->setColorLED(255, 0, 0);
85+
break;
86+
case 1:
87+
// Green
88+
myGamepad->setColorLED(0, 255, 0);
89+
break;
90+
case 2:
91+
// Blue
92+
myGamepad->setColorLED(0, 0, 255);
93+
break;
94+
}
95+
colorIdx++;
96+
}
97+
98+
if (myGamepad->b()) {
99+
// Turn on the 4 LED. Each bit represents one LED.
100+
static int led = 0;
101+
led++;
102+
// Some gamepads like the DS3, DualSense, Nintendo Wii, Nintendo Switch
103+
// support changing the "Player LEDs": those 4 LEDs that usually indicate
104+
// the "gamepad seat".
105+
// It is possible to change them by calling:
106+
myGamepad->setPlayerLEDs(led & 0x0f);
107+
}
108+
109+
if (myGamepad->x()) {
110+
// Duration: 255 is ~2 seconds
111+
// force: intensity
112+
// Some gamepads like DS3, DS4, DualSense, Switch, Xbox One S support
113+
// rumble.
114+
// It is possible to set it by calling:
115+
myGamepad->setRumble(0xc0 /* force */, 0xc0 /* duration */);
116+
}
117+
118+
// Another way to query the buttons, is by calling buttons(), or
119+
// miscButtons() which return a bitmask.
120+
// Some gamepads also have DPAD, axis and more.
121+
Serial.printf(
122+
"idx=%d, dpad: 0x%02x, buttons: 0x%04x, axis L: %4d, %4d, axis R: %4d, "
123+
"%4d, brake: %4d, throttle: %4d, misc: 0x%02x\n",
124+
i, // Gamepad Index
125+
myGamepad->dpad(), // DPAD
126+
myGamepad->buttons(), // bitmask of pressed buttons
127+
myGamepad->axisX(), // (-511 - 512) left X Axis
128+
myGamepad->axisY(), // (-511 - 512) left Y axis
129+
myGamepad->axisRX(), // (-511 - 512) right X axis
130+
myGamepad->axisRY(), // (-511 - 512) right Y axis
131+
myGamepad->brake(), // (0 - 1023): brake button
132+
myGamepad->throttle(), // (0 - 1023): throttle (AKA gas) button
133+
myGamepad->miscButtons() // bitmak of pressed "misc" buttons
134+
);
135+
136+
// You can query the axis and other properties as well. See Gamepad.h
137+
// For all the available functions.
138+
}
139+
}
140+
141+
// The main loop must have some kind of "yield to lower priority task" event.
142+
// Otherwise the watchdog will get triggered.
143+
// If your main loop doesn't have one, just add a simple `vTaskDelay(1)`.
144+
// Detailed info here:
145+
// https://stackoverflow.com/questions/66278271/task-watchdog-got-triggered-the-tasks-did-not-reset-the-watchdog-in-time
146+
147+
// vTaskDelay(1);
148+
delay(150);
149+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#######################################
2+
# Syntax Coloring Map For WiFiNINA
3+
#######################################
4+
5+
#######################################
6+
# Library (KEYWORD1)
7+
#######################################
8+
9+
10+
Controller KEYWORD1
11+
Gamepad KEYWORD1
12+
Bluepad32 KEYWORD1
13+
BP32 KEYWORD1
14+
15+
16+
#######################################
17+
# Methods and Functions (KEYWORD2)
18+
#######################################
19+
20+
# Bluepad32
21+
firmwareVersion KEYWORD2
22+
setDebug KEYWORD2
23+
pinMode KEYWORD2
24+
digitalRead KEYWORD2
25+
digitalWrite KEYWORD2
26+
27+
# Gamepad
28+
update KEYWORD2
29+
forgetBluetoothKeys KEYWORD2
30+
setup KEYWORD2
31+
a KEYWORD2
32+
b KEYWORD2
33+
x KEYWORD2
34+
y KEYWORD2
35+
l1 KEYWORD2
36+
l2 KEYWORD2
37+
r1 KEYWORD2
38+
r2 KEYWORD2
39+
thumbL KEYWORD2
40+
thumbR KEYWORD2
41+
buttons KEYWORD2
42+
miscButtons KEYWORD2
43+
axisX KEYWORD2
44+
axisY KEYWORD2
45+
axisRX KEYWORD2
46+
axisRY KEYWORD2
47+
brake KEYWORD2
48+
throttle KEYWORD2
49+
miscSystem KEYWORD2
50+
miscBack KEYWORD2
51+
miscHome KEYWORD2
52+
isConnected KEYWORD2
53+
getModel KEYWORD2
54+
setPlayerLEDs KEYWORD2
55+
setColorLED KEYWORD2
56+
setRumble KEYWORD2
57+
58+
59+
#######################################
60+
# Constants (LITERAL1)
61+
#######################################
62+
63+
# Controllers
64+
CONTROLLER_TYPE_UnknownSteamController LITERAL1
65+
CONTROLLER_TYPE_SteamController LITERAL1
66+
CONTROLLER_TYPE_SteamControllerV2 LITERAL1
67+
CONTROLLER_TYPE_UnknownNonSteamController LITERAL1
68+
CONTROLLER_TYPE_XBox360Controller LITERAL1
69+
CONTROLLER_TYPE_XBoxOneController LITERAL1
70+
CONTROLLER_TYPE_PS3Controller LITERAL1
71+
CONTROLLER_TYPE_PS4Controller LITERAL1
72+
CONTROLLER_TYPE_WiiController LITERAL1
73+
CONTROLLER_TYPE_AppleController LITERAL1
74+
CONTROLLER_TYPE_AndroidController LITERAL1
75+
CONTROLLER_TYPE_SwitchProController LITERAL1
76+
CONTROLLER_TYPE_SwitchJoyConLeft LITERAL1
77+
CONTROLLER_TYPE_SwitchJoyConRight LITERAL1
78+
CONTROLLER_TYPE_SwitchJoyConPair LITERAL1
79+
CONTROLLER_TYPE_SwitchInputOnlyController LITERAL1
80+
CONTROLLER_TYPE_MobileTouch LITERAL1
81+
CONTROLLER_TYPE_XInputSwitchController LITERAL1
82+
CONTROLLER_TYPE_PS5Controller LITERAL1
83+
CONTROLLER_TYPE_iCadeController LITERAL1
84+
CONTROLLER_TYPE_SmartTVRemoteController LITERAL1
85+
CONTROLLER_TYPE_EightBitdoController LITERAL1
86+
CONTROLLER_TYPE_GenericController LITERAL1
87+
CONTROLLER_TYPE_NimbusController LITERAL1
88+
CONTROLLER_TYPE_OUYAController LITERAL1
89+
90+
# DPAD
91+
DPAD_UP LITERAL1
92+
DPAD_DOWN LITERAL1
93+
DPAD_RIGHT LITERAL1
94+
DPAD_LEFT LITERAL1
95+
96+
# Buttons
97+
BUTTON_A LITERAL1
98+
BUTTON_B LITERAL1
99+
BUTTON_X LITERAL1
100+
BUTTON_Y LITERAL1
101+
BUTTON_SHOULDER_L LITERAL1
102+
BUTTON_SHOULDER_R LITERAL1
103+
BUTTON_TRIGGER_L LITERAL1
104+
BUTTON_TRIGGER_R LITERAL1
105+
BUTTON_THUMB_L LITERAL1
106+
BUTTON_THUMB_R LITERAL1
107+
108+
# Misc buttons
109+
MISC_BUTTON_SYSTEM LITERAL1
110+
MISC_BUTTON_BACK LITERAL1
111+
MISC_BUTTON_HOME LITERAL1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=Bluepad32_ESP32
2+
version=3.7.0
3+
author=Ricardo Quesada
4+
maintainer=Ricardo Quesada <ricardoquesada@gmail.com>
5+
sentence=Enables gamepad support for ESP32 based controllers including: ESP32, ESP32-S3 and ESP32-C3.
6+
paragraph=With this library you can use any Bluetooth gamepad like DualSense, DualShock4, Nintendo Switch, Android gamepads, Xbox One S, etc. Bluetooth mice are also supported.
7+
category=Communication
8+
url=http://gitlab.com/ricardoquesada/bluepad32
9+
architectures=*
10+
includes=Bluepad32.h

bluepad32_files/package_esp32_bluepad32_index.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,67 @@
99
"online": "https://discord.gg/r5aMn6Cw5q"
1010
},
1111
"platforms": [
12+
{
13+
"name": "esp32_bluepad32",
14+
"architecture": "esp32",
15+
"version": "3.7.0-rc.0c",
16+
"category": "Contributed",
17+
"url": "https://github.com/ricardoquesada/esp32-arduino-lib-builder/releases/download/3.7.0-rc.0/esp32-bluepad32-3.7.0-rc.0c.zip",
18+
"archiveFileName": "esp32-bluepad32-3.7.0-rc.0c.zip",
19+
"checksum": "SHA-256:e4a1f04a0c022d9a74f16064a05ddd559c29685b270648c2ceac41f3c1c707ba",
20+
"size": "215365839",
21+
"help": {
22+
"online": "https://discord.gg/r5aMn6Cw5q"
23+
},
24+
"boards": [
25+
{
26+
"name": "ESP32 Dev Board"
27+
},
28+
{
29+
"name": "ESP32-S3 Dev Board"
30+
},
31+
{
32+
"name": "ESP32-C3 Dev Board"
33+
}
34+
],
35+
"toolsDependencies": [
36+
{
37+
"packager": "esp32",
38+
"name": "xtensa-esp32-elf-gcc",
39+
"version": "esp-2021r2-patch5-8.4.0"
40+
},
41+
{
42+
"packager": "esp32",
43+
"name": "xtensa-esp32s3-elf-gcc",
44+
"version": "esp-2021r2-patch5-8.4.0"
45+
},
46+
{
47+
"packager": "esp32",
48+
"name": "riscv32-esp-elf-gcc",
49+
"version": "esp-2021r2-patch5-8.4.0"
50+
},
51+
{
52+
"packager": "esp32",
53+
"name": "openocd-esp32",
54+
"version": "v0.11.0-esp32-20221026"
55+
},
56+
{
57+
"packager": "esp32",
58+
"name": "esptool_py",
59+
"version": "4.5.1"
60+
},
61+
{
62+
"packager": "esp32",
63+
"name": "mkspiffs",
64+
"version": "0.2.3"
65+
},
66+
{
67+
"packager": "esp32",
68+
"name": "mklittlefs",
69+
"version": "3.0.0-gnu12-dc7f933"
70+
}
71+
]
72+
},
1273
{
1374
"name": "esp32_bluepad32",
1475
"architecture": "esp32",

0 commit comments

Comments
 (0)