From de67aeeb29e73e34cb42f94d8c8a01f1f5c2a1d8 Mon Sep 17 00:00:00 2001 From: boerge1 Date: Sat, 16 Mar 2024 18:31:11 +0100 Subject: [PATCH 1/2] Issue_180: Play special shortcut on startup if a GPIO is set --- src/commands.cpp | 3 +++ src/commands.hpp | 6 ++++++ src/constants.hpp | 29 +++++++++++++++++++++++------ src/mp3.cpp | 15 ++++++++++++++- src/mp3.hpp | 2 ++ src/state_machine.cpp | 7 +++++++ src/tonuino.cpp | 15 ++++++++++++++- 7 files changed, 69 insertions(+), 8 deletions(-) diff --git a/src/commands.cpp b/src/commands.cpp index 3cae925..3cb67ff 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -33,6 +33,9 @@ const command cmd_table[][4] PROGMEM = { /* downLongRepeat, */ ,{ command::none , command::none , command::volume_down, command::none } /* updownLong, */ ,{ command::none , command::shortcut1 , command::to_first , command::to_first } #endif +#ifdef SPECIAL_START_SHORTCUT +/* specialStart, */ ,{ command::none , command::specialStart,command::none , command::none } +#endif #ifdef SerialInputAsCommand /* menu_jump , */ ,{ command::menu_jump , command::none , command::none , command::none } #endif diff --git a/src/commands.hpp b/src/commands.hpp index d67a54c..56fd70b 100644 --- a/src/commands.hpp +++ b/src/commands.hpp @@ -61,6 +61,9 @@ enum class commandRaw: uint8_t { fiveLong, fiveLongRepeat, #endif +#ifdef SPECIAL_START_SHORTCUT + specialStart, +#endif #ifdef SerialInputAsCommand menu_jump, #endif @@ -102,6 +105,9 @@ enum class command: uint8_t { ext_begin = buttonExtSC_begin, ext_end = ext_begin + buttonExtSC_buttons, #endif +#ifdef SPECIAL_START_SHORTCUT + specialStart, +#endif }; enum class state_for_command: uint8_t { diff --git a/src/constants.hpp b/src/constants.hpp index 9025c7c..334acfa 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -76,8 +76,8 @@ inline constexpr level getLevel(levelType t, int l) { return (l == LOW) #ifdef ALLinONE_Plus // if using Rotary Encoder Buchse -//inline constexpr uint8_t rotaryEncoderClkPin = 31; // PE2 -//inline constexpr uint8_t rotaryEncoderDtPin = 32; // PE3 +//inline constexpr uint8_t rotaryEncoderClkPin = 31; // PE1 +//inline constexpr uint8_t rotaryEncoderDtPin = 32; // PE2 // if using Opt Leiste (Male) inline constexpr uint8_t rotaryEncoderClkPin = 36; // PF2 @@ -112,13 +112,17 @@ inline constexpr uint8_t neoPixelRingPin = 5; // D5 on AiO/Classic #endif // ALLinONE_Plus inline constexpr uint8_t neoPixelNumber = 24; // Total Number of Pixels -/* uncomment the below line to enable the Speaker on/off on Pin D6 for Classic to suppress noise +/* uncomment the below line to enable the Speaker on/off for Classic to suppress noise * on startup and shutdown (automatically enabled on AiO and AiOplus) - * um den Lautsprecher ein/aus Schalter über D6 für die Classic Variante zu unterstützen bitte + * um den Lautsprecher ein/aus Schalter für die Classic Variante zu unterstützen bitte * in der nächste Zeile den Kommentar entfernen (zur Unterdrückung der Ein- und Ausschaltgeräusche) * (automatisch eingeschaltet für AiO und AiOplus) */ //#define SPKONOFF +#if not defined(ALLinONE_Plus) and not defined(ALLinONE) +inline constexpr uint8_t ampEnablePin = 6; +inline constexpr levelType ampEnablePinType = levelType::activeHigh; +#endif /* uncomment the below line to enable the Headphone Jack detection (automatically enabled on AiOplus) * um die Kopfhörer Erkennung einzuschalten bitte in der nächste Zeile den Kommentar entfernen @@ -161,6 +165,20 @@ inline constexpr levelType dfPlayer_noHeadphoneJackDetectType = levelType::a */ //#define STORE_LAST_CARD +/* uncomment the below line to enable special shortcut on startup via GPIO + * um den spezial Shortcut beim Start via GPIO zu aktivieren, in der nächste Zeile den Kommentar entfernen + */ +//#define SPECIAL_START_SHORTCUT +#ifdef ALLinONE_Plus +inline constexpr uint8_t specialStartShortcutPin = 33; // PE3 +#else +inline constexpr uint8_t specialStartShortcutPin = A6; // A6 on AiO/Classic +#endif // ALLinONE_Plus +inline constexpr levelType specialStartShortcutPinType = levelType::activeHigh; +inline constexpr uint8_t specialStartShortcutFolder = 1; +inline constexpr uint8_t specialStartShortcutTrack = 1; + + /* ################################################################################################# * Default Pins for Classic/AiO Variant * A0 A1 A2 A3 A4 A5 A6 A7 D5 D6 D7 D8 @@ -174,6 +192,7 @@ inline constexpr levelType dfPlayer_noHeadphoneJackDetectType = levelType::a * Speaker off x * Shutdown x * headphone jack detection x + * special start shortcut x * ################################################################################################# */ @@ -250,8 +269,6 @@ inline constexpr unsigned long dfPlayer_timeUntilStarts = 1000; inline constexpr uint8_t shutdownPin = 7; inline constexpr levelType shutdownPinType = levelType::activeLow; -inline constexpr uint8_t ampEnablePin = 6; -inline constexpr levelType ampEnablePinType = levelType::activeHigh; inline constexpr uint8_t openAnalogPin = A7; inline constexpr unsigned long cycleTime = 50; #endif /* TonUINO_Classic or TonUINO_Every */ diff --git a/src/mp3.cpp b/src/mp3.cpp index 8884532..4ec7fa8 100644 --- a/src/mp3.cpp +++ b/src/mp3.cpp @@ -131,6 +131,10 @@ void Mp3::clearMp3Queue() { mp3_track_next = 0; } void Mp3::enqueueTrack(uint8_t folder, uint8_t firstTrack, uint8_t lastTrack, uint8_t currentTrack) { +#ifdef HPJACKDETECT + if (tempSpkOn > 0) + --tempSpkOn; +#endif clearAllQueue(); current_folder = folder; endless = false; @@ -195,6 +199,10 @@ void Mp3::playCurrent() { } } void Mp3::playNext(uint8_t tracks, bool fromOnPlayFinished) { +#ifdef HPJACKDETECT + if (playing == play_folder) + tempSpkOn = 0; +#endif if (playing == play_folder && (current_track+1 < q.size() || endless)) { current_track += tracks; if (current_track >= q.size()) @@ -214,6 +222,9 @@ void Mp3::playNext(uint8_t tracks, bool fromOnPlayFinished) { } void Mp3::playPrevious(uint8_t tracks) { if (playing == play_folder) { +#ifdef HPJACKDETECT + tempSpkOn = 0; +#endif int current_track_tmp = static_cast(current_track) - tracks; current_track = endless ? (current_track_tmp%q.size()+q.size()) % q.size() : max(current_track_tmp, 0); LOG(mp3_log, s_debug, F("playPrevious: "), current_track); @@ -296,7 +307,9 @@ void Mp3::logVolume() { void Mp3::loop() { #ifdef HPJACKDETECT - const level noHeadphoneJackDetect_now = getLevel(dfPlayer_noHeadphoneJackDetectType, digitalRead(dfPlayer_noHeadphoneJackDetect)); + level noHeadphoneJackDetect_now = getLevel(dfPlayer_noHeadphoneJackDetectType, digitalRead(dfPlayer_noHeadphoneJackDetect)); + if (tempSpkOn) + noHeadphoneJackDetect_now = level::active; if (noHeadphoneJackDetect != noHeadphoneJackDetect_now) { noHeadphoneJackDetect = noHeadphoneJackDetect_now; diff --git a/src/mp3.hpp b/src/mp3.hpp index d6c5f4d..1d87b12 100644 --- a/src/mp3.hpp +++ b/src/mp3.hpp @@ -234,6 +234,7 @@ class Mp3: public DfMp3 { #ifdef HPJACKDETECT bool isHeadphoneJackDetect() { return noHeadphoneJackDetect == level::inactive; } + void setTempSpkOn() { tempSpkOn = 2; } #endif private: @@ -285,6 +286,7 @@ class Mp3: public DfMp3 { #ifdef HPJACKDETECT level noHeadphoneJackDetect{level::unknown}; + uint8_t tempSpkOn{}; #endif }; diff --git a/src/state_machine.cpp b/src/state_machine.cpp index b3fd756..d3177bf 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -613,6 +613,13 @@ void Idle::react(command_e const &cmd_e) { return; } break; +#endif +#ifdef SPECIAL_START_SHORTCUT + case command::specialStart: + tonuino.setMyFolder({specialStartShortcutFolder, pmode_t::einzel, specialStartShortcutTrack, 0}, true /*myFolderIsCard*/); + LOG(state_log, s_debug, str_Idle(), str_to(), str_StartPlay()); + transit(); + break; #endif default: break; diff --git a/src/tonuino.cpp b/src/tonuino.cpp index 94f4268..171b2a2 100644 --- a/src/tonuino.cpp +++ b/src/tonuino.cpp @@ -65,6 +65,11 @@ void Tonuino::setup() { digitalWrite(usbAccessPin, getLevel(usbAccessPinType, level::inactive)); #endif +#ifdef SPECIAL_START_SHORTCUT + pinMode(specialStartShortcutPin, INPUT); +#endif + + #ifdef NEO_RING ring.init(); ring.call_on_startup(); @@ -104,7 +109,15 @@ void Tonuino::setup() { commands.getCommandRaw(); // Start Shortcut "at Startup" - e.g. Welcome Sound - SM_tonuino::dispatch(command_e(commandRaw::start)); +#ifdef SPECIAL_START_SHORTCUT + if (getLevel(specialStartShortcutPinType, digitalRead(specialStartShortcutPin)) == level::active) { +#ifdef HPJACKDETECT + mp3.setTempSpkOn(); +#endif // HPJACKDETECT + SM_tonuino::dispatch(command_e(commandRaw::specialStart)); + } else +#endif // SPECIAL_START_SHORTCUT + SM_tonuino::dispatch(command_e(commandRaw::start)); } void Tonuino::loop() { From 2a55b6e2c71da5a468624564550fb114f2297e8b Mon Sep 17 00:00:00 2001 From: boerge1 Date: Sun, 17 Mar 2024 13:30:11 +0100 Subject: [PATCH 2/2] Issue_180: Play special shortcut on startup if a GPIO is set --- README.md | 7 ++++--- TonUINO-TNG.ino | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6995806..07dc6d5 100644 --- a/README.md +++ b/README.md @@ -90,11 +90,12 @@ Die SD Karte (Ordner mp3 und advert) hat sich gegenüber der Version 3.1.6 geän # Change Log -## Version 3.1.7 (14.03.2024) +## Version 3.1.7 (17.03.2024) +- [Issue 180](https://github.com/tonuino/TonUINO-TNG/issues/180): Play special shortcut on startup if a GPIO is set - [Issue 056](https://github.com/tonuino/TonUINO-TNG/issues/56): Implement headphone jack detection - -## Version 3.1.7 (09.03.2024) - [Issue 178](https://github.com/tonuino/TonUINO-TNG/issues/178): Use Nano Every optional with HW Serial connection to the DfPlayer + +## Version 3.1.7 (14.03.2024) - [Issue 176](https://github.com/tonuino/TonUINO-TNG/issues/176): Implement the memory game ## Version 3.1.6 (18.02.2024) diff --git a/TonUINO-TNG.ino b/TonUINO-TNG.ino index db46fce..fea09db 100644 --- a/TonUINO-TNG.ino +++ b/TonUINO-TNG.ino @@ -35,7 +35,7 @@ void setup() LOG(init_log, s_error, F("TonUINO Version 3.1 - refactored by Boerge1\n")); LOG(init_log, s_error, F("created by Thorsten Voß and licensed under GNU/GPL.")); LOG(init_log, s_error, F("Information and contribution at https://tonuino.de.\n")); - LOG(init_log, s_error, F("V3.1.7 14.03.24\n")); + LOG(init_log, s_error, F("V3.1.7 17.03.24\n")); Tonuino::getTonuino().setup(); }