From 7c83826400201aaebffb99e3e9a03419ea7f3dc1 Mon Sep 17 00:00:00 2001 From: Sylvain Gougouzian Date: Thu, 20 Aug 2026 12:15:46 +0200 Subject: [PATCH] move to esp32 --- PICOW/hugo_phone/hugo_phone.ino | 82 --------------------------------- esp32/hugo_phone/hugo_phone.ino | 82 +++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 PICOW/hugo_phone/hugo_phone.ino create mode 100644 esp32/hugo_phone/hugo_phone.ino diff --git a/PICOW/hugo_phone/hugo_phone.ino b/PICOW/hugo_phone/hugo_phone.ino deleted file mode 100644 index fcbb3ac..0000000 --- a/PICOW/hugo_phone/hugo_phone.ino +++ /dev/null @@ -1,82 +0,0 @@ -#include - -// Définition des broches GP (et non les numéros physiques de la carte) -const int pinQ1 = 2; // GP2 -const int pinQ2 = 3; // GP3 -const int pinQ3 = 4; // GP4 -const int pinQ4 = 5; // GP5 -const int pinStD = 6; // GP6 - -bool keyWasPressed = false; - -void setup() { - pinMode(pinQ1, INPUT); - pinMode(pinQ2, INPUT); - pinMode(pinQ3, INPUT); - pinMode(pinQ4, INPUT); - pinMode(pinStD, INPUT); - - // Initialise l'émulation du clavier USB - Keyboard.begin(); -} - -void loop() { - bool isKeyPressed = digitalRead(pinStD); - - // Détection du début de l'appui (front montant) - if (isKeyPressed && !keyWasPressed) { - - // CORRECTION 1 : On lit les broches de données INSTANTANÉMENT - int val = digitalRead(pinQ1) | (digitalRead(pinQ2) << 1) | (digitalRead(pinQ3) << 2) | (digitalRead(pinQ4) << 3); - - // CORRECTION 2 : On envoie la touche avec le Shift automatique pour AZERTY - sendKeyAZERTY(val); - - // On applique l'anti-rebond APRÈS la lecture pour ne pas bloquer le signal - delay(80); - - keyWasPressed = true; - } - // Détection du relâchement de la touche - else if (!isKeyPressed && keyWasPressed) { - keyWasPressed = false; - delay(20); // Petit temps mort pour stabiliser la fin de l'appui - } - delay(5); -} - -// Fonction pour forcer la touche Majuscule (Shift) et obtenir un vrai chiffre sur Mac -void typeDigit(char key) { - Keyboard.press(KEY_LEFT_SHIFT); // On simule l'appui sur Shift - Keyboard.press(key); // On appuie sur la touche - delay(15); // Temps de traitement pour macOS - Keyboard.releaseAll(); // On relâche tout -} - -void sendKeyAZERTY(int val) { - switch (val) { - case 1: typeDigit('1'); break; // Écrit "1" (via Shift + &) - case 2: typeDigit('2'); break; // Écrit "2" (via Shift + é) - case 3: typeDigit('3'); break; // Écrit "3" (via Shift + ") - case 4: typeDigit('4'); break; // Écrit "4" (via Shift + ') - case 5: typeDigit('5'); break; // Écrit "5" (via Shift + () - case 6: typeDigit('6'); break; // Écrit "6" (via Shift + -) - case 7: typeDigit('7'); break; // Écrit "7" (via Shift + è) - case 8: typeDigit('8'); break; // Écrit "8" (via Shift + _) - case 9: typeDigit('9'); break; // Écrit "9" (via Shift + ç) - case 10: typeDigit('0'); break; // Écrit "0" (via Shift + à) - - case 11: // Écrit '*' (Shift + ']' sur AZERTY Mac) - Keyboard.press(KEY_LEFT_SHIFT); - Keyboard.press(']'); - delay(15); - Keyboard.releaseAll(); - break; - - case 12: // Écrit '#' - Keyboard.write('~'); - break; - - default: break; - } -} \ No newline at end of file diff --git a/esp32/hugo_phone/hugo_phone.ino b/esp32/hugo_phone/hugo_phone.ino new file mode 100644 index 0000000..a964ecf --- /dev/null +++ b/esp32/hugo_phone/hugo_phone.ino @@ -0,0 +1,82 @@ +#include + +// Instanciation avec le nom du périphérique, le fabricant et le niveau de batterie initial +BleKeyboard bleKeyboard("S63 Vintage Keypad", "RetroCom", 100); + +// Pinout ESP32-C3 +const int PIN_Q1 = 0; +const int PIN_Q2 = 3; +const int PIN_Q3 = 4; +const int PIN_Q4 = 5; +const int PIN_STD = 6; + +// Table de correspondance DTMF (norme MT8870) +const char DTMF_MAP[] = { + 'D', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', '0', '*', + '#', 'A', 'B', 'C' +}; + +volatile bool toucheDetectee = false; + +// Interruption déclenchée par la broche StD du MT8870 +void IRAM_ATTR stdISR() { + toucheDetectee = true; +} + +void envoyerToucheAZERTY(char touche) { + // Si c'est un chiffre (0 à 9), on applique SHIFT + if (touche >= '0' && touche <= '9') { + bleKeyboard.press(KEY_LEFT_SHIFT); + bleKeyboard.press(touche); + delay(10); // Court délai pour s'assurer que l'OS enregistre la combinaison + bleKeyboard.releaseAll(); + } else { + // Pour les caractères non numériques (*, #, A, B, C, D) + bleKeyboard.write(touche); + } +} + +void setup() { + Serial.begin(115200); + + pinMode(PIN_Q1, INPUT); + pinMode(PIN_Q2, INPUT); + pinMode(PIN_Q3, INPUT); + pinMode(PIN_Q4, INPUT); + pinMode(PIN_STD, INPUT); + + attachInterrupt(digitalPinToInterrupt(PIN_STD), stdISR, RISING); + + // Démarrage du service Bluetooth NimBLE + bleKeyboard.begin(); + Serial.println("NimBLE Bluetooth prêt ! En attente de connexion..."); +} + +void loop() { + if (toucheDetectee) { + delay(10); // Stabilisation du signal DTMF + + // Lecture binaire du MT8870 + int q1 = digitalRead(PIN_Q1); + int q2 = digitalRead(PIN_Q2); + int q3 = digitalRead(PIN_Q3); + int q4 = digitalRead(PIN_Q4); + + int codeBinaire = (q4 << 3) | (q3 << 2) | (q2 << 1) | q1; + char touche = DTMF_MAP[codeBinaire]; + + // Envoi de la touche si l'appareil est connecté en Bluetooth + if (bleKeyboard.isConnected()) { + envoyerToucheAZERTY(touche); + Serial.print("Touche envoyée : "); + Serial.println(touche); + } else { + Serial.print("Touche tapée (hors connexion BT) : "); + Serial.println(touche); + } + + toucheDetectee = false; + } +} -- 2.51.2