Skip to content

Commit 6cf79ee

Browse files
authored
Merge pull request #660 from davepl/RGBW
Test of RGBW Branch
2 parents 26fe5c1 + 21ec184 commit 6cf79ee

25 files changed

+462
-125
lines changed

config/ci_exclude.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["heltecv3demo"]
1+
[]

config/partitions_custom.csv

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
# ESP-IDF Partition Table
2-
# This gives us some additional space for code.
3-
# It should also fix the OTA regression.
4-
# Name, Type, SubType, Offset, Size, Flags
5-
6-
# Note that our NVS code assumes name 'storage' for the NVS partition
1+
# Standard 4M partition layout with OTA (Over the air updates)
72

3+
# Name, Type, SubType, Offset, Size, Flags
84
nvs, data, nvs, 0x00b000, 0x002000,
95
otadata, data, ota, 0x00d000, 0x002000,
10-
app0, app, ota_0, 0x010000, 0x190000,
11-
app1, app, ota_1, 0x1A0000, 0x190000,
12-
storage, data, spiffs, 0x330000, 0x0D0000
6+
app0, app, ota_0, 0x010000, 0x1A0000,
7+
app1, app, ota_1, 0x1B0000, 0x1A0000,
8+
storage, data, spiffs, 0x350000, 0x0B0000

include/deviceconfig.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@
9494

9595
#define DEVICE_CONFIG_FILE "/device.cfg"
9696
#define NTP_SERVER_DEFAULT "0.pool.ntp.org"
97-
#define BRIGHTNESS_MIN uint8_t(10)
97+
#ifndef BRIGHTNESS_MIN
98+
#define BRIGHTNESS_MIN uint8_t(10)
99+
#endif
98100
#define BRIGHTNESS_MAX uint8_t(255)
99101
#define POWER_LIMIT_MIN 1000
100102
#define POWER_LIMIT_DEFAULT 4500

include/effectmanager.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,19 @@ class EffectManager : public IJSONSerializable
153153
ClearEffects();
154154
}
155155

156-
std::shared_ptr<GFXBase> GetBaseGraphics()
156+
// SetTempEffect - Sets a temporary effect to be played until remote changes it.
157+
// The effect must have already had its Init() function called.
158+
159+
void SetTempEffect(std::shared_ptr<LEDStripEffect> effect)
160+
{
161+
_tempEffect = effect;
162+
}
163+
164+
// GetBaseGraphics - Returns the vector of GFXBase objects that the effects use to draw
165+
166+
std::vector<std::shared_ptr<GFXBase>> & GetBaseGraphics()
157167
{
158-
return _gfx[0];
168+
return _gfx;
159169
}
160170

161171
bool IsNewFrameAvailable() const

include/effects.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#define EFFECT_STRIP_FAN_BEAT 37
8484
#define EFFECT_STRIP_SPLASH_LOGO 38
8585
#define EFFECT_STRIP_VUMETER 39
86+
#define EFFECT_STRIP_VUMETER_VERTICAL 40
8687

8788
// Matrix effects
8889
#define EFFECT_MATRIX_ALIEN_TEXT 101
@@ -147,6 +148,7 @@
147148
#define EFFECT_MATRIX_STOCKS 159
148149
#define EFFECT_MATRIX_SILON 160
149150
#define EFFECT_MATRIX_PDPGRID 161
151+
#define EFFECT_MATRIX_AUDIOSPIKE 162
150152

151153
// Hexagon Effects
152154
#define EFFECT_HEXAGON_OUTER_RING 201
@@ -183,6 +185,7 @@
183185
#define PTY_SPARKS "spc"
184186
#define PTY_SPARKING "spg"
185187
#define PTY_SPARKHEIGHT "sph"
188+
#define PTY_SPARKTEMP "spt"
186189
#define PTY_COOLING "clg"
187190
#define PTY_PALETTE "plt"
188191
#define PTY_ORDER "ord"
@@ -194,6 +197,7 @@
194197
#define PTY_MAXSPEED "mxs"
195198
#define PTY_SPEEDDIVISOR "sdd"
196199
#define PTY_DELTAHUE "dth"
200+
#define PTY_MIRRORED "mrd"
197201
#define PTY_EVERYNTH "ent"
198202
#define PTY_COLOR "clr"
199203
#define PTY_BLEND "bld"

include/effects/matrix/spectrumeffects.h

Lines changed: 150 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ class VUMeter
120120
//
121121
// Draw i-th pixel in row y
122122

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

128-
int xHalf = pGFXChannel->width()/2;
129-
pGFXChannel->setPixel(xHalf-i-1, yVU, ColorFromPalette(pPalette ? *pPalette : vu_gpGreen, i*(256/xHalf)).fadeToBlackBy(fadeBy));
130-
pGFXChannel->setPixel(xHalf+i, yVU, ColorFromPalette(pPalette ? *pPalette : vu_gpGreen, i*(256/xHalf)).fadeToBlackBy(fadeBy));
128+
int xHalf = GFX[0]->width()/2;
129+
GFX[0]->setPixel(xHalf-i-1, yVU, ColorFromPalette(pPalette ? *pPalette : vu_gpGreen, i*(256/xHalf)).fadeToBlackBy(fadeBy));
130+
GFX[0]->setPixel(xHalf+i, yVU, ColorFromPalette(pPalette ? *pPalette : vu_gpGreen, i*(256/xHalf)).fadeToBlackBy(fadeBy));
131131
}
132132

133133

@@ -140,25 +140,25 @@ class VUMeter
140140

141141
public:
142142

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

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

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

161-
EraseVUMeter(pGFXChannel, bars, yVU);
161+
EraseVUMeter(GFX, bars, yVU);
162162

163163
if (bars >= iPeakVUy)
164164
{
@@ -173,21 +173,74 @@ class VUMeter
173173
if (iPeakVUy > 1)
174174
{
175175
int fade = MAX_FADE * (millis() - msPeakVU) / (float) MS_PER_SECOND * 2;
176-
DrawVUPixels(pGFXChannel, iPeakVUy, yVU, fade);
177-
DrawVUPixels(pGFXChannel, iPeakVUy-1, yVU, fade);
176+
DrawVUPixels(GFX, iPeakVUy, yVU, fade);
177+
DrawVUPixels(GFX, iPeakVUy-1, yVU, fade);
178178
}
179179

180180
for (int i = 0; i < bars; i++)
181-
DrawVUPixels(pGFXChannel, i, yVU, i > bars ? 255 : 0, pPalette);
181+
DrawVUPixels(GFX, i, yVU, i > bars ? 255 : 0, pPalette);
182182
}
183183
};
184184

185+
class VUMeterVertical : public VUMeter
186+
{
187+
private:
188+
virtual inline void EraseVUMeter(std::vector<std::shared_ptr<GFXBase>> & GFX, int start, int yVU) const
189+
{
190+
for (int i = start; i <= GFX[0]->width(); i++)
191+
for (auto& device : GFX)
192+
device->setPixel(i, yVU, CRGB::Black);
193+
}
194+
195+
// DrawVUPixels
196+
//
197+
// Draw i-th pixel in row y
198+
199+
virtual void DrawVUPixels(std::vector<std::shared_ptr<GFXBase>> & GFX, int i, int yVU, int fadeBy = 0, const CRGBPalette16 * pPalette = nullptr) override
200+
{
201+
for (auto& device : GFX)
202+
device->setPixel(i, yVU, ColorFromPalette(pPalette ? *pPalette : vu_gpGreen, i*256/GFX[0]->width()).fadeToBlackBy(fadeBy));
203+
}
204+
205+
public:
206+
void DrawVUMeter(std::vector<std::shared_ptr<GFXBase>> & GFX, int yVU = 0, const CRGBPalette16 * pPalette = nullptr)
207+
{
208+
const int MAX_FADE = 256;
209+
210+
int size = GFX[0]->width();
211+
int bars = g_Analyzer._VURatioFade / 2.0 * size;
212+
bars = min(bars, size);
213+
214+
EraseVUMeter(GFX, bars, yVU);
215+
216+
if (bars >= iPeakVUy)
217+
{
218+
msPeakVU = millis();
219+
iPeakVUy = bars;
220+
}
221+
else if (millis() - msPeakVU > MS_PER_SECOND / 2)
222+
{
223+
iPeakVUy = 0;
224+
}
225+
226+
if (iPeakVUy > 1)
227+
{
228+
int fade = MAX_FADE * (millis() - msPeakVU) / (float) MS_PER_SECOND * 2;
229+
DrawVUPixels(GFX, iPeakVUy, yVU, fade);
230+
DrawVUPixels(GFX, iPeakVUy-1, yVU, fade);
231+
}
232+
233+
for (int i = 0; i < bars; i++)
234+
DrawVUPixels(GFX, i, yVU, i > bars ? 255 : 0, pPalette);
235+
}
236+
};
237+
185238
class VUMeterEffect : virtual public VUMeter, public LEDStripEffect
186239
{
187240
public:
188241
virtual void Draw() override
189242
{
190-
DrawVUMeter(g(), 0);
243+
DrawVUMeter(g_ptrSystem->EffectManager().GetBaseGraphics(), 0);
191244
}
192245

193246
VUMeterEffect() : LEDStripEffect(EFFECT_STRIP_VUMETER, "VUMeter")
@@ -205,6 +258,28 @@ class VUMeterEffect : virtual public VUMeter, public LEDStripEffect
205258
}
206259
};
207260

261+
class VUMeterVerticalEffect : virtual public VUMeterVertical, public LEDStripEffect
262+
{
263+
public:
264+
virtual void Draw() override
265+
{
266+
DrawVUMeter(g_ptrSystem->EffectManager().GetBaseGraphics(), 0);
267+
}
268+
269+
VUMeterVerticalEffect() : LEDStripEffect(EFFECT_STRIP_VUMETER_VERTICAL, "Vertical VUMeter")
270+
{
271+
}
272+
273+
VUMeterVerticalEffect(const JsonObjectConst& jsonObject)
274+
: LEDStripEffect(jsonObject)
275+
{
276+
}
277+
278+
bool SerializeToJSON(JsonObject& jsonObject) override
279+
{
280+
return true;
281+
}
282+
};
208283
// SpectrumAnalyzerEffect
209284
//
210285
// An effect that draws an audio spectrum analyzer on a matrix. It is assumed that the
@@ -779,4 +854,64 @@ class SpectrumBarEffect : public LEDStripEffect, public BeatEffectBase
779854
}
780855
};
781856

857+
// AudioSpikeEffect [MATRIX EFFECT]
858+
//
859+
// Simply displays the raw audio sample buffer as a waveform
860+
861+
class AudioSpikeEffect : public LEDStripEffect
862+
{
863+
protected:
864+
865+
public:
866+
867+
AudioSpikeEffect(const String & pszFriendlyName)
868+
: LEDStripEffect(EFFECT_MATRIX_AUDIOSPIKE, pszFriendlyName)
869+
{
870+
}
871+
872+
AudioSpikeEffect(const JsonObjectConst& jsonObject)
873+
: LEDStripEffect(jsonObject)
874+
{
875+
}
876+
877+
virtual bool SerializeToJSON(JsonObject& jsonObject) override
878+
{
879+
StaticJsonDocument<LEDStripEffect::_jsonSize> jsonDoc;
880+
881+
JsonObject root = jsonDoc.to<JsonObject>();
882+
LEDStripEffect::SerializeToJSON(root);
883+
884+
assert(!jsonDoc.overflowed());
885+
return jsonObject.set(jsonDoc.as<JsonObjectConst>());
886+
}
887+
888+
virtual size_t DesiredFramesPerSecond() const override
889+
{
890+
return 60;
891+
}
892+
893+
virtual void Draw() override
894+
{
895+
fadeAllChannelsToBlackBy(50);
896+
897+
static int colorOffset = 0;
898+
colorOffset+= 4;
899+
900+
static int offset = 2;
901+
902+
const int16_t * data = g_Analyzer.GetSampleBuffer();
903+
int lastY = map(data[offset], 0, 2500, 0, MATRIX_HEIGHT);
904+
for (int32_t x = 0; x < MATRIX_WIDTH; ++x)
905+
{
906+
byte y1 = map(data[offset+x], 0, 2500, 0, MATRIX_HEIGHT);
907+
CRGB color = ColorFromPalette(spectrumBasicColors, (y1 * 4) + colorOffset, 255, NOBLEND);
908+
g()->drawLine(x, lastY, x+1, y1, color);
909+
lastY = y1;
910+
}
911+
offset += MATRIX_WIDTH;
912+
if (offset + MATRIX_WIDTH > g_Analyzer.GetSampleBufferSize())
913+
offset = 2;
914+
}
915+
};
916+
782917
#endif

0 commit comments

Comments
 (0)