Bugfixes
This commit is contained in:
@@ -16,11 +16,51 @@
|
||||
|
||||
FASTLED_USING_NAMESPACE
|
||||
|
||||
class RGBTest : public Pattern
|
||||
{
|
||||
public:
|
||||
using Pattern::Pattern;
|
||||
|
||||
const char * name() const override
|
||||
{
|
||||
return "rgbtest";
|
||||
}
|
||||
|
||||
void run() override
|
||||
{
|
||||
CRGB color;
|
||||
switch(m_index)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
color = CRGB::Red;
|
||||
break;
|
||||
case 2:
|
||||
color = CRGB::Green;
|
||||
break;
|
||||
case 3:
|
||||
color = CRGB::Blue;
|
||||
}
|
||||
|
||||
fill_solid(&leds[0], NUM_LEDS, color);
|
||||
|
||||
EVERY_N_SECONDS(1)
|
||||
{
|
||||
m_index++;
|
||||
if (m_index >= 4)
|
||||
m_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int m_index = 0;
|
||||
};
|
||||
|
||||
class LedController
|
||||
{
|
||||
public:
|
||||
LedController() :
|
||||
controller(FastLED.addLeds<WS2812, pin, RGB>(&leds[0], leds.size())),
|
||||
controller(FastLED.addLeds<WS2812, pin, BRG>(&leds[0], leds.size())),
|
||||
m_rainbow(leds),
|
||||
m_rainbowWithGlitter(leds),
|
||||
m_confetti(leds),
|
||||
@@ -28,7 +68,8 @@ public:
|
||||
m_juggle(leds),
|
||||
m_bpm(leds),
|
||||
m_fire2012(leds),
|
||||
patterns { &m_rainbow, &m_rainbowWithGlitter, &m_confetti, &m_sineleon, &m_juggle, &m_bpm, &m_fire2012 },
|
||||
m_rgbtest(leds),
|
||||
patterns { &m_rainbow, &m_rainbowWithGlitter, &m_confetti, &m_sineleon, &m_juggle, &m_bpm, &m_fire2012, &m_rgbtest },
|
||||
iter(patterns.begin())
|
||||
{
|
||||
controller.setCorrection(TypicalLEDStrip);
|
||||
@@ -62,8 +103,10 @@ private:
|
||||
JugglePattern m_juggle;
|
||||
BpmPattern m_bpm;
|
||||
Fire2012Pattern m_fire2012;
|
||||
RGBTest m_rgbtest;
|
||||
|
||||
public:
|
||||
using PatternContainer = std::array<Pattern*, 8>;
|
||||
const PatternContainer patterns;
|
||||
PatternContainer::const_iterator iter;
|
||||
};
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <FastLED.h>
|
||||
|
||||
FASTLED_USING_NAMESPACE
|
||||
@@ -11,4 +12,3 @@ class Pattern;
|
||||
constexpr auto pin = 0;
|
||||
constexpr auto NUM_LEDS = 100;
|
||||
using LedContainer = std::array<CRGB, NUM_LEDS>;
|
||||
using PatternContainer = std::array<Pattern*, 7>;
|
||||
|
46
src/main.cpp
46
src/main.cpp
@@ -20,6 +20,9 @@ bool rotatePattern = true;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(true);
|
||||
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASSWD);
|
||||
|
||||
server.on("/", HTTP_GET, []()
|
||||
@@ -43,11 +46,11 @@ void setup()
|
||||
"}"
|
||||
"</style>"
|
||||
|
||||
"<title>Hello, world!</title>"
|
||||
"<title>LED-Control</title>"
|
||||
"</head>"
|
||||
"<body>"
|
||||
"<div class=\"container\">"
|
||||
"<h1>Hello, world!</h1>"
|
||||
"<h1>LED-Control</h1>"
|
||||
"<p>"
|
||||
"<a href=\"setPower?val=true\" id=\"enablePower\" class=\"softLink\">Turn LEDs on</a> "
|
||||
"<a href=\"setPower?val=false\" id=\"disablePower\" class=\"softLink\">Turn LEDs off</a> "
|
||||
@@ -132,6 +135,45 @@ void setup()
|
||||
);
|
||||
});
|
||||
|
||||
server.on("/update", HTTP_GET, []() {
|
||||
server.sendHeader("Connection", "close");
|
||||
server.send(200, "text/html",
|
||||
"<form method=\"POST\" action=\"/update\" enctype=\"multipart/form-data\">"
|
||||
"<input type=\"file\" name=\"update\" />"
|
||||
"<button type=\"submit\">Install</button>"
|
||||
"</form>");
|
||||
});
|
||||
|
||||
server.on("/update", HTTP_POST, []() {
|
||||
server.sendHeader("Connection", "close");
|
||||
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
|
||||
ESP.restart();
|
||||
}, []() {
|
||||
HTTPUpload& upload = server.upload();
|
||||
if (upload.status == UPLOAD_FILE_START) {
|
||||
Serial.setDebugOutput(true);
|
||||
Serial.printf("Update: %s\n", upload.filename.c_str());
|
||||
|
||||
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
if (!Update.begin(maxSketchSpace)) { //start with max available size
|
||||
Update.printError(Serial);
|
||||
}
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
|
||||
Update.printError(Serial);
|
||||
}
|
||||
} else if (upload.status == UPLOAD_FILE_END) {
|
||||
if (Update.end(true)) { //true to set the size to the current progress
|
||||
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
|
||||
} else {
|
||||
Update.printError(Serial);
|
||||
}
|
||||
|
||||
Serial.setDebugOutput(false);
|
||||
}
|
||||
yield();
|
||||
});
|
||||
|
||||
server.on("/status", HTTP_GET, []()
|
||||
{
|
||||
server.sendHeader("Connection", "close");
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
class Pattern {
|
||||
public:
|
||||
Pattern(LedContainer leds) :
|
||||
Pattern(LedContainer &leds) :
|
||||
leds(leds)
|
||||
{
|
||||
}
|
||||
|
@@ -20,13 +20,15 @@ public:
|
||||
|
||||
void run() override
|
||||
{
|
||||
uint8_t BeatsPerMinute = 62;
|
||||
CRGBPalette16 palette = PartyColors_p;
|
||||
uint8_t beat = beatsin8(BeatsPerMinute, 64, 255);
|
||||
for(int i = 0; i < leds.size(); i++)
|
||||
leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-(gHue++)+(i*10));
|
||||
leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
|
||||
gHue++;
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr uint8_t BeatsPerMinute = 62;
|
||||
const CRGBPalette16 &palette = *reinterpret_cast<const CRGBPalette16*>(&PartyColors_p);
|
||||
|
||||
uint8_t gHue = 0;
|
||||
};
|
||||
|
Reference in New Issue
Block a user