From 2fd5977ac6ecaec757c07692405edd753ed49689 Mon Sep 17 00:00:00 2001 From: boerge1 Date: Sat, 9 Mar 2024 14:47:50 +0100 Subject: [PATCH] Issue_178: Use Nano Every optional with HW Serial connection to the DfPlayer --- README.md | 5 +++-- TonUINO-TNG.ino | 2 +- src/constants.hpp | 26 ++++++++++++++++---------- src/mp3.cpp | 5 ++--- src/mp3.hpp | 9 ++++----- test/src/tonuino_tests.cpp | 6 +++--- 6 files changed, 29 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index c891f67..cfe59c2 100644 --- a/README.md +++ b/README.md @@ -92,10 +92,11 @@ Die SD Karte (Ordner mp3 und advert) hat sich gegenüber der Version 3.1.5 geän # Change Log +## Version 3.1.6 (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.6 (18.02.2024) - [Issue 173](https://github.com/tonuino/TonUINO-TNG/issues/173): Improve Rorary Encoder implementation (also for NANO and optional for next/previous) - -## Version 3.1.6 (12.02.2024) - [Issue 135](https://github.com/tonuino/TonUINO-TNG/issues/135): Make new variants available for online upload (3 butonn variants) - [Issue 167](https://github.com/tonuino/TonUINO-TNG/issues/167): Save the last played card in EEPROM and restore it at startup - [Issue 155](https://github.com/tonuino/TonUINO-TNG/issues/155): Implement a Quiz Game diff --git a/TonUINO-TNG.ino b/TonUINO-TNG.ino index c395446..d93bf5d 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.6 18.02.24\n")); + LOG(init_log, s_error, F("V3.1.6 09.03.24\n")); Tonuino::getTonuino().setup(); } diff --git a/src/constants.hpp b/src/constants.hpp index 81810fb..df54585 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -11,6 +11,11 @@ //#define ALLinONE //#define ALLinONE_Plus +/* If using Nano Every with connected DfPlayer Rx/Tx to D0/D1 uncomment the following lines + * Wenn der Nano Every verwendet wird und Rx/Tx vom DfPlayer mit D0/D1 verbunden ist, den Kommentare der folgenden Zeile entfernen + */ +//#define DFPlayerUsesHardwareSerial + /* uncomment one of the below lines to enable special button support * um die Tasten zu konfigurieren, bitte eine der nächsten Zeilen auskommentieren * default: THREEBUTTONS for classic/every @@ -211,11 +216,14 @@ inline constexpr uint8_t cardRemoveDelay = 3; // ####### mp3 ######################################### -#define DFPlayerUsesSoftwareSerial - -inline constexpr uint8_t maxTracksInFolder = 255; +#ifdef DFPlayerUsesHardwareSerial +inline constexpr HardwareSerial &dfPlayer_serial = Serial1; +#else inline constexpr uint8_t dfPlayer_receivePin = 2; inline constexpr uint8_t dfPlayer_transmitPin = 3; +#endif + +inline constexpr uint8_t maxTracksInFolder = 255; inline constexpr uint8_t dfPlayer_busyPin = 4; inline constexpr levelType dfPlayer_busyPinType = levelType::activeHigh; inline constexpr unsigned long dfPlayer_timeUntilStarts = 1000; @@ -223,7 +231,7 @@ inline constexpr unsigned long dfPlayer_timeUntilStarts = 1000; // ####### tonuino ##################################### inline constexpr uint8_t shutdownPin = 7; -inline constexpr levelType shutdownPinType = levelType::activeHigh; +inline constexpr levelType shutdownPinType = levelType::activeLow; inline constexpr uint8_t ampEnablePin = 6; inline constexpr levelType ampEnablePinType = levelType::activeHigh; inline constexpr uint8_t openAnalogPin = A7; @@ -272,14 +280,13 @@ inline constexpr uint8_t cardRemoveDelay = 3; // ####### mp3 ######################################### #define DFPlayerUsesHardwareSerial +inline constexpr HardwareSerial &dfPlayer_serial = Serial3; inline constexpr uint8_t maxTracksInFolder = 255; -// inline constexpr uint8_t dfPlayer_receivePin = 2; -// inline constexpr uint8_t dfPlayer_transmitPin = 3; inline constexpr uint8_t dfPlayer_busyPin = 13; inline constexpr levelType dfPlayer_busyPinType = levelType::activeHigh; inline constexpr unsigned long dfPlayer_timeUntilStarts = 1000; -inline constexpr HardwareSerial &dfPlayer_serial = Serial3; + // ####### tonuino ##################################### inline constexpr uint8_t shutdownPin = 27; @@ -333,11 +340,10 @@ inline constexpr uint8_t cardRemoveDelay = 3; // ####### mp3 ######################################### -#define DFPlayerUsesSoftwareSerial - -inline constexpr uint8_t maxTracksInFolder = 255; inline constexpr uint8_t dfPlayer_receivePin = 2; inline constexpr uint8_t dfPlayer_transmitPin = 3; + +inline constexpr uint8_t maxTracksInFolder = 255; inline constexpr uint8_t dfPlayer_busyPin = 4; inline constexpr levelType dfPlayer_busyPinType = levelType::activeHigh; inline constexpr unsigned long dfPlayer_timeUntilStarts = 1000; diff --git a/src/mp3.cpp b/src/mp3.cpp index 9728b10..457b957 100644 --- a/src/mp3.cpp +++ b/src/mp3.cpp @@ -38,13 +38,12 @@ void Mp3Notify::OnPlayFinished(DfMp3&, DfMp3_PlaySources /*source*/, uint16_t tr Tonuino::getTonuino().nextTrack(1/*tracks*/, true/*fromOnPlayFinished*/); } -#ifdef DFPlayerUsesSoftwareSerial +#ifndef DFPlayerUsesHardwareSerial Mp3::Mp3(const Settings& settings) : Base{softwareSerial} , softwareSerial{dfPlayer_receivePin, dfPlayer_transmitPin} , settings{settings} -#endif /* DFPlayerUsesSoftwareSerial */ -#ifdef DFPlayerUsesHardwareSerial +#else Mp3::Mp3(const Settings &settings) : Base{dfPlayer_serial} , settings{settings} diff --git a/src/mp3.hpp b/src/mp3.hpp index 90d6666..91f7e13 100644 --- a/src/mp3.hpp +++ b/src/mp3.hpp @@ -10,11 +10,10 @@ #include "queue.hpp" #include "timer.hpp" -#ifdef DFPlayerUsesSoftwareSerial // make sure to include "constants.hpp" before this line! +#ifndef DFPlayerUsesHardwareSerial // make sure to include "constants.hpp" before this line! #include using SerialType = SoftwareSerial; -#endif // DFPlayerUsesSoftwareSerial -#ifdef DFPlayerUsesHardwareSerial +#else using SerialType = HardwareSerial; #endif // DFPlayerUsesHardwareSerial @@ -227,9 +226,9 @@ class Mp3: public DfMp3 { typedef queue track_queue; -#ifdef DFPlayerUsesSoftwareSerial +#ifndef DFPlayerUsesHardwareSerial SoftwareSerial softwareSerial; -#endif /* DFPlayerUsesSoftwareSerial */ +#endif /* not DFPlayerUsesHardwareSerial */ const Settings& settings; uint8_t volume{}; diff --git a/test/src/tonuino_tests.cpp b/test/src/tonuino_tests.cpp index 22cec30..57b761a 100644 --- a/test/src/tonuino_tests.cpp +++ b/test/src/tonuino_tests.cpp @@ -21,7 +21,7 @@ TEST_F(tonuino_test_fixture, initial_state) { EXPECT_EQ(pin_mode[shutdownPin], OUTPUT); #ifdef TonUINO_Classic - EXPECT_EQ(pin_value[shutdownPin], LOW); + EXPECT_EQ(pin_value[shutdownPin], HIGH); #endif #if defined ALLinONE || defined ALLinONE_Plus @@ -210,7 +210,7 @@ TEST_F(tonuino_test_fixture, shutdown_in_idle) { EXPECT_EQ(pin_value[shutdownPin], LOW); #endif #ifdef TonUINO_Classic - EXPECT_EQ(pin_value[shutdownPin], HIGH); + EXPECT_EQ(pin_value[shutdownPin], LOW); #endif EXPECT_TRUE(getMp3() .called_sleep ); EXPECT_TRUE(getMFRC522().called_AntennaOff ); @@ -241,7 +241,7 @@ TEST_F(tonuino_test_fixture, shutdown_in_pause) { EXPECT_EQ(pin_value[shutdownPin], LOW); #endif #ifdef TonUINO_Classic - EXPECT_EQ(pin_value[shutdownPin], HIGH); + EXPECT_EQ(pin_value[shutdownPin], LOW); #endif EXPECT_TRUE(getMp3() .called_sleep ); EXPECT_TRUE(getMFRC522().called_AntennaOff );