Skip to content

Commit

Permalink
Issue_178: Use Nano Every optional with HW Serial connection to the
Browse files Browse the repository at this point in the history
DfPlayer
  • Loading branch information
boerge1 committed Mar 9, 2024
1 parent aae924e commit 2fd5977
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.6 18.02.24\n"));
LOG(init_log, s_error, F("V3.1.6 09.03.24\n"));

Tonuino::getTonuino().setup();
}
Expand Down
26 changes: 16 additions & 10 deletions src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -211,19 +216,22 @@ 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;

// ####### 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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/mp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
9 changes: 4 additions & 5 deletions src/mp3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SoftwareSerial.h>
using SerialType = SoftwareSerial;
#endif // DFPlayerUsesSoftwareSerial
#ifdef DFPlayerUsesHardwareSerial
#else
using SerialType = HardwareSerial;
#endif // DFPlayerUsesHardwareSerial

Expand Down Expand Up @@ -227,9 +226,9 @@ class Mp3: public DfMp3 {

typedef queue<uint8_t, maxTracksInFolder> track_queue;

#ifdef DFPlayerUsesSoftwareSerial
#ifndef DFPlayerUsesHardwareSerial
SoftwareSerial softwareSerial;
#endif /* DFPlayerUsesSoftwareSerial */
#endif /* not DFPlayerUsesHardwareSerial */
const Settings& settings;

uint8_t volume{};
Expand Down
6 changes: 3 additions & 3 deletions test/src/tonuino_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 2fd5977

Please sign in to comment.