Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 141: Enhance Features for Neo Pixel Ring #144

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Die SD Karte (Ordner mp3 und advert) hat sich gegenüber der Version 3.1.2 geän

# Change Log

## Version 3.1.5 (04.12.2023)
- [Issue 141](https://github.com/tonuino/TonUINO-TNG/issues/141): Enhance Features for Neo Pixel Ring

## Version 3.1.5 (21.11.2023)
- [Issue 132](https://github.com/tonuino/TonUINO-TNG/issues/132): Support DF Player MP3-TF-16P V3.0 with the chip MH2024K-24SS

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.5 21.11.23\n"));
LOG(init_log, s_error, F("V3.1.5 04.12.23\n"));

Tonuino::getTonuino().setup();
}
Expand Down
27 changes: 23 additions & 4 deletions src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,39 @@
* um den Drehgeber zu unterstützen bitte in der nächste Zeile den Kommentar entfernen (nur für AioPlus)
*/
//#define ROTARY_ENCODER
inline constexpr uint8_t rotaryEncoderClkPin = 31;
inline constexpr uint8_t rotaryEncoderDtPin = 32;
#ifdef ALLinONE_Plus
// if using Rotary Encoder Buchse
//inline constexpr uint8_t rotaryEncoderClkPin = 31; // PE2
//inline constexpr uint8_t rotaryEncoderDtPin = 32; // PE3

// if using Opt Leiste (Male)
inline constexpr uint8_t rotaryEncoderClkPin = 36; // PF2
inline constexpr uint8_t rotaryEncoderDtPin = 37; // PF3
#endif // ALLinONE_Plus


/* uncomment the below line to enable the poti for volume setting
* um den Poti zu unterstützen bitte in der nächste Zeile den Kommentar entfernen
*/
//#define POTI
//inline constexpr uint8_t potiPin = A14; // AiO+ PF4
#ifdef ALLinONE_Plus
inline constexpr uint8_t potiPin = A14; // AiO+ PF4
#else
inline constexpr uint8_t potiPin = A5 ; // AiO/Classic A5
#endif // ALLinONE_Plus

/* uncomment the below line to enable the neo ring
* To have more features (show volume setting) uncomment also NEO_RING_EXT
* um den Neo Ring zu unterstützen bitte in der nächste Zeile den Kommentar entfernen
* um weitere Features einzuschalten, auch den Kommentar für NEO_RING_EXT entfernen
*/
//#define NEO_RING
inline constexpr uint8_t neoPixelRingPin = 10; // PB2 on AiOplus
//#define NEO_RING_EXT
#ifdef ALLinONE_Plus
inline constexpr uint8_t neoPixelRingPin = 10; // PB2 on AiOplus (Erweiterungsleiste (Female))
#else
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
Expand Down
2 changes: 1 addition & 1 deletion src/modifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void SleepTimer::loop() {
LOG(modifier_log, s_info, str_SleepTimer(), F(" -> SLEEP!"));
if (SM_tonuino::is_in_state<Play>())
SM_tonuino::dispatch(command_e(commandRaw::pause));
tonuino.resetActiveModifier();
//tonuino.resetActiveModifier();
}
}

Expand Down
26 changes: 17 additions & 9 deletions src/mp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void Mp3::waitForTrackToStart() {
} while (!isPlaying() && millis() < currentTime + maxStartTime);
}

void Mp3::playAdvertisement(uint16_t track, bool olnyIfIsPlaying) {
void Mp3::playAdvertisement(uint16_t track, bool /*olnyIfIsPlaying*/) {
LOG(mp3_log, s_info, F("play adv: "), track);
#ifdef DFMiniMp3_T_CHIP_LISP3
advPlaying = true;
Expand All @@ -89,14 +89,16 @@ void Mp3::playAdvertisement(uint16_t track, bool olnyIfIsPlaying) {
LOG(mp3_log, s_debug, F("playAdvertisement: "), track);
Base::playAdvertisement(track);
}
else if (not olnyIfIsPlaying) {
start();
loop();
LOG(mp3_log, s_debug, F("playAdvertisement: "), track);
Base::playAdvertisement(track);
waitForTrackToFinish(); // TODO remove waitForTrackToFinish
pause();
}
// the following doesn't work
// else if (not olnyIfIsPlaying) {
// if (isPause)
// start();
// loop();
// LOG(mp3_log, s_debug, F("playAdvertisement: "), track);
// Base::playAdvertisement(track);
// waitForTrackToFinish(); // TODO remove waitForTrackToFinish
// pause();
// }
}

void Mp3::playAdvertisement(advertTracks track, bool olnyIfIsPlaying) {
Expand Down Expand Up @@ -244,6 +246,9 @@ void Mp3::increaseVolume() {
LOG(mp3_log, s_debug, F("setVolume: "), volume+1);
Base::setVolume(++volume);
}
#ifdef NEO_RING_EXT
volumeChangedTimer.start(1000);
#endif // NEO_RING_EXT
logVolume();
}

Expand All @@ -252,6 +257,9 @@ void Mp3::decreaseVolume() {
LOG(mp3_log, s_debug, F("setVolume: "), volume-1);
Base::setVolume(--volume);
}
#ifdef NEO_RING_EXT
volumeChangedTimer.start(1000);
#endif // NEO_RING_EXT
logVolume();
}

Expand Down
8 changes: 7 additions & 1 deletion src/mp3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ class Mp3: public DfMp3 {
void decreaseVolume();
void setVolume ();
void setVolume (uint8_t);
uint8_t getVolume () const { return volume; }
#ifdef NEO_RING_EXT
uint8_t getVolumeRel() const { return static_cast<uint16_t>(volume-settings.minVolume)*0xff/(settings.maxVolume-settings.minVolume); }
bool volumeChanged () { return not volumeChangedTimer.isExpired(); }
#endif // NEO_RING_EXT
void loop ();

private:
Expand All @@ -214,6 +217,9 @@ class Mp3: public DfMp3 {
const Settings& settings;

uint8_t volume{};
#ifdef NEO_RING_EXT
Timer volumeChangedTimer{};
#endif // NEO_RING_EXT

// folder queue
track_queue q{};
Expand Down
8 changes: 8 additions & 0 deletions src/ring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ void Ring::setAll(const color_t color) {
showStrip();
}

void Ring::level(uint8_t l) {
const uint8_t last = static_cast<uint16_t>(l) * neoPixelNumber / 0xff;
setAll([last, this](uint8_t i) {
return (i <= last) ? wheel(static_cast<uint16_t>(i)*100/neoPixelNumber) : black;}
);
}


// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
Ring::color_t Ring::wheel(byte WheelPos) const {
Expand Down
6 changes: 6 additions & 0 deletions src/ring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Ring {
static constexpr color_t green { 0, 255, 0 };
static constexpr color_t blue { 0, 0, 255 };
static constexpr color_t black { 0, 0, 0 };
static constexpr color_t orange{ 192, 64, 0 };

void call_on_startup () { setAll (red ); }
void call_on_idle () { pulse (green); }
Expand All @@ -41,6 +42,10 @@ class Ring {
void call_on_pause () { rainbow (0 ); }
void call_on_admin () { pulse (blue ); }
void call_on_sleep () { setAll (black); }
void call_on_volume(uint8_t v)
{ level (v ); }
void call_on_sleep_timer() { static uint8_t c = 0; if (++c%4==0) setAll (orange*random(100,255)); }
void call_before_sleep(uint8_t r) { setAll (orange*r); }

void brightness_up () { if (brightness < brightness_max) ++brightness; strip.setBrightness(brightness); }
void brightness_down () { if (brightness > 0 ) --brightness; strip.setBrightness(brightness); }
Expand All @@ -55,6 +60,7 @@ class Ring {
void rainbow(uint8_t incr);
void setAll(const color_t color);
void setAll(auto&& f);
void level(uint8_t l);

uint8_t brightness { brightness_init };

Expand Down
7 changes: 7 additions & 0 deletions src/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ bool Timer::isExpired() {
void Timer::stop() {
active = false;
}

unsigned long Timer::remainingTime() {
if (not active)
return 0xffffffff;
return expireTime - millis();
}

1 change: 1 addition & 0 deletions src/timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Timer {
bool isExpired();
void stop();
bool isActive() { return active; }
unsigned long remainingTime();
private:
unsigned long expireTime{0 };
bool active {false};
Expand Down
11 changes: 10 additions & 1 deletion src/tonuino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ void Tonuino::loop() {
SM_tonuino::dispatch(card_e(chip_card.getCardEvent()));

#ifdef NEO_RING
#ifdef NEO_RING_EXT
if (mp3.volumeChanged())
ring.call_on_volume(mp3.getVolumeRel());
else if (standbyTimer.remainingTime() < 60*1000ul)
ring.call_before_sleep(standbyTimer.remainingTime() / 1000 * 255 / 60);
else if (activeModifier->getActive() == pmode_t::sleep_timer)
ring.call_on_sleep_timer();
else
#endif // NEO_RING_EXT
if (SM_tonuino::is_in_state<Idle>())
ring.call_on_idle();
else if (SM_tonuino::is_in_state<StartPlay>())
Expand All @@ -100,7 +109,7 @@ void Tonuino::loop() {
ring.call_on_pause();
else // admin menu
ring.call_on_admin();
#endif
#endif // NEO_RING

unsigned long stop_cycle = millis();

Expand Down
16 changes: 16 additions & 0 deletions test/libs/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ inline void delay(unsigned long ms) { current_time += ms; }
#define PIN_A6 (20)
#define PIN_A7 (21)

#define PIN_A8 (22)
#define PIN_A9 (23)
#define PIN_A10 (24)
#define PIN_A11 (25)
#define PIN_A12 (26)
#define PIN_A13 (27)
#define PIN_A14 (28)

static const uint8_t A0 = PIN_A0;
static const uint8_t A1 = PIN_A1;
static const uint8_t A2 = PIN_A2;
Expand All @@ -70,6 +78,14 @@ static const uint8_t A5 = PIN_A5;
static const uint8_t A6 = PIN_A6;
static const uint8_t A7 = PIN_A7;

static const uint8_t A8 = PIN_A8;
static const uint8_t A9 = PIN_A9;
static const uint8_t A10 = PIN_A10;
static const uint8_t A11 = PIN_A11;
static const uint8_t A12 = PIN_A12;
static const uint8_t A13 = PIN_A13;
static const uint8_t A14 = PIN_A14;

static const uint8_t max_pin = 32;

extern uint8_t pin_mode[max_pin];
Expand Down