1
0
mirror of https://github.com/xfjx/TonUINO.git synced 2025-08-22 09:04:04 +02:00

Added Support for 5 Buttons // Unterstützung von 5 Knöpfen hinzugefügt

This commit is contained in:
Thorsten Voß
2019-02-25 22:35:16 +01:00
parent e6b78d2d8c
commit dfa8d069bf

View File

@@ -6,6 +6,20 @@
#include <SoftwareSerial.h>
#include <avr/sleep.h>
/*
_____ _____ _____ _____ _____
|_ _|___ ___| | | | | | |
| | | . | | | |- -| | | | | |
|_| |___|_|_|_____|_____|_|___|_____|
TonUINO Version 2.1
created by Thorsten Voß and licensed under GNU/GPL.
Information and contribution at https://tonuino.de.
*/
// uncomment the below line to enable five button support
//#define FIVEBUTTONS
static const uint32_t cardCookie = 322417479;
// DFPlayer Mini
@@ -300,15 +314,27 @@ MFRC522::StatusCode status;
#define busyPin 4
#define shutdownPin 7
#ifdef FIVEBUTTONS
#define buttonFourPin A3
#define buttonFivePin A4
#endif
#define LONG_PRESS 1000
Button pauseButton(buttonPause);
Button upButton(buttonUp);
Button downButton(buttonDown);
#ifdef FIVEBUTTONS
Button buttonFour(buttonFourPin);
Button buttonFive(buttonFivePin);
#endif
bool ignorePauseButton = false;
bool ignoreUpButton = false;
bool ignoreDownButton = false;
#ifdef FIVEBUTTONS
bool ignoreButtonFour = false;
bool ignoreButtonFive = false;
#endif
/// Funktionen für den Standby Timer (z.B. über Pololu-Switch oder Mosfet)
@@ -407,10 +433,14 @@ void setup() {
pinMode(buttonPause, INPUT_PULLUP);
pinMode(buttonUp, INPUT_PULLUP);
pinMode(buttonDown, INPUT_PULLUP);
#ifdef FIVEBUTTONS
pinMode(buttonFourPin, INPUT_PULLUP);
pinMode(buttonFivePin, INPUT_PULLUP);
#endif
pinMode(shutdownPin, OUTPUT);
digitalWrite(shutdownPin, LOW);
// RESET --- ALLE DREI KNÖPFE BEIM STARTEN GEDRÜCKT HALTEN -> alle EINSTELLUNGEN werden gelöscht
/* // RESET --- ALLE DREI KNÖPFE BEIM STARTEN GEDRÜCKT HALTEN -> alle EINSTELLUNGEN werden gelöscht
if (digitalRead(buttonPause) == LOW && digitalRead(buttonUp) == LOW &&
digitalRead(buttonDown) == LOW) {
Serial.println(F("Reset -> EEPROM wird gelöscht"));
@@ -418,6 +448,7 @@ void setup() {
EEPROM.update(i, 0);
}
}
*/
// Start Shortcut "at Startup" - e.g. Welcome Sound
playShortCut(3);
}
@@ -426,6 +457,10 @@ void readButtons() {
pauseButton.read();
upButton.read();
downButton.read();
#ifdef FIVEBUTTONS
buttonFour.read();
buttonFive.read();
#endif
}
void volumeUpButton() {
@@ -606,6 +641,7 @@ void loop() {
}
if (upButton.pressedFor(LONG_PRESS)) {
#ifndef FIVEBUTTONS
if (isPlaying()) {
if (!mySettings.invertVolumeButtons) {
volumeUpButton();
@@ -618,6 +654,7 @@ void loop() {
playShortCut(1);
}
ignoreUpButton = true;
#endif
} else if (upButton.wasReleased()) {
if (!ignoreUpButton)
if (!mySettings.invertVolumeButtons) {
@@ -630,6 +667,7 @@ void loop() {
}
if (downButton.pressedFor(LONG_PRESS)) {
#ifndef FIVEBUTTONS
if (isPlaying()) {
if (!mySettings.invertVolumeButtons) {
volumeDownButton();
@@ -642,6 +680,7 @@ void loop() {
playShortCut(2);
}
ignoreDownButton = true;
#endif
} else if (downButton.wasReleased()) {
if (!ignoreDownButton) {
if (!mySettings.invertVolumeButtons) {
@@ -653,6 +692,34 @@ void loop() {
}
ignoreDownButton = false;
}
#ifdef FIVEBUTTONS
if (buttonFour.wasReleased()) {
if (isPlaying()) {
if (!mySettings.invertVolumeButtons) {
volumeUpButton();
}
else {
nextButton();
}
}
else {
playShortCut(1);
}
}
if (buttonFive.wasReleased()) {
if (isPlaying()) {
if (!mySettings.invertVolumeButtons) {
volumeDownButton();
}
else {
previousButton();
}
}
else {
playShortCut(2);
}
}
#endif
// Ende der Buttons
} while (!mfrc522.PICC_IsNewCardPresent());
@@ -780,6 +847,22 @@ void adminMenu() {
setstandbyTimer();
}
bool askCode(uint8_t *code) {
uint8_t x = 0;
while (x < 3) {
readButtons();
if (pauseButton.pressedFor(LONG_PRESS))
break;
if (pauseButton.wasReleased())
code[x++] = 1;
if (upButton.wasReleased())
code[x++] = 2;
if (downButton.wasReleased())
code[x++] = 3;
}
return true;
}
uint8_t voiceMenu(int numberOfOptions, int startMessage, int messageOffset,
bool preview = false, int previewFromFolder = 0, int defaultValue = 0, bool exitWithLongPress = false) {
uint8_t returnValue = defaultValue;
@@ -897,7 +980,7 @@ void resetCard() {
if (!mfrc522.PICC_ReadCardSerial())
return;
Serial.print(F("Karte wird neu Konfiguriert!"));
Serial.print(F("Karte wird neu konfiguriert!"));
setupCard();
}