87 lines
1.7 KiB
C++
87 lines
1.7 KiB
C++
/*
|
|
* ESP8266 RGBW controller
|
|
* Copyright 2020 (c) Mark van Renswoude
|
|
*
|
|
* https://git.x2software.net/pub/RGBWifi
|
|
*/
|
|
#include "./strip.h"
|
|
#include <Math.h>
|
|
#include <FS.h>
|
|
#include "./debug.h"
|
|
#include "./global.h"
|
|
|
|
|
|
|
|
NeoGamma<NeoGammaTableMethod> colorGamma;
|
|
RgbwColor clearColor(0);
|
|
|
|
|
|
void Strip::init(uint16_t ledCount)
|
|
{
|
|
mBus = new NeoPixelBus<NeoPixelBusFeature, NeoPixelBusMethod>(ledCount);
|
|
mBus->Begin();
|
|
|
|
setStatic(clearColor);
|
|
}
|
|
|
|
|
|
void Strip::tick()
|
|
{
|
|
if (tickMethod != nullptr)
|
|
(*this.*tickMethod)();
|
|
}
|
|
|
|
|
|
void Strip::setStatic(const RgbwColor color)
|
|
{
|
|
tickMethod = nullptr;
|
|
|
|
_d("Strip :: setStatic, color = "); _d(color.R); _d(","); _d(color.G); _d(","); _d(color.B); _d(","); _dln(color.W);
|
|
RgbwColor corrected = colorGamma.Correct(color);
|
|
|
|
_d("Strip :: setStatic, gamma corrected = "); _d(corrected.R); _d(","); _d(corrected.G); _d(","); _d(corrected.B); _d(","); _dln(corrected.W);
|
|
mBus->ClearTo(corrected);
|
|
this->update();
|
|
}
|
|
|
|
|
|
void Strip::setRainbow(uint16_t speed)
|
|
{
|
|
lastTick = currentTime;
|
|
delay = (uint32_t)(1000.0F / (float)speed);
|
|
tickMethod = speed > 0 ? &Strip::tickRainbow : nullptr;
|
|
|
|
uint16_t ledCount = systemSettings->ledCount();
|
|
HslColor* color = new HslColor(0, 1, 0.5);
|
|
|
|
for (uint16_t ledIndex = 0; ledIndex < ledCount; ledIndex++)
|
|
{
|
|
color->H = (float)ledIndex / (float)ledCount;
|
|
mBus->SetPixelColor(ledIndex, *color);
|
|
}
|
|
|
|
delete color;
|
|
|
|
this->update();
|
|
}
|
|
|
|
|
|
void Strip::update()
|
|
{
|
|
while (!mBus->CanShow())
|
|
yield();
|
|
|
|
mBus->Show();
|
|
}
|
|
|
|
|
|
void Strip::tickRainbow()
|
|
{
|
|
uint32_t shiftAmount = (currentTime - lastTick) / delay;
|
|
if (shiftAmount == 0)
|
|
return;
|
|
|
|
lastTick = currentTime;
|
|
mBus->RotateLeft(shiftAmount);
|
|
this->update();
|
|
} |