Skip to content

Commit

Permalink
Reorganise files and folders, move classes to files, globals to classes
Browse files Browse the repository at this point in the history
New files/classes:

AppLedsV: 
- class static: width, height, depth, nrOfLedsP, nrOfLedsV

AppEffects
- global: gHue and call

AppModLeds
- class static: fps

SysJsonRDWS

AppModLedFixGen

SysModPinManager rename to SysModPins
  • Loading branch information
ewoudwijma committed Jul 29, 2023
1 parent d023d8d commit 118388b
Show file tree
Hide file tree
Showing 29 changed files with 1,034 additions and 896 deletions.
145 changes: 31 additions & 114 deletions src/AppModLeds.h → src/App/AppEffects.h
Original file line number Diff line number Diff line change
@@ -1,82 +1,15 @@
#pragma once
#include "Module.h"

#include <vector>
#include "FastLED.h"

#define DATA_PIN 16
#define NUM_LEDS_FastLed 1024
#define NUM_LEDS_Preview 2000

//https://github.com/FastLED/FastLED/blob/master/examples/DemoReel100/DemoReel100.ino
//https://blog.ja-ke.tech/2019/06/02/neopixel-performance.html

class LedsV {

public:
// CRGB *leds = nullptr;
CRGB ledsP[NUM_LEDS_Preview];

std::vector<std::vector<uint16_t>> mappingTable;
uint16_t mappingTableLedCounter = 0;

void ledFixProjectAndMap(JsonObject ledFixObject, JsonObject projectionObject);

uint16_t indexVLocal = 0;

// ledsV[indexV] stores indexV locally
LedsV& operator[](uint16_t indexV);

// CRGB& operator[](uint16_t indexV) {
// // indexVLocal = indexV;
// CRGB x = getPixelColor(indexV);
// return x;
// }

// ledsV = uses locally stored indexV and color to call setPixelColor
LedsV& operator=(const CRGB color);

// maps the virtual led to the physical led(s) and assign a color to it
void setPixelColor(int indexV, CRGB color);

CRGB getPixelColor(int indexV);

// LedsV& operator+=(const CRGB color) {
// setPixelColor(indexVLocal, getPixelColor(indexVLocal) + color);
// return *this;
// }
// LedsV& operator|=(const CRGB color) {
// // setPixelColor(indexVLocal, color);
// setPixelColor(indexVLocal, getPixelColor(indexVLocal) | color);
// return *this;
// }

// LedsV& operator+(const CRGB color) {
// setPixelColor(indexVLocal, getPixelColor(indexVLocal) + color);
// return *this;
// }

};

//after header split they all needs to be static otherwise multiple definition link error
static LedsV ledsV = LedsV(); //virtual leds
static CRGB *ledsP = ledsV.ledsP; //physical leds, used by FastLed in particular

static float distance(uint16_t x1, uint16_t y1, uint16_t z1, uint16_t x2, uint16_t y2, uint16_t z2) {
return sqrtf((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
}

static uint16_t nrOfLedsP = 64; //amount of physical leds
static uint16_t nrOfLedsV = 64; //amount of virtual leds (calculated by projection)
/*
@title StarMod
@file AppEffects.h
@date 20230729
@repo https://github.com/ewoudwijma/StarMod
@Authors https://github.com/ewoudwijma/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
@license GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
*/

static uint8_t gHue = 0; // rotating "base color" used by many of the patterns
static uint16_t width = 8;
static uint16_t height = 8;
static uint16_t depth = 1;
static uint16_t fps = 40;
static unsigned long call = 0;
static uint8_t bri = 10;


//should not contain bytes to keep mem as small as possible
class Effect {
Expand All @@ -95,7 +28,7 @@ class RainbowEffect:public Effect {
void setup() {} //not implemented yet
void loop() {
// FastLED's built-in rainbow generator
fill_rainbow( ledsP, nrOfLedsP, gHue, 7);
fill_rainbow( ledsP, ledsV.nrOfLedsP, gHue, 7);
}
};

Expand All @@ -113,7 +46,7 @@ class RainbowWithGlitterEffect:public RainbowEffect {
static void addGlitter( fract8 chanceOfGlitter)
{
if( random8() < chanceOfGlitter) {
ledsP[ random16(nrOfLedsP) ] += CRGB::White;
ledsP[ random16(ledsV.nrOfLedsP) ] += CRGB::White;
}
}
};
Expand All @@ -126,8 +59,8 @@ class SinelonEffect:public Effect {
void setup() {} //not implemented yet
void loop() {
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( ledsP, nrOfLedsP, 20);
int pos = beatsin16( 13, 0, nrOfLedsV-1 );
fadeToBlackBy( ledsP, ledsV.nrOfLedsP, 20);
int pos = beatsin16( 13, 0, ledsV.nrOfLedsV-1 );
// ledsV[pos] += CHSV( gHue, 255, 192);
ledsV[pos] = ledsV.getPixelColor(pos) + CHSV( gHue, 255, 192);
// CRGB x = ledsV[pos];
Expand All @@ -142,10 +75,10 @@ class RunningEffect:public Effect {
void setup() {} //not implemented yet
void loop() {
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( ledsP, nrOfLedsP, 70); //physical leds
// int pos0 = (call-1)%nrOfLeds;
fadeToBlackBy( ledsP, ledsV.nrOfLedsP, 70); //physical leds
// int pos0 = (call-1)%ledsV.nrOfLeds;
// leds[pos0] = CHSV( 0,0,0);
int pos = call%nrOfLedsV; //Virtual leds
int pos = call%ledsV.nrOfLedsV; //Virtual leds
ledsV[pos] = CHSV( gHue, 255, 192); //make sore the right physical leds get their value
}
};
Expand All @@ -158,8 +91,8 @@ class ConfettiEffect:public Effect {
void setup() {} //not implemented yet
void loop() {
// random colored speckles that blink in and fade smoothly
fadeToBlackBy( ledsP, nrOfLedsP, 10);
int pos = random16(nrOfLedsP);
fadeToBlackBy( ledsP, ledsV.nrOfLedsP, 10);
int pos = random16(ledsV.nrOfLedsP);
ledsP[pos] += CHSV( gHue + random8(64), 200, 255);
}
};
Expand All @@ -175,7 +108,7 @@ class BPMEffect:public Effect {
uint8_t BeatsPerMinute = 62;
CRGBPalette16 palette = PartyColors_p;
uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
for( int i = 0; i < nrOfLedsV; i++) { //9948
for( int i = 0; i < ledsV.nrOfLedsV; i++) { //9948
ledsV[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
}
}
Expand All @@ -192,10 +125,10 @@ class JuggleEffect:public Effect {
void setup() {} //not implemented yet
void loop() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( ledsP, nrOfLedsP, 20);
fadeToBlackBy( ledsP, ledsV.nrOfLedsP, 20);
uint8_t dothue = 0;
for( int i = 0; i < 8; i++) {
ledsP[beatsin16( i+7, 0, nrOfLedsP-1 )] |= CHSV(dothue, 200, 255);
ledsP[beatsin16( i+7, 0, ledsV.nrOfLedsP-1 )] |= CHSV(dothue, 200, 255);
dothue += 32;
}
}
Expand All @@ -210,12 +143,12 @@ class Ripples3DEffect:public Effect {
void loop() {
float ripple_interval = 1.3;// * (SEGMENT.intensity/128.0);

fill_solid(ledsP, nrOfLedsP, CRGB::Black);
fill_solid(ledsP, ledsV.nrOfLedsP, CRGB::Black);
// fill(CRGB::Black);

uint16_t mW = width;
uint16_t mH = height;
uint16_t mD = depth;
uint16_t mW = ledsV.width;
uint16_t mH = ledsV.height;
uint16_t mD = ledsV.depth;

for (int z=0; z<mD; z++) {
for (int x=0; x<mW; x++) {
Expand All @@ -238,14 +171,14 @@ class SphereMove3DEffect:public Effect {
uint16_t origin_x, origin_y, origin_z, d;
float diameter;

fill_solid(ledsP, nrOfLedsP, CRGB::Black);
fill_solid(ledsP, ledsV.nrOfLedsP, CRGB::Black);
// fill(CRGB::Black);

uint32_t interval = call/((256.0-128.0)/20.0);

uint16_t mW = width;
uint16_t mH = height;
uint16_t mD = depth;
uint16_t mW = ledsV.width;
uint16_t mH = ledsV.height;
uint16_t mD = ledsV.depth;

origin_x = 3.5+sinf(interval)*2.5;
origin_y = 3.5+cosf(interval)*2.5;
Expand All @@ -260,28 +193,12 @@ class SphereMove3DEffect:public Effect {
d = distance(x, y, z, origin_x, origin_y, origin_z);

if (d>diameter && d<diameter+1) {
ledsV[x + height * mW + z * mW * mH] = CHSV( gHue + random8(64), 200, 255);// ColorFromPalette(pal,call, bri, LINEARBLEND);
ledsV[x + ledsV.height * mW + z * mW * mH] = CHSV( gHue + random8(64), 200, 255);// ColorFromPalette(pal,call, bri, LINEARBLEND);
}
}
}
}
}
}; // 3DSphereMove

static std::vector<Effect *> effects;

class AppModLeds:public Module {

public:
uint8_t dataPin = 16;
unsigned long frameMillis = 0;
unsigned long frameCounter = 0;

AppModLeds();

void setup();

void loop();
};

static AppModLeds *lds;
static std::vector<Effect *> effects;
Loading

0 comments on commit 118388b

Please sign in to comment.