Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ButtonHandler: Simplify button handling/customization (up to 7 buttons), detect button combos #61

Open
wants to merge 1 commit into
base: DEV
Choose a base branch
from

Conversation

hvdh2
Copy link
Contributor

@hvdh2 hvdh2 commented Mar 10, 2020

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

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)).
Tested on a different branch, but not tested here yet.
@hvdh2 hvdh2 changed the title ButtonHandler: Make button handling easier, detect button combinations. ButtonHandler: Simplify button handling/customization (up to 7 buttons), detect button combos Mar 11, 2020
@KarstenDE
Copy link

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!

@hvdh2
Copy link
Contributor Author

hvdh2 commented Apr 6, 2020

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:

  1. 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 };

  2. 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

  3. 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ß!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants