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

241 rings #127

Draft
wants to merge 8 commits into
base: mdev
Choose a base branch
from
Draft
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
186 changes: 186 additions & 0 deletions usermods/usermod_v2_241_rings/usermod_v2_241_rings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#pragma once

#include "wled.h"
//========================================================================================================================

static const char _data_FX_mode_Rings[] PROGMEM = "Rings - Rings@Speed,Jump,,,,Inward;;!,!;1;";
// static const char _data_FX_mode_SimpleRings[] PROGMEM = "Rings - Simple@Speed,Jump,,,,;;!,!;1;";
static const char _data_FX_mode_RandomFlow[] PROGMEM = "Rings - Random Flow@Speed;!;;1";
static const char _data_FX_mode_AudioRings[] PROGMEM = "Rings - AudioRings@Speed,,,,,Fade,Inward;;!;1f;pal=11,sx=255";

#define ringCount 9 // total Number of Rings
#define RINGS 9

//Map rings on disk to indicies.
//This is where all the magic happens.
//Each represents one of the concentric rings.
uint8_t ringMap[ringCount][2] = {
{0, 0}, //0 Center Point
{1, 8}, //1
{9, 20}, //2
{21, 36}, //3
{37, 60}, //4
{61, 92}, //5
{93, 132}, //6
{133, 180}, //7
{181, 240}, //8 Outer Ring
};

void setRing(int ring, CRGB colour) {
for (int i = ringMap[ring][0]; i <= ringMap[ring][1]; i++) {
SEGMENT.setPixelColor(i, colour);
}
}

void setRingFromFtt(int index, int ring) {
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t *fftResult = (uint8_t*)um_data->u_data[2];

uint8_t val = fftResult[map(index, 0, 6, 0, NUM_GEQ_CHANNELS)];
// Visualize leds to the beat
CRGB color = SEGMENT.color_from_palette(val, false, false, 0);
color.nscale8_video(val);
setRing(ring, color);
}


uint16_t mode_Rings() {

int JUMP = map(SEGMENT.intensity, 0, 255, 1,50); // TODO: set range
bool INWARD = SEGMENT.check1;

static uint8_t hue[RINGS];

if (SEGENV.call == 0) {
for (int r = 0; r < RINGS; r++) {
hue[r] = random(0, 255);
}
}

for (int r = 0; r < RINGS; r++) {
setRing(r, SEGMENT.color_from_palette(hue[r], false, false, 0));
}
delay(map(SEGMENT.speed, 0, 255, 200, 0)); // FIX
if (INWARD) {
for (int r = 0; r < RINGS; r++) {
hue[(r - 1)] = hue[r]; // set ring one less to that of the outer
}
hue[(RINGS - 1)] += JUMP;
}
else {
for (int r = (RINGS - 1); r >= 1; r--) {
hue[r] = hue[(r - 1)]; // set this ruing based on the inner
}
hue[0] += JUMP;
}
return FRAMETIME; // TODO
}

// uint16_t mode_SimpleRings() {
// int JUMP = map(SEGMENT.intensity, 0, 255, 1,50); // TODO: set range
// static uint8_t j;
// for (int r = 0; r < RINGS; r++) {
// setRing(r, SEGMENT.color_from_palette(j + (r * JUMP), false, false, 0));
// }
// j += JUMP;
// // FastLED.delay(SPEED);
// delay(map(SEGMENT.speed, 0, 255, 200, 0)); // FIX
// return FRAMETIME_FIXED_SLOW; // TODO
// }


uint16_t mode_RandomFlow() {
static int hue[RINGS];
hue[0] = random(0, 255);
for (int r = 0; r < RINGS; r++) {
setRing(r, CHSV(hue[r], 255, 255));
}
for (int r = (RINGS - 1); r >= 1; r--) {
hue[r] = hue[(r - 1)]; // set this ring based on the inner
}
delay(map(SEGMENT.speed, 0, 255, 200, 0)); // FIX
return FRAMETIME_FIXED_SLOW; // TODO
}


uint16_t mode_AudioRings() {

bool newReading = false; // TODO return FRAMETIME_FIXED_SLOW; // TODO

bool INWARD = SEGMENT.check2;

uint8_t secondHand = micros()/(256-SEGMENT.speed)/500+1 % 64;
if((SEGMENT.speed > 254) || (SEGENV.aux0 != secondHand)) { // WLEDMM allow run run at full speed
SEGENV.aux0 = secondHand;
newReading = true;
}

if(newReading) {
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t *fftResult = (uint8_t*)um_data->u_data[2];

for (int i = 0; i < 7; i++) {

uint8_t val;
if(INWARD) {
val = fftResult[(i*2)];
}
else {
int b = 14 -(i*2);
val = fftResult[b];
}

// Visualize leds to the beat
CRGB color = SEGMENT.color_from_palette(val, false, false, 0, val);
// CRGB color = ColorFromPalette(currentPalette, val, 255, currentBlending);
if(SEGMENT.check1) color.nscale8_video(val);
setRing(i, color);
// setRingFromFtt((i * 2), i);
}

setRingFromFtt(2, 7); // set outer ring to base
setRingFromFtt(0, 8); // set outer ring to base

}
return 0;
}


class Rings241Usermod : public Usermod {

public:

Rings241Usermod(const char *name, bool enabled):Usermod(name, enabled) {} //WLEDMM


void setup() {

if(!enabled) return;

strip.addEffect(250, &mode_Rings, _data_FX_mode_Rings);
// strip.addEffect(251, &mode_SimpleRings, _data_FX_mode_SimpleRings);
strip.addEffect(252, &mode_RandomFlow, _data_FX_mode_RandomFlow);
strip.addEffect(253, &mode_AudioRings, _data_FX_mode_AudioRings);

initDone = true;
}

void loop() {}

uint16_t getId()
{
return USERMOD_ID_241RINGS;
}

};



3 changes: 3 additions & 0 deletions wled00/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
#define USERMOD_ID_ANIMARTRIX 93 //Usermod "usermod_v2_animartrix.h"
#define USERMOD_ID_AUTOPLAYLIST 94 // Usermod usermod_v2_auto_playlist.h

#define USERMOD_ID_241RINGS 101 //Usermod "usermod_v2_241_rings.h"


//Access point behavior
#define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot
#define AP_BEHAVIOR_NO_CONN 1 //Open when no connection (either after boot or if connection is lost)
Expand Down
6 changes: 6 additions & 0 deletions wled00/usermods_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
#ifdef USERMOD_ANIMARTRIX
#include "../usermods/usermod_v2_animartrix/usermod_v2_animartrix.h"
#endif
#ifdef USERMOD_241RINGS
#include "../usermods/usermod_v2_241_rings/usermod_v2_241_rings.h"
#endif
#ifdef USERMOD_AUTO_PLAYLIST
#include "../usermods/usermod_v2_auto_playlist/usermod_v2_auto_playlist.h"
#endif
Expand Down Expand Up @@ -404,6 +407,9 @@ void registerUsermods()
#ifdef USERMOD_ANIMARTRIX
usermods.add(new AnimartrixUsermod("Animartrix", false));
#endif
#ifdef USERMOD_241RINGS
usermods.add(new Rings241Usermod("241Rings", true));
#endif

#ifdef USERMOD_AUTO_PLAYLIST
usermods.add(new AutoPlaylistUsermod(false));
Expand Down