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

Test of RGBW Branch #660

Merged
merged 9 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
14 changes: 5 additions & 9 deletions config/partitions_custom.csv
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# ESP-IDF Partition Table
# This gives us some additional space for code.
# It should also fix the OTA regression.
# Name, Type, SubType, Offset, Size, Flags

# Note that our NVS code assumes name 'storage' for the NVS partition
# Standard 4M partition layout with OTA (Over the air updates)

# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x00b000, 0x002000,
otadata, data, ota, 0x00d000, 0x002000,
app0, app, ota_0, 0x010000, 0x190000,
app1, app, ota_1, 0x1A0000, 0x190000,
storage, data, spiffs, 0x330000, 0x0D0000
app0, app, ota_0, 0x010000, 0x1A0000,
app1, app, ota_1, 0x1B0000, 0x1A0000,
storage, data, spiffs, 0x350000, 0x0B0000
rbergen marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion include/deviceconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@

#define DEVICE_CONFIG_FILE "/device.cfg"
#define NTP_SERVER_DEFAULT "0.pool.ntp.org"
#define BRIGHTNESS_MIN uint8_t(10)
#ifndef BRIGHTNESS_MIN
#define BRIGHTNESS_MIN uint8_t(10)
#endif
#define BRIGHTNESS_MAX uint8_t(255)
rbergen marked this conversation as resolved.
Show resolved Hide resolved
#define POWER_LIMIT_MIN 1000
#define POWER_LIMIT_DEFAULT 4500
Expand Down
14 changes: 12 additions & 2 deletions include/effectmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,19 @@ class EffectManager : public IJSONSerializable
ClearEffects();
}

std::shared_ptr<GFXBase> GetBaseGraphics()
// SetTempEffect - Sets a temporary effect to be played until remote changes it.
// The effect must have already had its Init() function called.

void SetTempEffect(std::shared_ptr<LEDStripEffect> effect)
{
_tempEffect = effect;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could swear this functionality existed for the atomic lamp already, but could not find a way to actually set the temp effect, so added this method. Let me know if I missed something that would have obviated the need for it!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can remember, the _tempEffect could only be set through the constructor the whole time. But there is a theoretical chance that the possibility did exist a long time ago, and I removed it because the function wasn't used anywhere - I have done some dead code clean-up over time.

// GetBaseGraphics - Returns the vector of GFXBase objects that the effects use to draw

std::vector<std::shared_ptr<GFXBase>> & GetBaseGraphics()
{
return _gfx[0];
return _gfx;
}
rbergen marked this conversation as resolved.
Show resolved Hide resolved

bool IsNewFrameAvailable() const
Expand Down
4 changes: 4 additions & 0 deletions include/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
#define EFFECT_STRIP_FAN_BEAT 37
#define EFFECT_STRIP_SPLASH_LOGO 38
#define EFFECT_STRIP_VUMETER 39
#define EFFECT_STRIP_VUMETER_VERTICAL 40

// Matrix effects
#define EFFECT_MATRIX_ALIEN_TEXT 101
Expand Down Expand Up @@ -147,6 +148,7 @@
#define EFFECT_MATRIX_STOCKS 159
#define EFFECT_MATRIX_SILON 160
#define EFFECT_MATRIX_PDPGRID 161
#define EFFECT_MATRIX_AUDIOSPIKE 162

// Hexagon Effects
#define EFFECT_HEXAGON_OUTER_RING 201
Expand Down Expand Up @@ -183,6 +185,7 @@
#define PTY_SPARKS "spc"
#define PTY_SPARKING "spg"
#define PTY_SPARKHEIGHT "sph"
#define PTY_SPARKTEMP "spt"
#define PTY_COOLING "clg"
#define PTY_PALETTE "plt"
#define PTY_ORDER "ord"
Expand All @@ -194,6 +197,7 @@
#define PTY_MAXSPEED "mxs"
#define PTY_SPEEDDIVISOR "sdd"
#define PTY_DELTAHUE "dth"
#define PTY_MIRRORED "mrd"
#define PTY_EVERYNTH "ent"
#define PTY_COLOR "clr"
#define PTY_BLEND "bld"
Expand Down
165 changes: 150 additions & 15 deletions include/effects/matrix/spectrumeffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ class VUMeter
//
// Draw i-th pixel in row y

void DrawVUPixels(std::shared_ptr<GFXBase> pGFXChannel, int i, int yVU, int fadeBy = 0, const CRGBPalette16 * pPalette = nullptr)
virtual void DrawVUPixels(std::vector<std::shared_ptr<GFXBase>> & GFX, int i, int yVU, int fadeBy = 0, const CRGBPalette16 * pPalette = nullptr)
{
if (g_Analyzer.MicMode() == PeakData::PCREMOTE)
pPalette = &vuPaletteBlue;

int xHalf = pGFXChannel->width()/2;
pGFXChannel->setPixel(xHalf-i-1, yVU, ColorFromPalette(pPalette ? *pPalette : vu_gpGreen, i*(256/xHalf)).fadeToBlackBy(fadeBy));
pGFXChannel->setPixel(xHalf+i, yVU, ColorFromPalette(pPalette ? *pPalette : vu_gpGreen, i*(256/xHalf)).fadeToBlackBy(fadeBy));
int xHalf = GFX[0]->width()/2;
GFX[0]->setPixel(xHalf-i-1, yVU, ColorFromPalette(pPalette ? *pPalette : vu_gpGreen, i*(256/xHalf)).fadeToBlackBy(fadeBy));
GFX[0]->setPixel(xHalf+i, yVU, ColorFromPalette(pPalette ? *pPalette : vu_gpGreen, i*(256/xHalf)).fadeToBlackBy(fadeBy));
rbergen marked this conversation as resolved.
Show resolved Hide resolved
}


Expand All @@ -140,25 +140,25 @@ class VUMeter

public:

inline void EraseVUMeter(std::shared_ptr<GFXBase> pGFXChannel, int start, int yVU) const
virtual inline void EraseVUMeter(std::vector<std::shared_ptr<GFXBase>> & GFX, int start, int yVU) const
{
int xHalf = pGFXChannel->width()/2;
int xHalf = GFX[0]->width()/2;
for (int i = start; i <= xHalf; i++)
{
pGFXChannel->setPixel(xHalf-i, yVU, CRGB::Black);
pGFXChannel->setPixel(xHalf-1+i, yVU, CRGB::Black);
GFX[0]->setPixel(xHalf-i, yVU, CRGB::Black);
GFX[0]->setPixel(xHalf-1+i, yVU, CRGB::Black);
}
}

void DrawVUMeter(std::shared_ptr<GFXBase> pGFXChannel, int yVU, const CRGBPalette16 * pPalette = nullptr)
virtual void DrawVUMeter(std::vector<std::shared_ptr<GFXBase>> & GFX, int yVU = 0, const CRGBPalette16 * pPalette = nullptr)
{
const int MAX_FADE = 256;

int xHalf = pGFXChannel->width()/2-1;
int xHalf = GFX[0]->width()/2-1;
int bars = g_Analyzer._VURatioFade / 2.0 * xHalf;
bars = min(bars, xHalf);

EraseVUMeter(pGFXChannel, bars, yVU);
EraseVUMeter(GFX, bars, yVU);

if (bars >= iPeakVUy)
{
Expand All @@ -173,21 +173,74 @@ class VUMeter
if (iPeakVUy > 1)
{
int fade = MAX_FADE * (millis() - msPeakVU) / (float) MS_PER_SECOND * 2;
DrawVUPixels(pGFXChannel, iPeakVUy, yVU, fade);
DrawVUPixels(pGFXChannel, iPeakVUy-1, yVU, fade);
DrawVUPixels(GFX, iPeakVUy, yVU, fade);
DrawVUPixels(GFX, iPeakVUy-1, yVU, fade);
}

for (int i = 0; i < bars; i++)
DrawVUPixels(pGFXChannel, i, yVU, i > bars ? 255 : 0, pPalette);
DrawVUPixels(GFX, i, yVU, i > bars ? 255 : 0, pPalette);
}
};

class VUMeterVertical : public VUMeter
{
private:
virtual inline void EraseVUMeter(std::vector<std::shared_ptr<GFXBase>> & GFX, int start, int yVU) const
{
for (int i = start; i <= GFX[0]->width(); i++)
for (auto& device : GFX)
device->setPixel(i, yVU, CRGB::Black);
}

// DrawVUPixels
//
// Draw i-th pixel in row y

virtual void DrawVUPixels(std::vector<std::shared_ptr<GFXBase>> & GFX, int i, int yVU, int fadeBy = 0, const CRGBPalette16 * pPalette = nullptr) override
{
for (auto& device : GFX)
device->setPixel(i, yVU, ColorFromPalette(pPalette ? *pPalette : vu_gpGreen, i*256/GFX[0]->width()).fadeToBlackBy(fadeBy));
}

public:
void DrawVUMeter(std::vector<std::shared_ptr<GFXBase>> & GFX, int yVU = 0, const CRGBPalette16 * pPalette = nullptr)
{
const int MAX_FADE = 256;

int size = GFX[0]->width();
int bars = g_Analyzer._VURatioFade / 2.0 * size;
bars = min(bars, size);

EraseVUMeter(GFX, bars, yVU);

if (bars >= iPeakVUy)
{
msPeakVU = millis();
iPeakVUy = bars;
}
else if (millis() - msPeakVU > MS_PER_SECOND / 2)
{
iPeakVUy = 0;
}

if (iPeakVUy > 1)
{
int fade = MAX_FADE * (millis() - msPeakVU) / (float) MS_PER_SECOND * 2;
DrawVUPixels(GFX, iPeakVUy, yVU, fade);
DrawVUPixels(GFX, iPeakVUy-1, yVU, fade);
}

for (int i = 0; i < bars; i++)
DrawVUPixels(GFX, i, yVU, i > bars ? 255 : 0, pPalette);
}
};

class VUMeterEffect : virtual public VUMeter, public LEDStripEffect
{
public:
virtual void Draw() override
{
DrawVUMeter(g(), 0);
DrawVUMeter(g_ptrSystem->EffectManager().GetBaseGraphics(), 0);
}

VUMeterEffect() : LEDStripEffect(EFFECT_STRIP_VUMETER, "VUMeter")
Expand All @@ -205,6 +258,28 @@ class VUMeterEffect : virtual public VUMeter, public LEDStripEffect
}
};

class VUMeterVerticalEffect : virtual public VUMeterVertical, public LEDStripEffect
{
public:
virtual void Draw() override
{
DrawVUMeter(g_ptrSystem->EffectManager().GetBaseGraphics(), 0);
}

VUMeterVerticalEffect() : LEDStripEffect(EFFECT_STRIP_VUMETER_VERTICAL, "Vertical VUMeter")
{
}

VUMeterVerticalEffect(const JsonObjectConst& jsonObject)
: LEDStripEffect(jsonObject)
{
}

bool SerializeToJSON(JsonObject& jsonObject) override
{
return true;
}
};
// SpectrumAnalyzerEffect
//
// An effect that draws an audio spectrum analyzer on a matrix. It is assumed that the
Expand Down Expand Up @@ -779,4 +854,64 @@ class SpectrumBarEffect : public LEDStripEffect, public BeatEffectBase
}
};

// AudioSpikeEffect [MATRIX EFFECT]
//
// Simply displays the raw audio sample buffer as a waveform

class AudioSpikeEffect : public LEDStripEffect
{
protected:

public:

AudioSpikeEffect(const String & pszFriendlyName)
: LEDStripEffect(EFFECT_MATRIX_AUDIOSPIKE, pszFriendlyName)
{
}

AudioSpikeEffect(const JsonObjectConst& jsonObject)
: LEDStripEffect(jsonObject)
{
}

virtual bool SerializeToJSON(JsonObject& jsonObject) override
{
StaticJsonDocument<LEDStripEffect::_jsonSize> jsonDoc;

JsonObject root = jsonDoc.to<JsonObject>();
LEDStripEffect::SerializeToJSON(root);

assert(!jsonDoc.overflowed());
return jsonObject.set(jsonDoc.as<JsonObjectConst>());
}

virtual size_t DesiredFramesPerSecond() const override
{
return 60;
}

virtual void Draw() override
{
fadeAllChannelsToBlackBy(50);

static int colorOffset = 0;
colorOffset+= 4;

static int offset = 2;

const int16_t * data = g_Analyzer.GetSampleBuffer();
int lastY = map(data[offset], 0, 2500, 0, MATRIX_HEIGHT);
for (int32_t x = 0; x < MATRIX_WIDTH; ++x)
{
byte y1 = map(data[offset+x], 0, 2500, 0, MATRIX_HEIGHT);
CRGB color = ColorFromPalette(spectrumBasicColors, (y1 * 4) + colorOffset, 255, NOBLEND);
g()->drawLine(x, lastY, x+1, y1, color);
lastY = y1;
}
offset += MATRIX_WIDTH;
if (offset + MATRIX_WIDTH > g_Analyzer.GetSampleBufferSize())
offset = 2;
}
};

#endif
Loading
Loading