Compare commits
8 Commits
ecf5998510
...
ae997ef802
Author | SHA1 | Date | |
---|---|---|---|
ae997ef802 | |||
a6af2829ee | |||
0a4a62d7c8 | |||
7747e38253 | |||
b9cfc6568b | |||
1d66f9c541 | |||
f9e6a5ebd6 | |||
a96f6c79e3 |
32
include/SimpleEffect.h
Normal file
32
include/SimpleEffect.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "Effect.h"
|
||||
#include "prototypes.h"
|
||||
#include <cmath>
|
||||
|
||||
#define SE_CYCLE_COLORS 1 // Slowly cycle through the rainbow.
|
||||
#define SE_RANDOM_PIXEL_COLORS 2 // Every pixel gets a random color every frame.
|
||||
#define SE_ONLY_POSITIVE 4 // Only use colors, not white. This is equivalent to running your output through abs()
|
||||
#define SE_FADEOUT 8 // Fades the old image out. Returning 0 doesn't change the pixel's value.
|
||||
#define SE_RANDOM_STATIC_COLOR 16 // Sets a random static color at start of the effect.
|
||||
#define SE_DEBUG 32 // Prints debug messages.
|
||||
|
||||
class SimpleEffect : public Effect {
|
||||
protected:
|
||||
Window* window = &Window::window_full; // Use a full screen window per default.
|
||||
uint8_t _color = 0;
|
||||
uint16_t _flags;
|
||||
String _name;
|
||||
simple_effect_t _method;
|
||||
public:
|
||||
SimpleEffect(String name, uint16_t flags, simple_effect_t method): _name { name }, _method { method } {
|
||||
_flags = flags;
|
||||
if (_flags & SE_RANDOM_STATIC_COLOR) {
|
||||
_color = random8();
|
||||
_flags &= ~SE_CYCLE_COLORS & ~SE_RANDOM_PIXEL_COLORS;
|
||||
}
|
||||
};
|
||||
void loop(uint16_t ms) override;
|
||||
String get_name() { return _name; };
|
||||
boolean can_be_shown_with_clock() { return true; }
|
||||
|
||||
};
|
@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Effect.h"
|
||||
#include "my_fastled.h"
|
||||
|
||||
class ConfettiEffect : public Effect {
|
||||
protected:
|
||||
virtual CRGB _getColor();
|
||||
public:
|
||||
void loop(uint16_t ms);
|
||||
boolean can_be_shown_with_clock();
|
||||
String get_name() override { return "confetti"; }
|
||||
};
|
||||
|
||||
class RandomConfettiEffect : public ConfettiEffect {
|
||||
protected:
|
||||
CRGB _getColor() override;
|
||||
String get_name() override { return "random_confetti"; }
|
||||
};
|
||||
|
@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "Effect.h"
|
||||
#include "effect_clock.h"
|
||||
#include "effect_timer.h"
|
||||
#include "effects/clock.h"
|
||||
#include "effects/timer.h"
|
||||
|
||||
#define SIMPLE_EFFECT(name, use_in_cycle, flags, ...) {name, use_in_cycle, [](){ return new SimpleEffect(name, flags, [](double t, uint16_t i, uint8_t x, uint8_t y)->double __VA_ARGS__ ); }}
|
||||
|
||||
struct EffectEntry {
|
||||
const char* name;
|
||||
|
@ -19,9 +19,12 @@ public:
|
||||
virtual void loop(uint16_t ms);
|
||||
String get_name() override { return "big_clock"; }
|
||||
};
|
||||
<<<<<<< HEAD:include/effects/big_clock.h
|
||||
=======
|
||||
|
||||
class NightClockEffect : public BigClockEffect {
|
||||
private:
|
||||
void _draw_border_pixel(accum88 pos, CRGB* color) { };
|
||||
CRGB _get_color_font() { return CRGB(0x220000); }
|
||||
};
|
||||
>>>>>>> ecf5998510bf1f8230d070cebccb4c89f95ce856:include/effect_big_clock.h
|
8
include/effects/night_clock.h
Normal file
8
include/effects/night_clock.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "Effect.h"
|
||||
|
||||
class NightClockEffect : public Effect {
|
||||
public:
|
||||
virtual void loop(uint16_t ms);
|
||||
String get_name() override { return "night_clock"; }
|
||||
};
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "my_fastled.h"
|
||||
|
||||
extern uint8_t baseHue;
|
||||
extern char hostname[30];
|
||||
@ -31,3 +32,5 @@ typedef struct {
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
} Coords;
|
||||
|
||||
typedef std::function<double(double, uint16_t, uint8_t, uint8_t)> simple_effect_t;
|
35
src/SimpleEffect.cpp
Normal file
35
src/SimpleEffect.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "SimpleEffect.h"
|
||||
|
||||
void SimpleEffect::loop(uint16_t ms) {
|
||||
if (_flags & SE_FADEOUT) window->fadeToBlackBy(3);
|
||||
double t = 0.001 * millis();
|
||||
for(uint8_t x=0; x<window->width; x++) for(uint8_t y=0; y<window->height; y++) {
|
||||
uint16_t i = y*window->width + x;
|
||||
double r = _method(t, i, x, y);
|
||||
//if (i==0) Serial.printf("t=%f i=%d x=%d y=%d => r=%f, abs(r)=%d\n", t, i, x, y, r, abs(r)*255);
|
||||
if ((_flags & SE_DEBUG) && i==17) Serial.printf("t=%f i=%d x=%d y=%d => r=%f, abs(r*255)=%d\n", t, i, x, y, r, (int)abs(r*255));
|
||||
if ((_flags & SE_FADEOUT) && r==0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Clamp r between -1.0 and +1.0
|
||||
if (r<-1.0) {
|
||||
r = -1.0;
|
||||
} else if (r>1.0) {
|
||||
r = 1.0;
|
||||
}
|
||||
|
||||
if (_flags & SE_ONLY_POSITIVE) {
|
||||
r = abs(r);
|
||||
}
|
||||
|
||||
CRGB color;
|
||||
if (_flags & SE_RANDOM_PIXEL_COLORS) {
|
||||
color = CHSV(random8(), 255, abs(r*255));
|
||||
} else {
|
||||
color = CHSV(_flags & SE_CYCLE_COLORS ? baseHue : _color, r<0?0:255, abs(r*255));
|
||||
}
|
||||
|
||||
window->setPixel(x, y, &color);
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#include "effect_confetti.h"
|
||||
#include "config.h"
|
||||
#include "functions.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
void ConfettiEffect::loop(uint16_t ms) {
|
||||
window->fadeToBlackBy(3);
|
||||
for (int i=0; i<settings.effects.confetti.pixels_per_loop; i++) {
|
||||
CRGB color = _getColor();
|
||||
window->addPixelColor(random16(LED_COUNT), &color);
|
||||
}
|
||||
}
|
||||
|
||||
CRGB ConfettiEffect::_getColor() {
|
||||
return CHSV(baseHue + random8(64), 255, 255);
|
||||
}
|
||||
|
||||
CRGB RandomConfettiEffect::_getColor() {
|
||||
return CHSV(random8(), 255, 255);
|
||||
}
|
||||
|
||||
boolean ConfettiEffect::can_be_shown_with_clock() { return true; };
|
@ -1,31 +1,32 @@
|
||||
#include "effects.h"
|
||||
#include "config.h"
|
||||
#include "my_fastled.h"
|
||||
#include "effect_bell.h"
|
||||
#include "effect_sinematrix3.h"
|
||||
#include "effect_big_clock.h"
|
||||
#include "effect_clock.h"
|
||||
#include "effect_static.h"
|
||||
#include "effect_animation.h"
|
||||
#include "effect_dynamic.h"
|
||||
#include "effect_matrix.h"
|
||||
#include "effect_twirl.h"
|
||||
#include "effect_cycle.h"
|
||||
#include "effect_confetti.h"
|
||||
#include "effect_snake.h"
|
||||
#include "effect_fire.h"
|
||||
#include "effect_firework.h"
|
||||
#include "effect_gol.h"
|
||||
#include "effect_pixelclock.h"
|
||||
#include "effect_dvd.h"
|
||||
#include "effect_analogclock.h"
|
||||
#include "effect_sines.h"
|
||||
#include "effect_marquee.h"
|
||||
#include "effect_blur2d.h"
|
||||
#include "effect_tv_static.h"
|
||||
#include "effect_lightspeed.h"
|
||||
#include "effect_diamond.h"
|
||||
#include "effect_tpm2_net.h"
|
||||
#include "effects/bell.h"
|
||||
#include "effects/sinematrix3.h"
|
||||
#include "effects/big_clock.h"
|
||||
#include "effects/clock.h"
|
||||
#include "effects/static.h"
|
||||
#include "effects/animation.h"
|
||||
#include "effects/dynamic.h"
|
||||
#include "effects/matrix.h"
|
||||
#include "effects/twirl.h"
|
||||
#include "effects/cycle.h"
|
||||
#include "effects/snake.h"
|
||||
#include "effects/fire.h"
|
||||
#include "effects/firework.h"
|
||||
#include "effects/gol.h"
|
||||
#include "effects/pixelclock.h"
|
||||
#include "effects/dvd.h"
|
||||
#include "effects/analogclock.h"
|
||||
#include "effects/sines.h"
|
||||
#include "effects/marquee.h"
|
||||
#include "effects/blur2d.h"
|
||||
#include "effects/tv_static.h"
|
||||
#include "effects/lightspeed.h"
|
||||
#include "effects/diamond.h"
|
||||
#include "effects/tpm2_net.h"
|
||||
#include "SimpleEffect.h"
|
||||
#include "effects/night_clock.h"
|
||||
|
||||
Effect* current_effect;
|
||||
|
||||
@ -47,8 +48,8 @@ EffectEntry effects[] = {
|
||||
/* 10 */ {"rainbow_matrix", true, [](){ return new RainbowMatrixEffect(); }},
|
||||
/* 11 */ {"cycle", 0, [](){ return new CycleEffect(); }},
|
||||
/* 12 */ {"twirl", true, [](){ return new TwirlEffect(); }},
|
||||
/* 13 */ {"confetti", true, [](){ return new ConfettiEffect(); }},
|
||||
/* 14 */ {"random_confetti", true, [](){ return new RandomConfettiEffect(); }},
|
||||
/* 13 */ SIMPLE_EFFECT("confetti", true, SE_CYCLE_COLORS | SE_FADEOUT, {return random8()>252?1:0;}),
|
||||
/* 14 */ SIMPLE_EFFECT("rainbow_confetti", true, SE_RANDOM_PIXEL_COLORS | SE_FADEOUT, {return random8()>252?1:0;}),
|
||||
/* 15 */ {"snake", true, [](){ return new SnakeEffect(); }},
|
||||
/* 16 */ {"firework", true, [](){ return new FireworkEffect(); }},
|
||||
/* 17 */ {"gol", true, [](){ return new GolEffect(); }},
|
||||
@ -68,8 +69,14 @@ EffectEntry effects[] = {
|
||||
/* 31 */ {"child", 0, [](){ return AnimationEffect::Blinker("/child.pia", 300, 0xFFFF00); }},
|
||||
/* 32 */ {"diamond", true, [](){ return new DiamondEffect(); }},
|
||||
/* 33 */ {"tpm2.net", 0, [](){ return new Tpm2NetEffect(); }},
|
||||
/* 34 */ SIMPLE_EFFECT("slow_blinking", true, SE_CYCLE_COLORS, {return sin(t + (x+1)*(y+1)*i);} ),
|
||||
/* 35 */ SIMPLE_EFFECT("upwave", true, SE_CYCLE_COLORS, {return (cos(t+y/2));} ),
|
||||
/* 36 */ SIMPLE_EFFECT("centerwave", true, SE_CYCLE_COLORS, {return sin(t*2 - sqrt((x-4)*(x-4) + (y-7)*(y-7)));} ),
|
||||
/* 37 */ SIMPLE_EFFECT("sineline", true, SE_RANDOM_STATIC_COLOR, {return sin(x/2)-sin(x-t)-y+6;} ),
|
||||
/* 38 */ SIMPLE_EFFECT("barbershop", true, SE_RANDOM_STATIC_COLOR, {return 1*cos(0.8*i-t*5);} ),
|
||||
/* 39 */ SIMPLE_EFFECT("zigzag", true, SE_CYCLE_COLORS, { return cos(cos(x+y)-y*cos(t/8+x/16));} ),
|
||||
};
|
||||
const uint8_t effects_size = 34;
|
||||
const uint8_t effects_size = 40;
|
||||
|
||||
|
||||
Effect* select_effect(const char* name) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "effect_analogclock.h"
|
||||
#include "effects/analogclock.h"
|
||||
#include "my_fastled.h"
|
||||
#include "ntp.h"
|
||||
#include <time.h>
|
@ -1,4 +1,4 @@
|
||||
#include "effect_animation.h"
|
||||
#include "effects/animation.h"
|
||||
#include "functions.h"
|
||||
|
||||
AnimationEffect::AnimationEffect(const char* name, uint32_t bg, int x, int y) {
|
@ -1,6 +1,6 @@
|
||||
#include "Effect.h"
|
||||
#include "functions.h"
|
||||
#include "effect_bell.h"
|
||||
#include "effects/bell.h"
|
||||
#include "sprites.h"
|
||||
|
||||
void BellEffect::loop(uint16_t ms) {
|
@ -1,5 +1,5 @@
|
||||
#include "Effect.h"
|
||||
#include "effect_big_clock.h"
|
||||
#include "effects/big_clock.h"
|
||||
#include "fonts.h"
|
||||
#include <time.h>
|
||||
#include "settings.h"
|
@ -1,4 +1,4 @@
|
||||
#include "effect_blur2d.h"
|
||||
#include "effects/blur2d.h"
|
||||
Blur2DBlob::Blur2DBlob() {
|
||||
_x_freq = random16(6<<8, 15<<8);
|
||||
_y_freq = random16(6<<8, 15<<8);
|
@ -1,4 +1,4 @@
|
||||
#include "effect_clock.h"
|
||||
#include "effects/clock.h"
|
||||
#include <FastLED.h>
|
||||
#include "functions.h"
|
||||
#include "fonts.h"
|
@ -1,4 +1,4 @@
|
||||
#include "effect_cycle.h"
|
||||
#include "effects/cycle.h"
|
||||
#include "effects.h"
|
||||
|
||||
CycleEffect::CycleEffect() {
|
@ -1,4 +1,4 @@
|
||||
#include "effect_diamond.h"
|
||||
#include "effects/diamond.h"
|
||||
#include "my_fastled.h"
|
||||
|
||||
void DiamondEffect::loop(uint16_t ms) {
|
@ -1,4 +1,4 @@
|
||||
#include "effect_dvd.h"
|
||||
#include "effects/dvd.h"
|
||||
#include "my_fastled.h"
|
||||
|
||||
void DvdEffect::loop(uint16_t ms) {
|
@ -1,4 +1,4 @@
|
||||
#include "effect_dynamic.h"
|
||||
#include "effects/dynamic.h"
|
||||
#include "functions.h"
|
||||
#include "config.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "effect_fire.h"
|
||||
#include "effects/fire.h"
|
||||
#include "my_color_palettes.h"
|
||||
#include "config.h"
|
||||
#include "my_fastled.h"
|
@ -1,5 +1,5 @@
|
||||
// Based on https://gist.github.com/kriegsman/68929cbd1d6de4535b20
|
||||
#include "effect_firework.h"
|
||||
#include "effects/firework.h"
|
||||
|
||||
FireworkEffectDot::FireworkEffectDot(Window* w, FireworkEffect* e) {
|
||||
_window = w;
|
@ -1,4 +1,4 @@
|
||||
#include "effect_gol.h"
|
||||
#include "effects/gol.h"
|
||||
#include "my_fastled.h"
|
||||
|
||||
GolEffect::GolEffect() {
|
@ -1,4 +1,4 @@
|
||||
#include "effect_lightspeed.h"
|
||||
#include "effects/lightspeed.h"
|
||||
#include "config.h"
|
||||
#include "functions.h"
|
||||
#include "prototypes.h"
|
@ -1,4 +1,4 @@
|
||||
#include "effect_marquee.h"
|
||||
#include "effects/marquee.h"
|
||||
#include "fonts.h"
|
||||
|
||||
boolean MarqueeEffect::can_be_shown_with_clock() {
|
@ -1,4 +1,4 @@
|
||||
#include "effect_matrix.h"
|
||||
#include "effects/matrix.h"
|
||||
#include "my_color_palettes.h"
|
||||
#include "functions.h"
|
||||
|
26
src/effects/night_clock.cpp
Normal file
26
src/effects/night_clock.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "Effect.h"
|
||||
#include "effects/night_clock.h"
|
||||
#include "fonts.h"
|
||||
#include <time.h>
|
||||
|
||||
void NightClockEffect::loop(uint16_t ms) {
|
||||
window->clear();
|
||||
time_t now;
|
||||
tm timeinfo;
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
uint8_t h = timeinfo.tm_hour;
|
||||
CRGB color = CRGB(0x440000);
|
||||
window->drawChar(&font5x7, 4<<8, 0<<8, '0' + (h / 10), &color);
|
||||
window->drawChar(&font5x7, 10<<8, 0<<8, '0' + (h % 10), &color);
|
||||
|
||||
uint8_t m = timeinfo.tm_min;
|
||||
window->drawChar(&font5x7, 4<<8, 9<<8, '0' + (m / 10), &color);
|
||||
window->drawChar(&font5x7, 10<<8, 9<<8, '0' + (m % 10), &color);
|
||||
|
||||
uint8_t s = timeinfo.tm_sec;
|
||||
if(s & 1) {
|
||||
window->setPixel(2, 11, &color);
|
||||
window->setPixel(2, 13, &color);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
#include "effect_pixelclock.h"
|
||||
#include "effects/pixelclock.h"
|
||||
#include "ntp.h"
|
||||
|
||||
PixelClockEffect::PixelClockEffect() {
|
@ -1,4 +1,4 @@
|
||||
#include "effect_sinematrix3.h"
|
||||
#include "effects/sinematrix3.h"
|
||||
#include "prototypes.h"
|
||||
#include "functions.h"
|
||||
#include "Effect.h"
|
@ -1,4 +1,4 @@
|
||||
#include "effect_sines.h"
|
||||
#include "effects/sines.h"
|
||||
|
||||
SinesEffectSinus::SinesEffectSinus(Window* w) {
|
||||
_window = w;
|
@ -1,4 +1,4 @@
|
||||
#include "effect_snake.h"
|
||||
#include "effects/snake.h"
|
||||
#include "functions.h"
|
||||
|
||||
SnakeEffect::SnakeEffect() {
|
@ -1,4 +1,4 @@
|
||||
#include "effect_static.h"
|
||||
#include "effects/static.h"
|
||||
#include "functions.h"
|
||||
#include "my_fastled.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "effect_timer.h"
|
||||
#include "effects/timer.h"
|
||||
#include <FastLED.h>
|
||||
#include "functions.h"
|
||||
#include "fonts.h"
|
@ -1,4 +1,4 @@
|
||||
#include "effect_tpm2_net.h"
|
||||
#include "effects/tpm2_net.h"
|
||||
#include "my_fastled.h"
|
||||
|
||||
void Tpm2NetEffect::loop(uint16_t ms) {
|
@ -1,4 +1,4 @@
|
||||
#include "effect_tv_static.h"
|
||||
#include "effects/tv_static.h"
|
||||
|
||||
void TvStaticEffect::loop(uint16_t ms) {
|
||||
//uint8_t dark_position = (millis() % settings.effects.tv_static.black_bar_speed) * _window->width / settings.effects.tv_static.black_bar_speed;
|
@ -1,4 +1,4 @@
|
||||
#include "effect_twirl.h"
|
||||
#include "effects/twirl.h"
|
||||
#include "functions.h"
|
||||
|
||||
boolean TwirlEffect::can_be_shown_with_clock() { return true; };
|
@ -2,16 +2,6 @@
|
||||
require 'websocket-eventmachine-client'
|
||||
require 'pp'
|
||||
|
||||
def rgb2ansi(r, g, b)
|
||||
if r==g && g==b
|
||||
return 16 if r<8
|
||||
return 231 if r>248
|
||||
return (((r - 8) / 247.0) * 24).round + 232
|
||||
end
|
||||
|
||||
return 16 + 36*(r/51.0).round + 6*(g/51.0).round + (b/51.0).round
|
||||
end
|
||||
|
||||
IP = ARGV[0]
|
||||
EFFECT = ARGV[1]
|
||||
uri = "ws://#{IP}:80/ws"
|
||||
@ -41,8 +31,7 @@ EM.run do
|
||||
str += "|"
|
||||
(0...width).each do |x|
|
||||
r, g, b = *data.shift(3)
|
||||
color_code = rgb2ansi(r, g, b)
|
||||
str += "\033[48;5;#{color_code}m "
|
||||
str += "\033[38;2;#{r};#{g};#{b}m●"
|
||||
end
|
||||
str += "\033[0m|\n"
|
||||
end
|
||||
|
16
src/wifi.cpp
16
src/wifi.cpp
@ -6,11 +6,21 @@
|
||||
void wifi_setup() {
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
Serial.println("WiFi * Connection Failed! Rebooting...");
|
||||
delay(5000);
|
||||
uint8_t result;
|
||||
uint8_t counter = 0;
|
||||
while ((result = WiFi.waitForConnectResult()) != WL_CONNECTED) {
|
||||
counter++;
|
||||
if (counter > 100) {
|
||||
Serial.print("WiFi * Connection Failed! Last result was: ");
|
||||
Serial.print(result);
|
||||
Serial.println(" Rebooting...");
|
||||
delay(100);
|
||||
ESP.restart();
|
||||
}
|
||||
Serial.print("WiFi * Still waiting for WiFi to connect. This is loop number ");
|
||||
Serial.println(counter);
|
||||
delay(100);
|
||||
}
|
||||
Serial.println("WiFi * Ready");
|
||||
Serial.print("WiFi * IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
Loading…
Reference in New Issue
Block a user