port to platformio
This commit is contained in:
75
src/animations/Chimes.cpp
Normal file
75
src/animations/Chimes.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
#include "../Figments/Figments.h"
|
||||
#include "../sprites/Chime.h"
|
||||
#include "../sprites/Blob.h"
|
||||
|
||||
#define CHIME_LENGTH 23
|
||||
#define CHIME_COUNT 4
|
||||
#define BLOB_COUNT 10
|
||||
|
||||
class ChimesAnimation: public Figment {
|
||||
public:
|
||||
ChimesAnimation(Task::State initialState) : Figment("Chimes", initialState) {
|
||||
m_chimes.forEach([](Chime<CHIME_LENGTH> &chime) {
|
||||
chime.setPos(random(Chime<CHIME_LENGTH>::Length * 5));
|
||||
chime.setHue(random(255));
|
||||
chime.setSpeed(random(90) + 138);
|
||||
chime.setBrightness(200);
|
||||
chime.setOffset(random(1024));
|
||||
});
|
||||
m_blobs.forEach([](Blob &blob) {
|
||||
blob.setPos(random(255));
|
||||
blob.setHue(random(255));
|
||||
blob.setBrightness(random(255));
|
||||
if (random(255) % 2) {
|
||||
blob.setVelocity(-1);
|
||||
} else {
|
||||
blob.setVelocity(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void handleEvent(const InputEvent& evt) override {
|
||||
if (evt.intent == InputEvent::UserInput) {
|
||||
if (strcmp(evt.asString(), "blobs") == 0) {
|
||||
m_blobs.toggle();
|
||||
} else if (strcmp(evt.asString(), "chimes") == 0) {
|
||||
m_chimes.toggle();
|
||||
}
|
||||
} else if (evt.intent == InputEvent::SetColor) {
|
||||
m_flashBrightness.set(255, 0);
|
||||
m_flashColor = evt.asRGB();
|
||||
uint8_t flashHue = rgb2hsv_approximate(m_flashColor).hue;
|
||||
m_blobs.forEach([&](Blob& blob) {
|
||||
blob.setHue(flashHue);
|
||||
});
|
||||
m_chimes.forEach([&](Chime<CHIME_LENGTH>& chime) {
|
||||
chime.setHue(flashHue);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void loop() override {
|
||||
m_chimes.update();
|
||||
m_blobs.update();
|
||||
m_flashColor.update();
|
||||
EVERY_N_MILLISECONDS(5) {
|
||||
m_flashBrightness.update();
|
||||
}
|
||||
}
|
||||
|
||||
void render(Display* dpy) const override {
|
||||
m_chimes.render(dpy);
|
||||
m_blobs.render(dpy);
|
||||
Surface fullSurface(dpy, {0, 0}, {255, 0});
|
||||
CRGB scaledColor = CRGB(m_flashColor).nscale8_video(std::max((uint8_t)10, ease8InOutCubic(m_flashBrightness)));
|
||||
fullSurface.paintWith([&](CRGB& pixel) {
|
||||
pixel = blend(scaledColor, pixel, 200);
|
||||
//pixel = scaledColor;
|
||||
});
|
||||
}
|
||||
|
||||
SpriteList<Chime<CHIME_LENGTH>, CHIME_COUNT> m_chimes;
|
||||
SpriteList<Blob, BLOB_COUNT> m_blobs;
|
||||
AnimatedRGB m_flashColor;
|
||||
AnimatedNumber m_flashBrightness;
|
||||
};
|
64
src/animations/Drain.cpp
Normal file
64
src/animations/Drain.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#include <Figments.h>
|
||||
#include <ArduinoLog.h>
|
||||
|
||||
class DrainAnimation: public Figment {
|
||||
public:
|
||||
|
||||
DrainAnimation(Task::State initialState) : Figment("Drain", initialState) {}
|
||||
|
||||
void loop() override {
|
||||
EVERY_N_MILLISECONDS(8) {
|
||||
m_pos++;
|
||||
m_fillColor.update();
|
||||
}
|
||||
EVERY_N_MILLISECONDS(50) {
|
||||
if (random(255) >= 10) {
|
||||
m_burst -= m_burst / 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void handleEvent(const InputEvent& event) override {
|
||||
if (event.intent == InputEvent::SetColor) {
|
||||
m_fillColor = event.asRGB();
|
||||
} else if (event.intent == InputEvent::Acceleration) {
|
||||
m_pos += log10(event.asInt());
|
||||
uint16_t burstInc = event.asInt() / 6;
|
||||
m_burst = (m_burst > 0xFFFF - burstInc) ? 0xFFFF : m_burst + burstInc;
|
||||
}
|
||||
}
|
||||
|
||||
AnimatedRGB m_fillColor;
|
||||
|
||||
void render(Display* dpy) const override {
|
||||
dpy->clear();
|
||||
Surface leftPanel{dpy, {0, 0}, {128, 0}};
|
||||
Surface rightPanel{dpy, {128, 0}, {255, 0}};
|
||||
fillRange(dpy, leftPanel.start, leftPanel.end, rgb2hsv_approximate(m_fillColor));
|
||||
fillRange(dpy, rightPanel.end, rightPanel.start, rgb2hsv_approximate(m_fillColor));
|
||||
}
|
||||
|
||||
void fillRange(Display* dpy, const PhysicalCoordinates &start, const PhysicalCoordinates& end, const CHSV &baseColor) const {
|
||||
int length = end.x - start.x;
|
||||
int direction = 1;
|
||||
if (length < 0) {
|
||||
direction = -1;
|
||||
}
|
||||
|
||||
uint8_t frac = 255 / std::abs(length);
|
||||
for(int i = 0; i < std::abs(length); i++) {
|
||||
auto coords = PhysicalCoordinates((start.x + (i * direction)), 0);
|
||||
|
||||
const uint8_t localScale = inoise8(i * 80, m_pos * 3);
|
||||
const uint8_t dimPosition = lerp8by8(50, 190, scale8(sin8((frac * i) / 2), localScale));
|
||||
const uint8_t withBurst = ease8InOutCubic(lerp16by16(dimPosition, 255, m_burst));
|
||||
auto scaledColor = CHSV(baseColor.hue, lerp8by8(100, 255, localScale), withBurst);
|
||||
|
||||
CRGB src(dpy->pixelAt(coords));
|
||||
dpy->pixelAt(coords) = blend(scaledColor, src, 200);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t m_pos;
|
||||
uint16_t m_burst;
|
||||
};
|
63
src/animations/Drain.h
Normal file
63
src/animations/Drain.h
Normal file
@ -0,0 +1,63 @@
|
||||
class DrainAnimation: public Figment {
|
||||
public:
|
||||
|
||||
DrainAnimation(Task::State initialState) : Figment("Drain", initialState) {}
|
||||
|
||||
void loop() override {
|
||||
EVERY_N_MILLISECONDS(8) {
|
||||
m_pos++;
|
||||
m_fillColor.update();
|
||||
}
|
||||
EVERY_N_MILLISECONDS(50) {
|
||||
if (random(255) >= 10) {
|
||||
m_burst -= m_burst / 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void handleEvent(const InputEvent& event) override {
|
||||
if (event.intent == InputEvent::SetColor) {
|
||||
m_fillColor = event.asRGB();
|
||||
} else if (event.intent == InputEvent::Acceleration) {
|
||||
m_pos += log10(event.asInt());
|
||||
uint16_t burstInc = event.asInt() / 6;
|
||||
m_burst = (m_burst > 0xFFFF - burstInc) ? 0xFFFF : m_burst + burstInc;
|
||||
}
|
||||
}
|
||||
|
||||
AnimatedRGB m_fillColor;
|
||||
|
||||
void render(Display* dpy) const override {
|
||||
dpy->clear();
|
||||
Surface leftPanel{dpy, {0, 0}, {128, 0}};
|
||||
Surface rightPanel{dpy, {128, 0}, {255, 0}};
|
||||
fillRange(dpy, leftPanel.start, leftPanel.end, rgb2hsv_approximate(m_fillColor));
|
||||
fillRange(dpy, rightPanel.end, rightPanel.start, rgb2hsv_approximate(m_fillColor));
|
||||
}
|
||||
|
||||
void fillRange(Display* dpy, const PhysicalCoordinates &start, const PhysicalCoordinates& end, const CHSV &baseColor) const {
|
||||
int length = end.x - start.x;
|
||||
int direction = 1;
|
||||
if (length < 0) {
|
||||
direction = -1;
|
||||
}
|
||||
|
||||
uint8_t frac = 255 / std::abs(length);
|
||||
for(int i = 0; i < std::abs(length); i++) {
|
||||
auto coords = PhysicalCoordinates((start.x + (i * direction)), 0);
|
||||
|
||||
const uint8_t localScale = inoise8(i * 80, m_pos * 3);
|
||||
const uint8_t dimPosition = lerp8by8(50, 190, scale8(sin8((frac * i) / 2), localScale));
|
||||
const uint8_t withBurst = ease8InOutCubic(lerp16by16(dimPosition, 255, m_burst));
|
||||
auto scaledColor = CHSV(baseColor.hue, lerp8by8(100, 255, localScale), withBurst);
|
||||
|
||||
CRGB src(dpy->pixelAt(coords));
|
||||
dpy->pixelAt(coords) = blend(scaledColor, src, 200);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t m_pos;
|
||||
uint16_t m_burst;
|
||||
};
|
||||
|
||||
|
47
src/animations/Flashlight.cpp
Normal file
47
src/animations/Flashlight.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <Figments.h>
|
||||
#include "../sprites/Blob.h"
|
||||
|
||||
class Flashlight: public Figment {
|
||||
public:
|
||||
Flashlight(Task::State initialState) : Figment("Flashlight", initialState) {
|
||||
m_blobs.forEach([](Blob &blob) {
|
||||
blob.setHue(random(255));
|
||||
blob.setSaturation(10);
|
||||
blob.setPos(random(255));
|
||||
});
|
||||
}
|
||||
|
||||
void handleEvent(const InputEvent& evt) override {
|
||||
if (evt.intent == InputEvent::Acceleration) {
|
||||
if (evt.asInt() > 10) {
|
||||
m_blobs.forEach([](Blob& blob) {blob.update();});
|
||||
}
|
||||
}
|
||||
|
||||
/*if (evt.intent() == InputEvent::UserInput) {
|
||||
if (evt.asInt() == 1) {
|
||||
m_blobs.forEach([](Blob& blob) {blob.setPos(random(255));});
|
||||
}
|
||||
if (evt.asInt() == 2) {
|
||||
m_blobs.forEach([](Blob& chime) {blob.setPos(0);});
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void loop() override {
|
||||
m_blobs.update();
|
||||
}
|
||||
|
||||
void render(Display* dpy) const override {
|
||||
m_blobs.render(dpy);
|
||||
for(int i = 0; i < dpy->pixelCount();i++) {
|
||||
dpy->pixelAt(i) |= 100;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr int blobCount = 30;
|
||||
SpriteList<Blob, blobCount> m_blobs;
|
||||
};
|
40
src/animations/Power.cpp
Normal file
40
src/animations/Power.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include <Figments.h>
|
||||
|
||||
template<uint8_t MaxBrightness = 255, uint32_t MaxMilliAmps = 500, uint32_t Voltage = 5>
|
||||
class Power: public Figment {
|
||||
public:
|
||||
Power() : Figment("Power") {}
|
||||
|
||||
void handleEvent(const InputEvent& evt) override {
|
||||
switch (evt.intent) {
|
||||
case InputEvent::PowerToggle:
|
||||
m_powerState = m_powerState.value() <= 128 ? 255 : 0;
|
||||
//Log.info("POWER TOGGLE %d", m_powerState.value());
|
||||
break;
|
||||
case InputEvent::SetPower:
|
||||
m_powerState = evt.asInt() == 0 ? 0 : 255;
|
||||
break;
|
||||
case InputEvent::SetBrightness:
|
||||
m_brightness = evt.asInt();
|
||||
}
|
||||
}
|
||||
|
||||
void loop() override {
|
||||
m_powerState.update();
|
||||
m_brightness.update();
|
||||
}
|
||||
|
||||
void render(Display* dpy) const override {
|
||||
const uint8_t clippedBrightness = min((uint8_t)m_brightness, MaxBrightness);
|
||||
const uint8_t scaledBrightness = scale8(m_powerState, clippedBrightness);
|
||||
const uint8_t videoBrightness = brighten8_video(scaledBrightness);
|
||||
const uint8_t powerBrightness = calculate_max_brightness_for_power_mW(videoBrightness, Watts);
|
||||
FastLED.setBrightness(powerBrightness);
|
||||
}
|
||||
|
||||
static constexpr uint32_t Watts = Voltage * MaxMilliAmps;
|
||||
|
||||
private:
|
||||
AnimatedNumber m_powerState = 255;
|
||||
AnimatedNumber m_brightness = MaxBrightness;
|
||||
};
|
50
src/animations/SolidAnimation.cpp
Normal file
50
src/animations/SolidAnimation.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include <Figments.h>
|
||||
#include "../sprites/Blob.h"
|
||||
|
||||
class SolidAnimation: public Figment {
|
||||
private:
|
||||
AnimatedNumber m_red, m_green, m_blue;
|
||||
static constexpr int blobCount = 20;
|
||||
SpriteList<Blob, blobCount> m_blobs;
|
||||
|
||||
public:
|
||||
SolidAnimation(Task::State initialState) : Figment("Solid", initialState) {
|
||||
m_blobs.forEach([](Blob& blob) {
|
||||
blob.setPos(random(140));
|
||||
blob.setBrightness(random(255));
|
||||
if (random(255) % 2) {
|
||||
blob.setVelocity(-1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void handleEvent(const InputEvent& evt) override {
|
||||
if (evt.intent == InputEvent::SetColor) {
|
||||
CRGB nextColor = evt.asRGB();
|
||||
m_red.set(nextColor.red);
|
||||
m_green.set(nextColor.green);
|
||||
m_blue.set(nextColor.blue);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() override {
|
||||
m_red.update();
|
||||
m_green.update();
|
||||
m_blue.update();
|
||||
EVERY_N_MILLIS(6) {
|
||||
CRGB rgb{m_red, m_green, m_blue};
|
||||
CHSV hsv = rgb2hsv_approximate(rgb);
|
||||
m_blobs.forEach([=](Blob& blob) {
|
||||
blob.setHue(hsv.hue);
|
||||
blob.setSaturation(hsv.saturation);
|
||||
});
|
||||
m_blobs.update();
|
||||
}
|
||||
}
|
||||
|
||||
void render(Display* dpy) const override {
|
||||
CRGB color(m_red.value(), m_green.value(), m_blue.value());
|
||||
Surface(dpy, {0, 0}, {255, 0}) = color;
|
||||
m_blobs.render(dpy);
|
||||
}
|
||||
};
|
53
src/animations/TestAnimation.cpp
Normal file
53
src/animations/TestAnimation.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "./TestAnimation.h"
|
||||
#include <FastLED.h>
|
||||
|
||||
const char*
|
||||
TestAnimation::name() const
|
||||
{
|
||||
return "Test";
|
||||
}
|
||||
|
||||
void
|
||||
TestAnimation::handleEvent(const InputEvent& evt)
|
||||
{
|
||||
if (evt.intent == InputEvent::Acceleration) {
|
||||
if (evt.asInt() > 5) {
|
||||
m_brightness += 15;
|
||||
}
|
||||
m_hue += scale8(evt.asInt(), 128);
|
||||
}
|
||||
|
||||
if (evt.intent == InputEvent::UserInput) {
|
||||
switch(evt.asInt()) {
|
||||
case 1:
|
||||
m_brightness.set(255, 0);break;
|
||||
case 2:
|
||||
m_saturation.set(255, 128);break;
|
||||
default:
|
||||
m_brightness.set(255, 0);
|
||||
m_saturation.set(255, 128);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TestAnimation::loop()
|
||||
{
|
||||
m_x += 4;
|
||||
if (m_x % 12 == 0) {
|
||||
m_y += 28;
|
||||
}
|
||||
m_hue.update();
|
||||
m_saturation.update();
|
||||
m_brightness.update();
|
||||
}
|
||||
|
||||
void
|
||||
TestAnimation::render(Display* dpy) const
|
||||
{
|
||||
for(uint8_t col = 0; col < 3; col++) {
|
||||
for (uint8_t i = 0; i < 254; i+=10) {
|
||||
dpy->pixelAt(VirtualCoordinates{(uint8_t)(m_x + (col * (254 / 3))), (uint8_t)(i + m_y)}) = CHSV(m_hue, m_saturation + 100, scale8(i, m_brightness));
|
||||
}
|
||||
}
|
||||
}
|
16
src/animations/TestAnimation.h
Normal file
16
src/animations/TestAnimation.h
Normal file
@ -0,0 +1,16 @@
|
||||
#include <Figments.h>
|
||||
|
||||
class TestAnimation: public Figment {
|
||||
public:
|
||||
const char* name() const;
|
||||
void handleEvent(const InputEvent& evt) override;
|
||||
void loop() override;
|
||||
void render(Display* dpy) const override;
|
||||
|
||||
private:
|
||||
AnimatedNumber m_hue;
|
||||
AnimatedNumber m_saturation;
|
||||
AnimatedNumber m_brightness;
|
||||
uint8_t m_x;
|
||||
uint8_t m_y;
|
||||
};
|
34
src/animations/UpdateStatus.cpp
Normal file
34
src/animations/UpdateStatus.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "./UpdateStatus.h"
|
||||
#include <FastLED.h>
|
||||
#include "../Static.h"
|
||||
|
||||
void
|
||||
UpdateStatus::handleEvent(const InputEvent& evt)
|
||||
{
|
||||
if (evt.intent == InputEvent::FirmwareUpdate) {
|
||||
static int updateCount = 0;
|
||||
updateCount++;
|
||||
//Log.info("Update count %d", updateCount);
|
||||
m_updateReady = true;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
UpdateStatus::loop()
|
||||
{
|
||||
m_pos++;
|
||||
}
|
||||
|
||||
void
|
||||
UpdateStatus::render(Display* dpy) const
|
||||
{
|
||||
if (m_updateReady) {
|
||||
for(int i = 0; i < 12; i+=3) {
|
||||
dpy->pixelAt(m_pos + i) = CRGB(255, 0, 0);
|
||||
dpy->pixelAt(m_pos + i + 1) = CRGB(0, 255, 0);
|
||||
dpy->pixelAt(m_pos + i + 2) = CRGB(0, 0, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STATIC_ALLOC(UpdateStatus);
|
13
src/animations/UpdateStatus.h
Normal file
13
src/animations/UpdateStatus.h
Normal file
@ -0,0 +1,13 @@
|
||||
#include <Figments.h>
|
||||
|
||||
class UpdateStatus: public Figment {
|
||||
public:
|
||||
UpdateStatus() : Figment("UpdateStatusAnimation") {}
|
||||
void handleEvent(const InputEvent& evt) override;
|
||||
void loop() override;
|
||||
void render(Display* dpy) const override;
|
||||
|
||||
private:
|
||||
bool m_updateReady = false;
|
||||
uint8_t m_pos = 0;
|
||||
};
|
Reference in New Issue
Block a user