Skip to content

Commit

Permalink
Merge pull request #186: Issue 180: Play special shortcut on startup …
Browse files Browse the repository at this point in the history
…if a GPIO is set
  • Loading branch information
boerge1 authored Mar 27, 2024
2 parents 85aa857 + 9147a37 commit e0a81fc
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ Die SD Karte (Ordner mp3 und advert) hat sich gegenüber der Version 3.1.6 geän

# Change Log

## Version 3.1.7 (27.03.2024)
## Version 3.1.7 (28.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
- [Issue 178](https://github.com/tonuino/TonUINO-TNG/issues/178): Use Nano Every optional with HW Serial connection to the DfPlayer

Expand Down
2 changes: 1 addition & 1 deletion TonUINO-TNG.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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 27.03.24\n"));
LOG(init_log, s_error, F("V3.1.7 28.03.24\n"));

Tonuino::getTonuino().setup();
}
Expand Down
3 changes: 3 additions & 0 deletions src/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ enum class commandRaw: uint8_t {
fiveLong,
fiveLongRepeat,
#endif
#ifdef SPECIAL_START_SHORTCUT
specialStart,
#endif
#ifdef SerialInputAsCommand
menu_jump,
#endif
Expand Down Expand Up @@ -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 {
Expand Down
29 changes: 23 additions & 6 deletions src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -174,6 +192,7 @@ inline constexpr levelType dfPlayer_noHeadphoneJackDetectType = levelType::a
* Speaker off x
* Shutdown x
* headphone jack detection x
* special start shortcut x
* #################################################################################################
*/

Expand Down Expand Up @@ -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 */
Expand Down
15 changes: 14 additions & 1 deletion src/mp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand All @@ -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<int>(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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/mp3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class Mp3: public DfMp3 {

#ifdef HPJACKDETECT
bool isHeadphoneJackDetect() { return noHeadphoneJackDetect == level::inactive; }
void setTempSpkOn() { tempSpkOn = 2; }
#endif

private:
Expand Down Expand Up @@ -285,6 +286,7 @@ class Mp3: public DfMp3 {

#ifdef HPJACKDETECT
level noHeadphoneJackDetect{level::unknown};
uint8_t tempSpkOn{};
#endif

};
Expand Down
7 changes: 7 additions & 0 deletions src/state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<StartPlay>();
break;
#endif
default:
break;
Expand Down
15 changes: 14 additions & 1 deletion src/tonuino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit e0a81fc

Please sign in to comment.