Skip to content

Commit

Permalink
Merge pull request #191: Issue_190: Neo Pixel Ring: Add the possibili…
Browse files Browse the repository at this point in the history
…ty to have 2 rings
  • Loading branch information
boerge1 authored Apr 13, 2024
2 parents d22d815 + 8a3a790 commit 357c8bc
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 21 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 (07.04.2024)
## Version 3.1.7 (08.04.2024)
- [Issue 190](https://github.com/tonuino/TonUINO-TNG/issues/190): Neo Pixel Ring: Add the possibility to have 2 rings remains
- [Issue 188](https://github.com/tonuino/TonUINO-TNG/issues/188): Pause when card removed modus: do not go to Play via button if card is not present

## Version 3.1.7 (29.03.2024)
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 07.04.24\n"));
LOG(init_log, s_error, F("V3.1.7 08.04.24\n"));

Tonuino::getTonuino().setup();
}
Expand Down
15 changes: 15 additions & 0 deletions src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@

/* uncomment one of the below lines to support a special chip on the DfMiniMp3 player
* um einen speziellen Chip auf dem DfMiniMp3 Player zu ünterstützen bitte in eine der nächste Zeilen den Kommentar entfernen
*
* GD3200B: bad behavior of getFolderTrackCount() - ignores the parameter folder
* MH2024K16SS: no checksums
* LISP3: bad behavior of callback OnPlayFinished - it is also called on advertise tracks (also on some MH2024K24SS)
* LKP Player: no ACK for requests (use Mp3ChipIncongruousNoAck for them)
*/
//#define DFMiniMp3_T_CHIP_GD3200B
//#define DFMiniMp3_T_CHIP_MH2024K16SS
Expand Down Expand Up @@ -162,12 +167,22 @@ inline constexpr uint8_t potiPin = A3 ; // AiO/Classic A3
*/
//#define NEO_RING
//#define NEO_RING_EXT
//#define NEO_RING_2

#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
#ifdef NEO_RING_2
#ifdef ALLinONE_Plus
inline constexpr uint8_t neoPixelRingPin2= 14; // PC0 on AiOplus (Erweiterungsleiste (Female))
#else
inline constexpr uint8_t neoPixelRingPin2= 2; // D2 on AiO/Classic (only Every)
#endif // ALLinONE_Plus
inline constexpr uint8_t neoPixelNumber2 = 24; // Total Number of Pixels
#endif // NEO_RING_2

// ######################################################################

Expand Down
27 changes: 17 additions & 10 deletions src/ring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,45 @@

#include <limits.h>

Ring::Ring()
: strip(neoPixelNumber, neoPixelRingPin, NEO_GRB + NEO_KHZ800)
{}
OneRing::OneRing(uint8_t pin, direction dir)
: brightness_pulse{(dir==direction::cw) ? brightness_pulse_min : brightness_pulse_max}
, dir{dir}
, strip{neoPixelNumber, pin, NEO_GRB + NEO_KHZ800}
{
if (dir==direction::ccw) {
brightness_pulse = brightness_pulse_max;
brightness_inc *= -1;
}
}

void Ring::init() {
void OneRing::init() {
strip.begin();
strip.setBrightness(brightness);
}

void Ring::pulse(const color_t color) {
void OneRing::pulse(const color_t color) {
brightness_pulse += brightness_inc;
if (brightness_pulse >= 200 or brightness_pulse <= 50)
if (brightness_pulse >= brightness_pulse_max or brightness_pulse <= brightness_pulse_min)
brightness_inc *= -1;

setAll(color*brightness_pulse);
}

// Rainbow cycle along whole strip.
void Ring::rainbow(uint8_t incr){
void OneRing::rainbow(uint8_t incr){
setAll([this](uint8_t i){ return wheel((255/neoPixelNumber * (neoPixelNumber-1-i) + pixelCycle) & 255); });

pixelCycle += incr;
}

void Ring::setAll(const color_t color) {
void OneRing::setAll(const color_t color) {
for (uint8_t i = 0; i < neoPixelNumber; i++) {
setPixel(i, color);
}
showStrip();
}

void Ring::level(uint8_t l) {
void OneRing::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;}
Expand All @@ -45,7 +52,7 @@ void Ring::level(uint8_t l) {

// 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 {
OneRing::color_t OneRing::wheel(byte WheelPos) const {
color_t color;
if (WheelPos == 255) WheelPos = 254;
const uint16_t WheelPos_times_3 = (WheelPos % 85) * 3;
Expand Down
59 changes: 51 additions & 8 deletions src/ring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
#include <Adafruit_NeoPixel.h>

inline constexpr uint8_t pulse_per_second = 1;
inline constexpr uint8_t brightness_pulse_max = 200;
inline constexpr uint8_t brightness_pulse_min = 50;

inline constexpr uint8_t brightness_max = 32;
inline constexpr uint8_t brightness_init = 16;

class Ring {
enum class direction: uint8_t {
cw,
ccw,
};

class OneRing {
public:
Ring();
OneRing(uint8_t pin = neoPixelRingPin, direction dir = direction::cw);

void init();

Expand All @@ -39,7 +47,7 @@ class Ring {
void call_on_idle () { pulse (green); }
void call_on_startPlay() { pulse (red ); }
void call_on_play () { rainbow (5 ); }
void call_on_quiz () { rainbow (10 ); }
void call_on_game () { rainbow (10 ); }
void call_on_pause () { rainbow (0 ); }
void call_on_admin () { pulse (blue ); }
void call_on_sleep () { setAll (black); }
Expand All @@ -66,19 +74,54 @@ class Ring {
uint8_t brightness { brightness_init };

// for pulse()
uint8_t brightness_pulse { 50 };
int8_t brightness_inc { cycleTime*255/pulse_per_second/1000 };

uint8_t brightness_pulse{ brightness_pulse_min };
int8_t brightness_inc { cycleTime*255/pulse_per_second/1000 };

// for rainbow()
uint8_t pixelCycle { 0 }; // Pattern Pixel Cycle

direction dir;

Adafruit_NeoPixel strip;
};

void Ring::setAll(auto&& f) {
#ifdef NEO_RING_2
class TwoRings {
public:
TwoRings()
: ring1(neoPixelRingPin)
, ring2(neoPixelRingPin2, direction::ccw)
{}

void init () { ring1.init ( ); ring2.init ( ); }

void call_on_startup () { ring1.call_on_startup ( ); ring2.call_on_startup ( ); }
void call_on_idle () { ring1.call_on_idle ( ); ring2.call_on_idle ( ); }
void call_on_startPlay () { ring1.call_on_startPlay ( ); ring2.call_on_startPlay ( ); }
void call_on_play () { ring1.call_on_play ( ); ring2.call_on_play ( ); }
void call_on_game () { ring1.call_on_game ( ); ring2.call_on_game ( ); }
void call_on_pause () { ring1.call_on_pause ( ); ring2.call_on_pause ( ); }
void call_on_admin () { ring1.call_on_admin ( ); ring2.call_on_admin ( ); }
void call_on_sleep () { ring1.call_on_sleep ( ); ring2.call_on_sleep ( ); }
void call_on_volume(uint8_t v) { ring1.call_on_volume (v); ring2.call_on_volume (v); }
void call_on_sleep_timer () { ring1.call_on_sleep_timer( ); ring2.call_on_sleep_timer( ); }
void call_before_sleep(uint8_t r) { ring1.call_before_sleep (r); ring2.call_before_sleep (r); }
void brightness_up () { ring1.brightness_up ( ); ring2.brightness_up ( ); }
void brightness_down () { ring1.brightness_down ( ); ring2.brightness_down ( ); }

private:
OneRing ring1;
OneRing ring2;
};
using Ring = TwoRings;
#else
using Ring = OneRing;
#endif // NEO_RING_2

void OneRing::setAll(auto&& f) {
for (uint8_t i = 0; i < neoPixelNumber; ++i) {
setPixel(i, f(i));
uint8_t fi = (dir == direction::cw) ? i : neoPixelNumber - i - 1;
setPixel(i, f(fi));
}
showStrip();
}
Expand Down
6 changes: 5 additions & 1 deletion src/tonuino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ void Tonuino::loop() {
ring.call_on_pause();
#ifdef QUIZ_GAME
else if (SM_tonuino::is_in_state<Quiz>())
ring.call_on_quiz();
ring.call_on_game();
#endif // QUIZ_GAME
#ifdef MEMORY_GAME
else if (SM_tonuino::is_in_state<Memory>())
ring.call_on_game();
#endif // MEMORY_GAME
else // admin menu
ring.call_on_admin();
#endif // NEO_RING
Expand Down

0 comments on commit 357c8bc

Please sign in to comment.