From fd0904acf54d3536af08cd9b0457336718fe6fc5 Mon Sep 17 00:00:00 2001 From: M1n-0 Date: Sat, 2 May 2026 22:05:31 +0200 Subject: [PATCH] add test code (forgot to push) --- main.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 main.py create mode 100644 test.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..761db16 --- /dev/null +++ b/main.py @@ -0,0 +1,73 @@ +#include + +BleGamepad bleGamepad("Manette ModulX", "Nono", 100); + +// --------- BOUTONS --------- +// Boutons câblés entre GPIO et GND +const int buttonPins[8] = { + 13, 12, 14, 27, + 26, 25, 33, 32 +}; + +// --------- JOYSTICKS --------- +// Joystick gauche +const int joyLX = 34; +const int joyLY = 35; + +// Joystick droit +const int joyRX = 39; +const int joyRY = 36; + +// Zone morte pour éviter les tremblements +const int deadzone = 180; + +// Convertit ADC ESP32 0-4095 vers axe manette -32767 à 32767 +int16_t mapJoystick(int pin) { + int value = analogRead(pin); // 0 à 4095 + int centered = value - 2048; + + if (abs(centered) < deadzone) { + return 0; + } + + return map(value, 0, 4095, -32767, 32767); +} + +void setup() { + Serial.begin(115200); + + for (int i = 0; i < 8; i++) { + pinMode(buttonPins[i], INPUT_PULLUP); + } + + bleGamepad.begin(); +} + +void loop() { + if (bleGamepad.isConnected()) { + + // Gestion des 8 boutons + for (int i = 0; i < 8; i++) { + bool pressed = digitalRead(buttonPins[i]) == LOW; + + if (pressed) { + bleGamepad.press(i + 1); // boutons 1 à 8 + } else { + bleGamepad.release(i + 1); + } + } + + // Lecture des joysticks + int16_t lx = mapJoystick(joyLX); + int16_t ly = mapJoystick(joyLY); + int16_t rx = mapJoystick(joyRX); + int16_t ry = mapJoystick(joyRY); + + // Envoie des axes + // X, Y = joystick gauche + // RX, RY = joystick droit + bleGamepad.setAxes(lx, ly, 0, rx, ry, 0); + + delay(10); + } +} \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..8f54c15 --- /dev/null +++ b/test.py @@ -0,0 +1,73 @@ +#include + +BleGamepad bleGamepad("Manette ESP32", "Nino", 100); + +// --------- BOUTONS --------- +// Boutons câblés entre GPIO et GND +const int buttonPins[8] = { + 13, 12, 14, 27, + 26, 25, 33, 32 +}; + +// --------- JOYSTICKS --------- +// Joystick gauche +const int joyLX = 34; +const int joyLY = 35; + +// Joystick droit +const int joyRX = 39; +const int joyRY = 36; + +// Zone morte pour éviter les tremblements +const int deadzone = 180; + +// Convertit ADC ESP32 0-4095 vers axe manette -32767 à 32767 +int16_t mapJoystick(int pin) { + int value = analogRead(pin); // 0 à 4095 + int centered = value - 2048; + + if (abs(centered) < deadzone) { + return 0; + } + + return map(value, 0, 4095, -32767, 32767); +} + +void setup() { + Serial.begin(115200); + + for (int i = 0; i < 8; i++) { + pinMode(buttonPins[i], INPUT_PULLUP); + } + + bleGamepad.begin(); +} + +void loop() { + if (bleGamepad.isConnected()) { + + // Gestion des 8 boutons + for (int i = 0; i < 8; i++) { + bool pressed = digitalRead(buttonPins[i]) == LOW; + + if (pressed) { + bleGamepad.press(i + 1); // boutons 1 à 8 + } else { + bleGamepad.release(i + 1); + } + } + + // Lecture des joysticks + int16_t lx = mapJoystick(joyLX); + int16_t ly = mapJoystick(joyLY); + int16_t rx = mapJoystick(joyRX); + int16_t ry = mapJoystick(joyRY); + + // Envoie des axes + // X, Y = joystick gauche + // RX, RY = joystick droit + bleGamepad.setAxes(lx, ly, 0, rx, ry, 0); + + delay(10); + } +} \ No newline at end of file