TonUINO
TonUINO copied to clipboard
ButtonHandler: Simplify button handling/customization (up to 7 buttons), detect button combos
Allows for easier code to handle button events (by switch()ing on event codes), and detects button combinations (Press X + Y (shortly), X + Y (hold), press and hold 3 buttons). Tested on a different branch, but not tested here yet. For example, see main loop (line 1080++).
// Use ButtonHandler.handle() return value to read codes. // Valid codes (using Up, Down as sample buttons: // Up | ShortPress "Up" was pressed and quickly released // Up | LongPress "Up" was pressed and is still held (after first LONG_PRESS duration) // Up | LongRepeat "Up" was pressed and is still held (after following LONG_PRESS durations) // TwoButtons | Up | (Down << As2nd) | ShortPress "Up" was pressed and then "Down", which was quickly released // TwoButtons | Up | (Down << As2nd) | LongPress "Up" was pressed and then also "Down", // which is still held (after first LONG_PRESS duration) // TwoButtons | Up | (Down << As2nd) | LongRepeat "Up" was pressed and then also "Down", // which is still held (after following LONG_PRESS durations) // AllThreeLong any three buttons have been pressed at the same time for one LONG_PRESS duration
Gibt es eine Beschreibung was der Code tun sollte? Und wie man es nutzen/prüfen kann? Würde es gerne testen/reviewen ...
Ich suche eine Möglichkeit weitere Buttons zB an A5-A7 anzuschließen und dort entweder Shortcuts oder direkt drei Verzeichnisse/Dateien zuordnen. Anwendung wäre zB eine „Feuerwehr-Taste“, dir dann Martinshorn abspielt. Ein normaler Druck (nicht lang).
Danke!
Moin.
Ich habe die Änderungen auf einem anderen Branch getestet (hauptsächlich Abspielen, Wechsel ins Admin-Menü und zurück. Nicht getestet: Optionen im Adminmenü, Modifier-Karten, Karten anlernen).
Du kannst diesen Stand als Basis nehmen. Für weitere Tasten musst du dies anpassen:
-
Zeile 640: const uint8_t aButtonPin[] = #if FIVEBUTTONS { A0, A1, A2, A3, A4 }; #else { A0, A1, A2 }; #endif ersetzt du gegen deine Liste an Pins für die Buttons, z.B. const uint8_t aButtonPin[] = { A0, A1, A2, A3, A4, A5, A6 };
-
Zeile 713: #if FIVEBUTTONS ExtButton button[numButtons] = { A0, A1, A2, A3, A4 }; // the button pins enum ButtonID { Pause, Up, Down, Four, Five }; // internal name #else ExtButton button[numButtons] = { A0, A1, A2 }; enum ButtonID { Pause, Up, Down }; #endif ersetzt du gegen ExtButton button[numButtons] = { A0, A1, A2, A3, A4, A5, A6 }; // hier nochmal die Pins enum ButtonID { Pause, Up, Down, Four, Five, Tatuetata, Bimmelim }; // internal name
-
Zeile 1088 Die Funktion loop() kümmert sich um die Behandlung von Ereignissen (auch Knopfdrücken) während des regulären Abspielens. In Zeile 1088 ist eine switch()-Anweisung. Da kannst du weitere Zeilen für deine zusätzlichen Buttons einfügen.
switch (event) { case Pause | ShortPress: case Pause | LongPress: case Pause | LongRepeat: // ignore button events for Pause button if handled by activeModifier if (activeModifier != nullptr && activeModifier->handlePause()) eventHandled = true; break;
case Tatuetata | ShortPress: playShortCut(2); break; case Bimmelim | ShortPress: myFolder = &myCard.nfcFolderSettings; myFolder->mode= 4; // Einzelmodus myFolder->folder = 8; // Ordner 8 myFolder->special= 7; // Titel 7 playFolder(); break; case AllThreeLong: // admin menu .... }
Viel Spaß!