Compare commits
95 Commits
096d13438a
...
master
Author | SHA1 | Date | |
---|---|---|---|
d76e088c37 | |||
c9825c8f9b | |||
ae997ef802 | |||
a6af2829ee | |||
0a4a62d7c8 | |||
7747e38253 | |||
b9cfc6568b | |||
1d66f9c541 | |||
f9e6a5ebd6 | |||
a96f6c79e3 | |||
ecf5998510 | |||
0ac4f9b181 | |||
fd44b217a7 | |||
209140cfb7 | |||
bcb5fdc9be | |||
b5bb0feccf | |||
0863380648 | |||
075823220a | |||
caa86551a0 | |||
10be8ef7cc | |||
9de77349e8 | |||
599bcd87bc | |||
70ddba2cbc | |||
3f09d9adbf | |||
cfb25d6030 | |||
4762a852d8 | |||
8e2d2225cb | |||
65dd09ca0d | |||
f014fd7cae | |||
1707084299 | |||
402d7f5d75 | |||
521e5f735d | |||
0da161ccd1 | |||
f8b6f5cc02 | |||
c6b2a8a1d0 | |||
6ba916282b | |||
79c13e760f | |||
47812de405 | |||
d28dca0a4d | |||
e2a56d7c29 | |||
439e2de17f | |||
994f4894dd | |||
b5343b59e5 | |||
66c0124072 | |||
2a6f68cc45 | |||
f5d47fe7da | |||
029c93166d | |||
141210a370 | |||
a902addf94 | |||
b644006036 | |||
dfe99408c9 | |||
3c0e4af325 | |||
aa72196a07 | |||
f76354a4d5 | |||
01c364795f | |||
38aa654c54 | |||
1418d519d5 | |||
efe9b924ec | |||
7b8dabee43 | |||
783cfdae3f | |||
54925dfc0e | |||
306f72d838 | |||
230a1f1a91 | |||
bd0041619a | |||
a3caaa1fef | |||
ec379c009e | |||
8568436fc1 | |||
6eeb7488b1 | |||
efa9a73cae | |||
bbdb46c04d | |||
4c611da6d1 | |||
377ccc477f | |||
efebe9adb4 | |||
359b7a7826 | |||
b5c1f350d2 | |||
5eba691429 | |||
d8fe055e3d | |||
6b4f75b8bc | |||
416ab46f9b | |||
b4aa711940 | |||
205a0df842 | |||
8bcee1871f | |||
ef57c5ea2e | |||
0f1d4abe04 | |||
2b50691067 | |||
af1314632e | |||
2b7033b685 | |||
97dd6de280 | |||
54d357e6df | |||
ac1f758b87 | |||
85aee53462 | |||
f42b5e1034 | |||
083564caef | |||
3f6d4cb0be | |||
382631d7d7 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -9,3 +9,5 @@ include/config.h
|
||||
.piolibdeps
|
||||
.pioenvs
|
||||
.DS_Store
|
||||
.vscode
|
||||
src/tools/snakenet/data_set.*
|
||||
|
@ -95,7 +95,6 @@ If you enabled `DEBUG`, log messages will be sent to `MQTT_TOPIC/log`.
|
||||
| FastLED (with small modifications) | Daniel Garcia & Mark Kriegsman | https://fastled.io
|
||||
| NTPClient (with modifications) | | https://github.com/arduino-libraries/NTPClient
|
||||
| ESP8266WebServer | | https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer
|
||||
| ErriezCRC32 | Erriez | https://github.com/Erriez/ErriezCRC32
|
||||
| ESPAsyncTCP | me-no-dev | https://github.com/me-no-dev/ESPAsyncTCP
|
||||
|
||||
### Inspirations and stuff
|
||||
|
BIN
data/child.pia
Normal file
BIN
data/child.pia
Normal file
Binary file not shown.
@ -6,10 +6,10 @@
|
||||
|
||||
class Effect {
|
||||
protected:
|
||||
Window* window = Window::getFullWindow(); // Use a full screen window per default.
|
||||
Window* window = &Window::window_full; // Use a full screen window per default.
|
||||
public:
|
||||
virtual ~Effect() {};
|
||||
virtual void loop() = 0;
|
||||
virtual void loop(uint16_t ms) = 0;
|
||||
virtual String get_name() = 0;
|
||||
boolean supports_window = false;
|
||||
virtual boolean can_be_shown_with_clock() { return false; };
|
||||
|
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; }
|
||||
|
||||
};
|
@ -14,10 +14,13 @@ private:
|
||||
void _circle_point(int x0, int y0, int x1, int y1, CRGB* color);
|
||||
void _subpixel_render(uint8_t x, uint8_t y, CRGB* color, SubpixelRenderingMode m);
|
||||
public:
|
||||
static Window window_full;
|
||||
static Window window_with_clock;
|
||||
static Window window_clock;
|
||||
|
||||
const uint8_t x, y;
|
||||
const uint8_t width, height;
|
||||
uint16_t count;
|
||||
static Window* getFullWindow();
|
||||
|
||||
Window(): Window(0, 0, LED_WIDTH, LED_HEIGHT) {};
|
||||
Window(uint8_t x, uint8_t y) : Window(x, y, LED_WIDTH-x, LED_HEIGHT-y) {};
|
||||
@ -29,9 +32,9 @@ public:
|
||||
void setSubPixel(accum88 x, accum88 y, CRGB* color, SubpixelRenderingMode m = SUBPIXEL_RENDERING_ADD);
|
||||
void setPixelByIndex(uint16_t index, CRGB* color);
|
||||
void raisePixel(uint8_t x, uint8_t y, CRGB* color);
|
||||
void line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, CRGB* color);
|
||||
void lineWithAngle(uint8_t x, uint8_t y, uint8_t angle, uint8_t length, CRGB* color);
|
||||
void lineWithAngle(uint8_t x, uint8_t y, uint8_t angle, uint8_t startdist, uint8_t length, CRGB* color);
|
||||
void line(saccum78 x1, saccum78 y1, saccum78 x2, saccum78 y2, CRGB* color);
|
||||
void lineWithAngle(uint8_t x, uint8_t y, uint16_t angle, uint8_t length, CRGB* color);
|
||||
void lineWithAngle(uint8_t x, uint8_t y, uint16_t angle, uint8_t startdist, uint8_t length, CRGB* color);
|
||||
void circle(uint8_t x, uint8_t y, uint8_t r, CRGB* color);
|
||||
uint16_t coordsToGlobalIndex(uint8_t x, uint8_t y);
|
||||
uint16_t localToGlobalIndex(uint16_t);
|
||||
@ -50,4 +53,5 @@ public:
|
||||
void blur_row(uint8_t y, fract8 intensity);
|
||||
void blur_columns(fract8 intensity);
|
||||
void blur_column(uint8_t x, fract8 intensity);
|
||||
void fill_with_checkerboard();
|
||||
};
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <Arduino.h>
|
||||
#define FASTLED_INTERNAL
|
||||
#include <FastLED.h>
|
||||
#include "settings.h"
|
||||
|
||||
//#define DEBUG // Uncomment this to enable Debug messages via Serial and, if enabled, MQTT.
|
||||
//#define CONFIG_USABLE // Uncomment this by removing the // at the beginning!
|
||||
@ -35,6 +36,8 @@
|
||||
#define MQTT_TOPIC "pitrix/" // MQTT topic to listen to. Must not start with a slash, but must end with one.
|
||||
#define MQTT_REPORT_METRICS // Whether to report metrics via MQTT. Disable if unwanted.
|
||||
#define MQTT_TOPIC_WEATHER "accuweather/pitrix/" // MQTT topic to listen for weather data. Must not start with a slash, but must end with one.
|
||||
#define MQTT_TOPIC_TIMER "alexa/timer"
|
||||
#define MQTT_TOPIC_HOMEASSISTANT "homeassistant"
|
||||
|
||||
#define HOSTNAME "pitrix-%08X" // Hostname of the ESP to use for OTA and MQTT client id. %08X will be replaced by the chip id.
|
||||
#define OTA_STARTUP_DELAY 10 // How many seconds to wait at startup. This is useful to prevent being unable to flash OTA by a bug in the code. Set to 0 to disable.
|
||||
@ -42,46 +45,39 @@
|
||||
#define FPS 50
|
||||
#define SHOW_TEXT_DELAY 100
|
||||
|
||||
#define RECORDER_ENABLE
|
||||
#define RECORDER_PORT 2122
|
||||
|
||||
#define MONITOR_LOOP_TIMES false
|
||||
#define MONITOR_LOOP_TIME_THRESHOLD 500
|
||||
#define MONITOR_LOOP_TIME_COUNT_MAX 10
|
||||
|
||||
#define EFFECT_CYCLE_TIME 300 // Time in seconds between cycling effects.
|
||||
#define EFFECT_CYCLE_RANDOM true
|
||||
// settings.effects.cycle.time = 300; // Time in seconds between cycling effects.
|
||||
// settings.effects.cycle.random = true;
|
||||
|
||||
#define EFFECT_MATRIX_LENGTH_MIN 4
|
||||
#define EFFECT_MATRIX_LENGTH_MAX 20
|
||||
#define EFFECT_MATRIX_SPEED_MIN 50
|
||||
#define EFFECT_MATRIX_SPEED_MAX 135
|
||||
// settings.effects.matrix.length_min = 4;
|
||||
// settings.effects.matrix.length_max = 20;
|
||||
// settings.effects.matrix.speed_min = 1;
|
||||
// settings.effects.matrix.speed_max = 10;
|
||||
|
||||
#define EFFECT_SINGLE_DYNAMIC_LOOP_TIME 40
|
||||
#define EFFECT_MULTI_DYNAMIC_LOOP_TIME 1400
|
||||
#define EFFECT_BIG_DYNAMIC_LOOP_TIME 50
|
||||
#define EFFECT_BIG_DYNAMIC_SIZE 3
|
||||
// .dynamic.single_loop_time = 40;
|
||||
// .dynamic.multi_loop_time = 1400;
|
||||
// .dynamic.big_loop_time = 50;
|
||||
// .dynamic.big_size = 3;
|
||||
|
||||
#define EFFECT_CONFETTI_PIXELS_PER_LOOP 2
|
||||
// .fire.cooldown = 192;
|
||||
// .fire.spark_chance = 5;
|
||||
|
||||
#define EFFECT_SNAKE_DIRECTION_CHANGE 10
|
||||
#define EFFECT_SNAKE_SLOWDOWN 2
|
||||
// .firework.drag = 255;
|
||||
// .firework.bounce = 200;
|
||||
// .firework.gravity = 10;
|
||||
// .firework.sparks = 12;
|
||||
|
||||
#define EFFECT_FIRE_COOLDOWN 192
|
||||
#define EFFECT_FIRE_SPARK_CHANCE 5
|
||||
// .gol.start_percentage = 90;
|
||||
// .gol.blend_speed = 10;
|
||||
// .gol.restart_after_steps = 100;
|
||||
|
||||
#define EFFECT_FIREWORK_SHOT_CHANCE 200
|
||||
#define EFFECT_FIREWORK_BLUR 200
|
||||
#define EFFECT_FIREWORK_FADEOUT_SPEED 5
|
||||
// .sines.count = 5;
|
||||
|
||||
#define EFFECT_GOL_START_PERCENTAGE 90
|
||||
#define EFFECT_GOL_BLEND_SPEED 10
|
||||
#define EFFECT_GOL_RESTART_AFTER_STEPS 100
|
||||
|
||||
#define EFFECT_DVD_WIDTH 3
|
||||
#define EFFECT_DVD_HEIGHT 2
|
||||
|
||||
#define EFFECT_SINES_COUNT 5
|
||||
// .snake.direction_change = 5;
|
||||
// .snake.slowdown = 2;
|
||||
|
||||
// Stop editing here
|
||||
|
||||
@ -101,22 +97,18 @@
|
||||
Serial.println(buffer);\
|
||||
} while (0);
|
||||
#else
|
||||
#define LOG(msg, ...) do { \
|
||||
char buffer[128]; \
|
||||
snprintf_P(buffer, 128, PSTR(msg), ##__VA_ARGS__);\
|
||||
Serial.print(buffer);\
|
||||
} while (0);
|
||||
#define LOGln(msg, ...) do { \
|
||||
char buffer[128]; \
|
||||
snprintf_P(buffer, 128, PSTR(msg), ##__VA_ARGS__);\
|
||||
Serial.println(buffer);\
|
||||
} while (0);
|
||||
#define LOG(x, ...) Serial.printf(x, ##__VA_ARGS__);
|
||||
#define LOGln(x, ...) { Serial.printf(x, ##__VA_ARGS__); Serial.println(); }
|
||||
#endif
|
||||
#define DBG(msg, ...) { Serial.printf(msg, ##__VA_ARGS__); Serial.println(); }
|
||||
#else
|
||||
#define LOG(msg, ...) do {} while(0);
|
||||
#define LOGln(msg, ...) do {} while(0);
|
||||
#define LOG(x) do {} while(0);
|
||||
#define LOGln(x) do {} while(0);
|
||||
#define DBG(msg, ...) do {} while(0);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined( ESP8266 ) && !defined( ESP32 )
|
||||
#error "Neither ESP8266 nor ESP32 are set. Maybe you are compiling this for another platform...?"
|
||||
#endif
|
||||
|
@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Effect.h"
|
||||
#include "prototypes.h"
|
||||
#include "my_fastled.h"
|
||||
#include "Animation.h"
|
||||
|
||||
class AnimationEffect : public Effect {
|
||||
private:
|
||||
Animation *animation;
|
||||
const char* name;
|
||||
uint16_t xOffset;
|
||||
uint16_t yOffset;
|
||||
public:
|
||||
AnimationEffect(const char* name) : AnimationEffect(name, 0x000000, 0, 0) {}
|
||||
AnimationEffect(const char* name, uint32_t bg_color) : AnimationEffect(name, bg_color, 0, 0) {}
|
||||
AnimationEffect(const char* name, uint32_t bg_color, int x, int y);
|
||||
~AnimationEffect();
|
||||
AnimationEffect* setFgColor(uint32_t c);
|
||||
void loop();
|
||||
String get_name() override;
|
||||
};
|
@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Effect.h"
|
||||
|
||||
class BigClockEffect : public Effect {
|
||||
private:
|
||||
CRGB _color_font = CRGB(0xAAAAAA);
|
||||
CRGB _color_seconds = CRGB(0xFF0000);
|
||||
|
||||
void _draw_seconds();
|
||||
void _draw_border_pixel(uint8_t second, CRGB* color);
|
||||
|
||||
public:
|
||||
void loop();
|
||||
String get_name() override { return "big_clock"; }
|
||||
};
|
@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "functions.h"
|
||||
#include "Effect.h"
|
||||
|
||||
class Blur2DEffect : public Effect {
|
||||
private:
|
||||
Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
|
||||
public:
|
||||
~Blur2DEffect();
|
||||
boolean supports_window = true;
|
||||
boolean can_be_shown_with_clock();
|
||||
void loop();
|
||||
String get_name() override { return "blur2d"; }
|
||||
};
|
||||
|
@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Effect.h"
|
||||
#include "my_fastled.h"
|
||||
|
||||
class ConfettiEffect : public Effect {
|
||||
protected:
|
||||
virtual CRGB _getColor();
|
||||
public:
|
||||
void loop();
|
||||
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,25 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Effect.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
class SnakeEffect : public Effect {
|
||||
private:
|
||||
Coords coords;
|
||||
uint8_t direction = 1;
|
||||
uint8_t hue = 0;
|
||||
uint8_t run = 0;
|
||||
bool is_turn_needed();
|
||||
void turn_random();
|
||||
bool turn_right();
|
||||
bool turn_left();
|
||||
bool is_direction_okay(uint8_t direction);
|
||||
public:
|
||||
SnakeEffect();
|
||||
~SnakeEffect();
|
||||
void loop();
|
||||
boolean valid_position(Coords c);
|
||||
Coords update_position(Coords c, uint8_t direction);
|
||||
boolean can_be_shown_with_clock();
|
||||
String get_name() override { return "snake"; }
|
||||
};
|
@ -1,17 +1,28 @@
|
||||
#ifndef effects_H
|
||||
#define effects_H
|
||||
#pragma once
|
||||
|
||||
#include "Effect.h"
|
||||
#include "effect_clock.h"
|
||||
#include "effects/clock.h"
|
||||
#include "effects/timer.h"
|
||||
|
||||
extern const char* cycle_effects[];
|
||||
extern uint8_t cycle_effects_count;
|
||||
#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;
|
||||
bool use_in_cycle;
|
||||
std::function<Effect*()> create;
|
||||
#ifdef MQTT_REPORT_METRICS
|
||||
int16_t heap_change_sum;
|
||||
uint16_t run_count;
|
||||
#endif
|
||||
};
|
||||
extern EffectEntry effects[];
|
||||
extern const uint8_t effects_size;
|
||||
|
||||
extern Effect* current_effect;
|
||||
extern ClockEffect effect_clock;
|
||||
extern TimerEffect effect_timer;
|
||||
|
||||
Effect* select_effect(uint32_t c);
|
||||
Effect* select_effect(char* name);
|
||||
Effect* select_effect(uint8_t id);
|
||||
bool change_current_effect(String s);
|
||||
void setup_effects();
|
||||
|
||||
#endif
|
||||
|
@ -4,6 +4,6 @@
|
||||
|
||||
class AnalogClockEffect : public Effect {
|
||||
public:
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
String get_name() override { return "analog_clock"; }
|
||||
};
|
24
include/effects/animation.h
Normal file
24
include/effects/animation.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "Effect.h"
|
||||
#include "prototypes.h"
|
||||
#include "my_fastled.h"
|
||||
#include "../Animation.h"
|
||||
|
||||
class AnimationEffect : public Effect {
|
||||
private:
|
||||
Animation *animation;
|
||||
const char* name;
|
||||
uint16_t xOffset;
|
||||
uint16_t yOffset;
|
||||
unsigned long _last_blink_at;
|
||||
uint16_t _blink_freq;
|
||||
public:
|
||||
AnimationEffect(const char* name, uint32_t bg_color=0x000000, int x=0, int y=0);
|
||||
static AnimationEffect* Blinker(const char* name, uint16_t interval, uint32_t color, uint32_t background_color=0x000000);
|
||||
~AnimationEffect();
|
||||
AnimationEffect* setFgColor(uint32_t c);
|
||||
AnimationEffect* setBlinkFrequency(uint16_t);
|
||||
void loop(uint16_t ms);
|
||||
String get_name() override;
|
||||
};
|
@ -9,7 +9,7 @@ private:
|
||||
CRGB color_off = CRGB(0x000000);
|
||||
boolean invert = false;
|
||||
public:
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
String get_name() override { return "bell"; }
|
||||
};
|
||||
|
21
include/effects/big_clock.h
Normal file
21
include/effects/big_clock.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Effect.h"
|
||||
|
||||
class BigClockEffect : public Effect {
|
||||
protected:
|
||||
CRGB _color_font = CRGB(0xAAAAAA);
|
||||
CRGB _color_seconds_light = CRGB(0xFFFF00);
|
||||
CRGB _color_seconds_dark = CRGB(0xAA0000);
|
||||
CRGB _color_seconds_moving_light = CRGB(0x666600);
|
||||
CRGB _color_seconds_moving_dark = CRGB(0x660000);
|
||||
|
||||
virtual CRGB _get_color_font() { return CRGB(0xAAAAAA); }
|
||||
|
||||
void _draw_seconds(uint8_t seconds);
|
||||
virtual void _draw_border_pixel(accum88 pos, CRGB* color);
|
||||
void _draw_colon(bool odd);
|
||||
public:
|
||||
virtual void loop(uint16_t ms);
|
||||
String get_name() override { return "big_clock"; }
|
||||
};
|
32
include/effects/blur2d.h
Normal file
32
include/effects/blur2d.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "functions.h"
|
||||
#include "Effect.h"
|
||||
|
||||
class Blur2DBlob {
|
||||
private:
|
||||
accum88 _x_freq;
|
||||
accum88 _y_freq;
|
||||
uint8_t _color_freq;
|
||||
public:
|
||||
Blur2DBlob();
|
||||
void render(Window* win);
|
||||
};
|
||||
|
||||
class Blur2DEffect : public Effect {
|
||||
private:
|
||||
Window* window = &Window::window_with_clock;
|
||||
uint8_t _count;
|
||||
Blur2DBlob* _blobs;
|
||||
public:
|
||||
Blur2DEffect();
|
||||
~Blur2DEffect();
|
||||
void _init();
|
||||
void _delete();
|
||||
boolean supports_window = true;
|
||||
boolean can_be_shown_with_clock();
|
||||
void loop(uint16_t ms);
|
||||
String get_name() override { return "blur2d"; }
|
||||
};
|
||||
|
@ -7,18 +7,12 @@
|
||||
|
||||
class ClockEffect : public Effect {
|
||||
protected:
|
||||
Window* window = new Window(0, LED_HEIGHT - 6, LED_WIDTH, 6);
|
||||
Window* window = &Window::window_clock;
|
||||
|
||||
public:
|
||||
~ClockEffect();
|
||||
virtual void loop();
|
||||
virtual ~ClockEffect();
|
||||
virtual void loop(uint16_t ms);
|
||||
String get_name() override { return "clock"; }
|
||||
void loop_with_invert(bool invert);
|
||||
void loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t y);
|
||||
};
|
||||
|
||||
class NightClockEffect : public ClockEffect {
|
||||
public:
|
||||
NightClockEffect();
|
||||
void loop() override;
|
||||
};
|
@ -8,6 +8,8 @@ private:
|
||||
Effect* effect = NULL;
|
||||
uint16_t effect_id = -1;
|
||||
unsigned long effectSince = 0;
|
||||
uint16_t _heap_free = 0;
|
||||
uint8_t _effects_count;
|
||||
public:
|
||||
CycleEffect();
|
||||
~CycleEffect();
|
||||
@ -17,5 +19,5 @@ public:
|
||||
boolean clock_as_mask();
|
||||
String get_name() override;
|
||||
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
};
|
11
include/effects/diamond.h
Normal file
11
include/effects/diamond.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include "Effect.h"
|
||||
|
||||
class DiamondEffect : public Effect {
|
||||
private:
|
||||
Window* window = &Window::window_with_clock;
|
||||
public:
|
||||
void loop(uint16_t ms) override;
|
||||
bool can_be_shown_with_clock() override;
|
||||
String get_name() override { return "diamond"; }
|
||||
};
|
@ -3,16 +3,16 @@
|
||||
|
||||
class DvdEffect : public Effect {
|
||||
private:
|
||||
Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
|
||||
uint8_t _x = 0;
|
||||
uint8_t _y = 0;
|
||||
Window* window = &Window::window_with_clock;
|
||||
saccum78 _x = 0;
|
||||
saccum78 _y = 0;
|
||||
int8_t _x_dir = 1;
|
||||
int8_t _y_dir = 1;
|
||||
CRGB _color;
|
||||
public:
|
||||
DvdEffect();
|
||||
~DvdEffect();
|
||||
void loop() override;
|
||||
void loop(uint16_t ms) override;
|
||||
bool can_be_shown_with_clock() override;
|
||||
String get_name() override { return "dvd"; }
|
||||
};
|
@ -13,22 +13,22 @@ public:
|
||||
SingleDynamicEffect();
|
||||
void init();
|
||||
boolean can_be_shown_with_clock();
|
||||
virtual void loop();
|
||||
virtual void loop(uint16_t ms);
|
||||
void draw();
|
||||
String get_name() override { return "single_dynamic"; }
|
||||
};
|
||||
|
||||
class MultiDynamicEffect : public SingleDynamicEffect {
|
||||
public:
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
String get_name() override { return "multi_dynamic"; }
|
||||
};
|
||||
|
||||
class BigDynamicEffect : public Effect {
|
||||
private:
|
||||
Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
|
||||
Window* window = &Window::window_with_clock;
|
||||
public:
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
~BigDynamicEffect();
|
||||
boolean can_be_shown_with_clock() override;
|
||||
String get_name() override { return "big_dynamic"; }
|
@ -15,6 +15,6 @@ private:
|
||||
public:
|
||||
FireEffect();
|
||||
~FireEffect();
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
String get_name() override { return "fire"; }
|
||||
};
|
@ -6,11 +6,6 @@
|
||||
|
||||
enum FireworkDotType { FIREWORK_DOT_NONE, FIREWORK_DOT_SHELL, FIREWORK_DOT_SPARK };
|
||||
|
||||
#define EFFECT_FIREWORK_DRAG 255
|
||||
#define EFFECT_FIREWORK_BOUNCE 200
|
||||
#define EFFECT_FIREWORK_GRAVITY 10
|
||||
#define EFFECT_FIREWORK_SPARKS 12
|
||||
|
||||
class FireworkEffect;
|
||||
|
||||
class FireworkEffectDot {
|
||||
@ -39,7 +34,7 @@ public:
|
||||
|
||||
class FireworkEffect : public Effect {
|
||||
private:
|
||||
Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
|
||||
Window* window = &Window::window_with_clock;
|
||||
bool _skyburst = 0;
|
||||
|
||||
accum88 _burst_x;
|
||||
@ -49,14 +44,14 @@ private:
|
||||
CRGB _burst_color;
|
||||
|
||||
FireworkEffectDot* _dot;
|
||||
FireworkEffectDot* _sparks[EFFECT_FIREWORK_SPARKS];
|
||||
FireworkEffectDot** _sparks;
|
||||
public:
|
||||
FireworkEffect();
|
||||
~FireworkEffect();
|
||||
void skyburst(accum88 x, accum88 y, saccum78 xv, saccum78 yv, CRGB c);
|
||||
boolean supports_window = true;
|
||||
boolean can_be_shown_with_clock();
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
String get_name() override { return "firework"; }
|
||||
};
|
||||
|
@ -17,7 +17,7 @@ private:
|
||||
public:
|
||||
GolEffect();
|
||||
~GolEffect();
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
bool can_be_shown_with_clock();
|
||||
String get_name() override { return "gol"; }
|
||||
};
|
32
include/effects/lightspeed.h
Normal file
32
include/effects/lightspeed.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "Effect.h"
|
||||
#include "my_fastled.h"
|
||||
|
||||
class LightspeedEffectStar {
|
||||
private:
|
||||
uint16_t _angle;
|
||||
accum88 _distance;
|
||||
uint16_t _speed;
|
||||
uint16_t _target;
|
||||
uint8_t _saturation;
|
||||
void _init();
|
||||
public:
|
||||
LightspeedEffectStar();
|
||||
void loop(Window* win);
|
||||
};
|
||||
|
||||
class LightspeedEffect : public Effect {
|
||||
private:
|
||||
LightspeedEffectStar* _stars;
|
||||
uint8_t _count;
|
||||
void _init();
|
||||
void _delete();
|
||||
public:
|
||||
LightspeedEffect();
|
||||
~LightspeedEffect();
|
||||
void loop(uint16_t ms);
|
||||
boolean can_be_shown_with_clock();
|
||||
String get_name() override { return "lightspeed"; }
|
||||
};
|
||||
|
@ -6,13 +6,13 @@
|
||||
|
||||
class MarqueeEffect : public Effect {
|
||||
private:
|
||||
Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
|
||||
Window* window = &Window::window_with_clock;
|
||||
String _text = String("No text set +++ ");
|
||||
saccum78 _position = (window->width<<8);
|
||||
public:
|
||||
boolean supports_window = true;
|
||||
boolean can_be_shown_with_clock();
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
void apply_option(String key, String value) override;
|
||||
String get_name() override { return "marquee"; }
|
||||
};
|
@ -9,7 +9,7 @@
|
||||
class MatrixEffectColumn {
|
||||
protected:
|
||||
Window* window;
|
||||
accum88 x, y;
|
||||
saccum78 x, y;
|
||||
uint8_t length = 1;
|
||||
uint8_t _direction = 2;
|
||||
bool _random_direction = false;
|
||||
@ -27,9 +27,9 @@ public:
|
||||
|
||||
MatrixEffectColumn(Window* win, uint8_t direction=0, bool random_direction=false);
|
||||
virtual ~MatrixEffectColumn() {};
|
||||
void advance();
|
||||
void advance(uint16_t ms);
|
||||
void draw();
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
};
|
||||
|
||||
class RainbowMatrixEffectColumn : public MatrixEffectColumn {
|
||||
@ -48,25 +48,58 @@ public:
|
||||
RandomMatrixEffectColumn(Window* win, uint8_t dir, bool rnd=false) : MatrixEffectColumn(win, dir, rnd) {};
|
||||
};
|
||||
|
||||
class MatrixEffect : public Effect {
|
||||
class ColumnMatrixEffectColumn : public MatrixEffectColumn {
|
||||
protected:
|
||||
uint8_t _hue;
|
||||
CRGB _getColor(uint8_t height) override;
|
||||
void restart(bool completely_random) override;
|
||||
public:
|
||||
ColumnMatrixEffectColumn(Window* win, uint8_t dir, bool rnd=false) : MatrixEffectColumn(win, dir, rnd) {};
|
||||
};
|
||||
|
||||
class MatrixEffectBase : public Effect {
|
||||
protected:
|
||||
MatrixEffectColumn** _columns;
|
||||
uint8_t _count;
|
||||
virtual uint8_t _get_count();
|
||||
virtual void _delete();
|
||||
void _init();
|
||||
virtual void _create() = 0;
|
||||
public:
|
||||
boolean can_be_shown_with_clock();
|
||||
virtual ~MatrixEffectBase();
|
||||
void loop(uint16_t ms);
|
||||
};
|
||||
|
||||
class MatrixEffect : public MatrixEffectBase {
|
||||
protected:
|
||||
void _create() override;
|
||||
public:
|
||||
MatrixEffect();
|
||||
virtual ~MatrixEffect();
|
||||
void loop();
|
||||
String get_name() override { return "matrix"; }
|
||||
};
|
||||
|
||||
class RainbowMatrixEffect : public MatrixEffect {
|
||||
class RainbowMatrixEffect : public MatrixEffectBase {
|
||||
protected:
|
||||
void _create() override;
|
||||
public:
|
||||
RainbowMatrixEffect();
|
||||
String get_name() override { return "rainbow_matrix"; }
|
||||
};
|
||||
|
||||
class RandomMatrixEffect : public MatrixEffect {
|
||||
class RandomMatrixEffect : public MatrixEffectBase {
|
||||
protected:
|
||||
uint8_t _get_count() override;
|
||||
void _create() override;
|
||||
public:
|
||||
RandomMatrixEffect();
|
||||
String get_name() override { return "random_matrix"; }
|
||||
};
|
||||
|
||||
class ColumnMatrixEffect : public MatrixEffectBase {
|
||||
protected:
|
||||
void _create() override;
|
||||
public:
|
||||
ColumnMatrixEffect();
|
||||
String get_name() override { return "column_matrix"; }
|
||||
};
|
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"; }
|
||||
};
|
@ -10,7 +10,7 @@ private:
|
||||
public:
|
||||
PixelClockEffect();
|
||||
~PixelClockEffect();
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
bool can_be_shown_with_clock();
|
||||
String get_name() override { return "pixel_clock"; }
|
||||
};
|
@ -4,6 +4,12 @@
|
||||
#include "functions.h"
|
||||
#include "Effect.h"
|
||||
|
||||
enum SinematrixColorScheme {
|
||||
SINEMATRIX_COLOR_PASTEL_RAINBOW,
|
||||
SINEMATRIX_COLOR_RAINBOW,
|
||||
SINEMATRIX_COLOR_PURPLEFLY,
|
||||
};
|
||||
|
||||
class Sinematrix3Effect : public Effect {
|
||||
private:
|
||||
double pangle = 0;
|
||||
@ -25,12 +31,14 @@ private:
|
||||
double fx = 1.0 / (LED_WIDTH / PI);
|
||||
double fy = 1.0 / (LED_HEIGHT / PI);
|
||||
Matrix rotate;
|
||||
SinematrixColorScheme _color_scheme;
|
||||
CRGB _get_color(int value);
|
||||
|
||||
public:
|
||||
Sinematrix3Effect(SinematrixColorScheme s = SINEMATRIX_COLOR_PASTEL_RAINBOW): _color_scheme(s) {};
|
||||
boolean supports_window = true;
|
||||
boolean can_be_shown_with_clock();
|
||||
boolean clock_as_mask();
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
String get_name() override { return "sinematrix3"; }
|
||||
};
|
||||
|
@ -6,28 +6,29 @@
|
||||
|
||||
class SinesEffectSinus {
|
||||
private:
|
||||
uint8_t _value;
|
||||
uint8_t _frequency;
|
||||
uint8_t _amplitude;
|
||||
uint8_t _x;
|
||||
uint8_t _step;
|
||||
uint16_t _frequency;
|
||||
uint16_t _color_frequency;
|
||||
uint16_t _amplitude;
|
||||
uint16_t _x;
|
||||
uint16_t _offset;
|
||||
Window* _window;
|
||||
CRGB _color;
|
||||
public:
|
||||
SinesEffectSinus(Window* w);
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
};
|
||||
|
||||
class SinesEffect : public Effect {
|
||||
private:
|
||||
SinesEffectSinus* _sinus[EFFECT_SINES_COUNT];
|
||||
uint8_t _step = 0;
|
||||
SinesEffectSinus** _sinus;
|
||||
uint8_t _count;
|
||||
void _init();
|
||||
void _delete();
|
||||
public:
|
||||
SinesEffect();
|
||||
~SinesEffect();
|
||||
boolean supports_window = true;
|
||||
boolean can_be_shown_with_clock();
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
String get_name() override { return "sines"; }
|
||||
};
|
||||
|
68
include/effects/snake.h
Normal file
68
include/effects/snake.h
Normal file
@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
#include "Effect.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
#define SNAKE_DIR_NORTH 0
|
||||
#define SNAKE_DIR_EAST 1
|
||||
#define SNAKE_DIR_SOUTH 2
|
||||
#define SNAKE_DIR_WEST 3
|
||||
|
||||
#define SNAKE_DEBUG false
|
||||
|
||||
class SnakeEffect : public Effect {
|
||||
private:
|
||||
Coords _pos;
|
||||
Coords _apple;
|
||||
Coords _tail;
|
||||
int8_t _dir = SNAKE_DIR_NORTH;
|
||||
uint8_t* _map;
|
||||
uint16_t _pixels;
|
||||
uint8_t _length;
|
||||
unsigned long _last_apple_at;
|
||||
unsigned long _last_move_at;
|
||||
uint16_t _round;
|
||||
|
||||
// Neural net config
|
||||
// These are actually float values. But in order to prevent rounding errors and stuff, they are provided
|
||||
// in form of the raw binary data of the IEE754 floating point numbers.
|
||||
// In _decide() there's code to memcpy()-convert them to a float.
|
||||
// Round 340, 223.4 points, length 39, 36% stopped, 64% died
|
||||
// const uint32_t _weights[36] = {0xbd8e626e, 0xbee2cd2c, 0x3e4d5cab, 0x3eceb8c3, 0xbed0a514, 0x3ec62438, 0x3e947ed4, 0xbe4b8bf2, 0xbf301113, 0xbf3f0a75, 0x3f1868f7, 0xbf0253ca, 0xbedca2f2, 0xbd547c6d, 0x3edd6a8a, 0xbd4b97b6, 0x3f64ec26, 0xbe5323c1, 0x3eccf87d, 0xbf2d4796, 0xbf62b6e8, 0xbf71daf6, 0xbf03f08e, 0xbf222609, 0x3e26c03c, 0xbf497837, 0xbee4d175, 0x3ec601de, 0x3e4e0695, 0x3eef2619, 0xbe849370, 0xbf18fb2b, 0x3f25bbd1, 0xbf3dcd78, 0x3f37a58d, 0x3ef4a25b};
|
||||
// Round 630, 221.0 points, length 38, 36% stopped, 64% died
|
||||
const uint32_t _weights[36] = {0xbd25943f, 0xbf279d81, 0x3e25d128, 0x3ec62438, 0x3f0e719c, 0x3eefbea9, 0x3e947ed4, 0xbe5323c1, 0xbf2d4796, 0xbf3f0a75, 0x3f0e45d9, 0xbf0253ca, 0xbedca2f2, 0xbd79073c, 0x3ede80ec, 0xbd4b97b6, 0x3f69a6be, 0xbe4b8bf2, 0x3eccf87d, 0xbf301113, 0xbf62b6e8, 0xbf71daf6, 0xbf204130, 0xbf222609, 0x3e26c03c, 0xbf497837, 0xbee4d175, 0x3ec601de, 0x3e4954eb, 0x3eef2619, 0xbe849370, 0xbf18fb2b, 0x3f25bbd1, 0xbf3b4e44, 0x3f484d59, 0x3edd6a8a};
|
||||
// Round 193, 164.8 points, length 36, 6% stopped, 94% died
|
||||
//const uint32_t _weights[36] = {0x3e872ffb, 0xbea57262, 0xbee269bf, 0x3ed790a3, 0xbf54014f, 0x3ecde0a6, 0xbf240a93, 0xbe9e4782, 0x3f205106, 0xbf4465c2, 0xbf79579a, 0xbf07f122, 0x3ed0e1bc, 0xbf7a5a09, 0xbf0fc70b, 0xbf6d1971, 0xbe0f5585, 0xbec94b12, 0x3f51f7a9, 0x3eaac42b, 0xbe6aafa6, 0x3d3e3ce3, 0xbf7c4232, 0xbe634103, 0x3f800000, 0x3eff886c, 0x3deae1e8, 0x3eea6988, 0xbf800000, 0xbf426a20, 0x3e3a0a45, 0xbe848803, 0x3e84e8c9, 0x3ef9fabc, 0xbe7733e6, 0xbecda633};
|
||||
// Round 13650, 244.8 points, length 42, 34% stopped, 66% died
|
||||
//const uint32_t _weights[36] = {0xbeb99de3, 0x3e6ca488, 0xbe3e9dad, 0xbed38d4e, 0x3f279fc1, 0xbd367111, 0xbf473843, 0xbf800000, 0x3f614edc, 0xbecc734f, 0xbe59b29d, 0x3d479078, 0x3efa7ca6, 0xbedc6ce6, 0x3f4626a1, 0x3e9d8c2c, 0x3f29e25c, 0x3ebde05d, 0x3e8f3e29, 0xbe8ad92c, 0xbe148f2d, 0x3d4a3ca7, 0xbf800000, 0x3d9cd634, 0x3f29802e, 0xbf2cc57e, 0xbcbfafff, 0x3e280b8a, 0x3f5ff9a3, 0xbf4e29c9, 0x3e8936d2, 0xbf49dda9, 0xbe9bf4c7, 0x3e203ea8, 0xbd4edf4d, 0xbf4e3c05};
|
||||
|
||||
const uint8_t _net_layout[3] = {6, 4, 3};
|
||||
const uint8_t _net_layers = 3;
|
||||
const uint8_t _net_total_size = 36;
|
||||
|
||||
uint8_t _head_rounds = 0;
|
||||
uint8_t _tail_rounds = 0;
|
||||
|
||||
|
||||
uint16_t _xy2i(uint8_t x, uint8_t y);
|
||||
uint16_t _xy2i(Coords c);
|
||||
Coords _i2xy(uint16_t i);
|
||||
Coords _new_pos(uint8_t dir);
|
||||
uint8_t _dying = 0;
|
||||
bool _is_free(uint8_t dir);
|
||||
uint8_t _free_spaces(uint8_t dir);
|
||||
uint8_t _to_apple(uint8_t dir);
|
||||
void _place_apple();
|
||||
void _init();
|
||||
void _decide();
|
||||
uint8_t _coords_to_field_id(Coords);
|
||||
int8_t _manual_decision();
|
||||
void _move();
|
||||
void _draw();
|
||||
public:
|
||||
SnakeEffect();
|
||||
~SnakeEffect();
|
||||
void loop(uint16_t ms);
|
||||
boolean can_be_shown_with_clock();
|
||||
String get_name() override { return "snake"; }
|
||||
};
|
@ -9,7 +9,7 @@ private:
|
||||
public:
|
||||
StaticEffect(CRGB col);
|
||||
boolean supports_window = true;
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
String get_name() override { return "static"; }
|
||||
};
|
||||
|
16
include/effects/timer.h
Normal file
16
include/effects/timer.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "Effect.h"
|
||||
#include "prototypes.h"
|
||||
#include "my_fastled.h"
|
||||
#include "Window.h"
|
||||
|
||||
class TimerEffect : public Effect {
|
||||
protected:
|
||||
Window* window = new Window(0, 0, LED_WIDTH, 6);
|
||||
|
||||
public:
|
||||
~TimerEffect();
|
||||
void loop(uint16_t ms);
|
||||
String get_name() override { return "timer"; }
|
||||
};
|
30
include/effects/tpm2_net.h
Normal file
30
include/effects/tpm2_net.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "Effect.h"
|
||||
#include "prototypes.h"
|
||||
#include "my_fastled.h"
|
||||
#include "Window.h"
|
||||
#include "config.h"
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
class Tpm2NetEffect : public Effect {
|
||||
protected:
|
||||
Window* window = &Window::window_full;
|
||||
WiFiUDP _udp;
|
||||
uint16_t _pixel_index = 0;
|
||||
|
||||
void _parse_command(uint16_t size, uint8_t packet_number);
|
||||
void _parse_data(uint16_t size, uint8_t packet_number);
|
||||
void _respond(uint8_t* data, uint8_t len);
|
||||
void _respond_ack();
|
||||
void _respond_with_data(uint8_t* data, uint8_t len);
|
||||
void _respond_unknown_command();
|
||||
unsigned long _last_packet_at = 0;
|
||||
|
||||
public:
|
||||
Tpm2NetEffect();
|
||||
virtual ~Tpm2NetEffect();
|
||||
virtual void loop(uint16_t ms);
|
||||
bool can_be_shown_with_clock();
|
||||
String get_name() override { return "tpm2.net"; }
|
||||
};
|
12
include/effects/tv_static.h
Normal file
12
include/effects/tv_static.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "Effect.h"
|
||||
|
||||
class TvStaticEffect : public Effect {
|
||||
private:
|
||||
Window* _window = &Window::window_with_clock;
|
||||
public:
|
||||
~TvStaticEffect();
|
||||
void loop(uint16_t ms) override;
|
||||
bool can_be_shown_with_clock() override;
|
||||
String get_name() override { return "tv_static"; }
|
||||
};
|
@ -10,7 +10,7 @@ private:
|
||||
double _real_center_x = LED_WIDTH / 2;
|
||||
double _real_center_y = LED_HEIGHT / 2;
|
||||
public:
|
||||
void loop();
|
||||
void loop(uint16_t ms);
|
||||
boolean can_be_shown_with_clock() override;
|
||||
boolean clock_as_mask() override;
|
||||
String get_name() override { return "twirl"; }
|
@ -2,6 +2,7 @@
|
||||
#include "prototypes.h"
|
||||
|
||||
extern Font font_numbers3x5;
|
||||
extern Font font_numbers3x3;
|
||||
extern Font font_numbers3x5_blocky;
|
||||
extern Font font_numbers4x7;
|
||||
extern Font font5x7;
|
||||
|
@ -5,15 +5,13 @@
|
||||
|
||||
#include "my_wifi.h"
|
||||
#include <FS.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
#if defined ( ESP8266 )
|
||||
extern ESP8266WebServer http_server;
|
||||
#elif defined ( ESP32 )
|
||||
extern ESP32WebServer http_server;
|
||||
#endif
|
||||
extern AsyncWebServer http_server;
|
||||
|
||||
extern File upload_file;
|
||||
extern uint32_t monitor_client;
|
||||
|
||||
void http_server_setup();
|
||||
void http_server_loop();
|
||||
void http_server_send_framedata();
|
||||
#endif
|
||||
|
@ -6,3 +6,4 @@
|
||||
|
||||
extern const TProgmemRGBGradientPalette_byte palette_fire[] FL_PROGMEM;
|
||||
extern const TProgmemRGBGradientPalette_byte palette_matrix[] FL_PROGMEM;
|
||||
extern const TProgmemRGBGradientPalette_byte palette_purplefly_gp[] FL_PROGMEM;
|
||||
|
@ -17,8 +17,8 @@ void mqtt_setup();
|
||||
|
||||
void mqtt_loop();
|
||||
|
||||
void mqtt_publish(const char* topic, int number);
|
||||
void mqtt_publish(const char* topic, const char* message);
|
||||
void mqtt_publish(const char* topic, int number, bool retain=false);
|
||||
void mqtt_publish(const char* topic, const char* message, bool retain=false);
|
||||
|
||||
void mqtt_log(const char* message);
|
||||
void mqtt_log(int number);
|
||||
|
@ -5,13 +5,11 @@
|
||||
#if defined( ESP8266 )
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#elif defined( ESP32 )
|
||||
#include <WiFi.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiServer.h>
|
||||
#include <ESP32WebServer.h>
|
||||
#endif
|
||||
|
||||
#include <WiFiUdp.h>
|
||||
|
@ -1,9 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <NTPClient.h>
|
||||
#include "my_wifi.h"
|
||||
#include "config.h"
|
||||
|
||||
extern NTPClient ntpClient;
|
||||
void updateCallback(NTPClient* c);
|
||||
void time_changed();
|
||||
void ntp_setup();
|
||||
|
@ -1,6 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "my_fastled.h"
|
||||
|
||||
extern uint8_t baseHue;
|
||||
extern char hostname[30];
|
||||
extern uint16_t frame;
|
||||
extern unsigned long timer;
|
||||
|
||||
typedef struct {
|
||||
uint8_t width;
|
||||
@ -27,5 +33,4 @@ typedef struct {
|
||||
uint16_t y;
|
||||
} Coords;
|
||||
|
||||
extern uint8_t baseHue;
|
||||
extern char hostname[30];
|
||||
typedef std::function<double(double, uint16_t, uint8_t, uint8_t)> simple_effect_t;
|
@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
#include "my_wifi.h"
|
||||
#include "config.h"
|
||||
#include <ESPAsyncTCP.h>
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
#ifdef RECORDER_ENABLE
|
||||
class Recorder {
|
||||
private:
|
||||
WiFiUDP _udp;
|
||||
AsyncServer* _server;
|
||||
AsyncClient* _client = NULL;
|
||||
uint16_t _client_port = 0;
|
||||
size_t _buffer_len;
|
||||
char* _buffer;
|
||||
uint16_t _msgid;
|
||||
boolean _skip_next_frame = false;
|
||||
public:
|
||||
Recorder();
|
||||
void loop();
|
||||
};
|
||||
#endif
|
104
include/settings.h
Normal file
104
include/settings.h
Normal file
@ -0,0 +1,104 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
enum SettingType {
|
||||
TYPE_UINT8,
|
||||
TYPE_UINT16,
|
||||
TYPE_BOOL
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
const char* name;
|
||||
uint16_t* value;
|
||||
SettingType type;
|
||||
} Setting;
|
||||
|
||||
struct Settings {
|
||||
uint16_t fps = 50;
|
||||
|
||||
struct /* effects */ {
|
||||
struct /* cycle */ {
|
||||
uint16_t time = 300;
|
||||
uint16_t random = 1;
|
||||
} cycle ;
|
||||
|
||||
struct /* matrix */ {
|
||||
uint16_t length_min = 4;
|
||||
uint16_t length_max = 20;
|
||||
uint16_t speed_min = 3;
|
||||
uint16_t speed_max = 7;
|
||||
uint16_t count = 16;
|
||||
uint16_t random_count = 32;
|
||||
} matrix;
|
||||
|
||||
struct /* big_clock */ {
|
||||
uint16_t spacing = 5;
|
||||
} big_clock;
|
||||
|
||||
struct /* blur2d */ {
|
||||
uint16_t count = 5;
|
||||
} blur2d;
|
||||
|
||||
struct /* confetti */ {
|
||||
uint16_t pixels_per_loop = 2;
|
||||
} confetti;
|
||||
|
||||
struct /* dvd */ {
|
||||
uint16_t width = 3;
|
||||
uint16_t height = 2;
|
||||
uint16_t speed = 50;
|
||||
} dvd;
|
||||
|
||||
struct /* dynamic */ {
|
||||
uint16_t single_loop_time = 40;
|
||||
uint16_t multi_loop_time = 1400;
|
||||
uint16_t big_loop_time = 50;
|
||||
uint16_t big_size = 3;
|
||||
} dynamic;
|
||||
|
||||
struct /* fire */ {
|
||||
uint16_t cooldown = 192;
|
||||
uint16_t spark_chance = 5;
|
||||
} fire;
|
||||
|
||||
struct /* firework */ {
|
||||
uint16_t drag = 255;
|
||||
uint16_t bounce = 200;
|
||||
uint16_t gravity = 10;
|
||||
uint16_t sparks = 12;
|
||||
} firework;
|
||||
|
||||
struct /* gol */ {
|
||||
uint16_t start_percentage = 90;
|
||||
uint16_t blend_speed = 10;
|
||||
uint16_t restart_after_steps = 100;
|
||||
} gol;
|
||||
|
||||
struct /* lightspeed */ {
|
||||
uint16_t count = 25;
|
||||
} lightspeed;
|
||||
|
||||
struct /* sines */ {
|
||||
uint16_t count = 5;
|
||||
} sines;
|
||||
|
||||
struct /* snake */ {
|
||||
uint16_t direction_change = 5;
|
||||
uint16_t slowdown = 2;
|
||||
} snake;
|
||||
|
||||
struct /* tv_static */ {
|
||||
uint16_t black_bar_speed = 12;
|
||||
} tv_static;
|
||||
} effects;
|
||||
};
|
||||
|
||||
extern Settings settings;
|
||||
extern Setting all_settings[];
|
||||
extern const uint8_t all_settings_size;
|
||||
|
||||
bool change_setting(const char* key, uint16_t new_value);
|
||||
uint16_t setting_default(Setting* s);
|
||||
bool save_settings();
|
||||
bool load_settings();
|
@ -10,32 +10,31 @@
|
||||
|
||||
[platformio]
|
||||
lib_dir = lib
|
||||
env_default = ota
|
||||
default_envs = ota
|
||||
|
||||
[extra]
|
||||
lib_deps =
|
||||
PubSubClient
|
||||
https://github.com/fabianonline/FastLED.git
|
||||
https://github.com/fabianonline/NTPClient.git
|
||||
ESP8266WebServer
|
||||
ErriezCRC32
|
||||
ESPAsyncTCP
|
||||
https://github.com/me-no-dev/ESPAsyncWebServer.git
|
||||
|
||||
[env:ota]
|
||||
upload_port = 10.10.2.78
|
||||
upload_port = 10.10.2.78 ; .78=prod, .80=dev
|
||||
upload_protocol = espota
|
||||
platform = espressif8266
|
||||
board = esp07
|
||||
framework = arduino
|
||||
lib_deps = ${extra.lib_deps}
|
||||
lib_ldf_mode = chain+
|
||||
lib_ldf_mode = deep
|
||||
build_flags = -Wl,-Teagle.flash.2m512.ld
|
||||
|
||||
[env:local]
|
||||
upload_port = /dev/cu.wchusbserial1420
|
||||
upload_port = /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0
|
||||
platform = espressif8266
|
||||
board = esp07
|
||||
framework = arduino
|
||||
lib_deps = ${extra.lib_deps}
|
||||
lib_ldf_mode = chain+
|
||||
lib_ldf_mode = deep
|
||||
build_flags = -Wl,-Teagle.flash.2m512.ld
|
||||
monitor_filters = time, esp8266_exception_decoder
|
||||
build_type = debug
|
||||
|
@ -75,7 +75,7 @@ bool Animation::_load_from_file(const char* filename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file.available() != size - 6) {
|
||||
if (file.available() < 0 || file.available() + 6 != size) {
|
||||
LOGln("Animation * Expected file to have %d bytes available, but found %d bytes available.", size - 6, file.available());
|
||||
file.close();
|
||||
return false;
|
||||
@ -84,16 +84,16 @@ bool Animation::_load_from_file(const char* filename) {
|
||||
// Now we can be sure to have the right amount of bytes available for reading
|
||||
|
||||
_width = file.read();
|
||||
LOGln("Animation * width: %d", _width);
|
||||
DBG("Animation * width: %d", _width);
|
||||
_height = file.read();
|
||||
LOGln("Animation * height: %d", _height);
|
||||
DBG("Animation * height: %d", _height);
|
||||
|
||||
_frame_count = file.read();
|
||||
LOGln("Animation * frame_count: %d", _frame_count);
|
||||
DBG("Animation * frame_count: %d", _frame_count);
|
||||
_color_count = file.read();
|
||||
LOGln("Animation * color_count: %d", _color_count);
|
||||
DBG("Animation * color_count: %d", _color_count);
|
||||
|
||||
LOGln("Animation * Loading colors...");
|
||||
DBG("Animation * Loading colors...");
|
||||
_colors = new CRGB*[_color_count];
|
||||
char* temp = new char[_color_count*3];
|
||||
int bytes_read = file.readBytes(temp, _color_count*3);
|
||||
@ -102,36 +102,33 @@ bool Animation::_load_from_file(const char* filename) {
|
||||
_colors[i] = new CRGB(temp[i*3], temp[i*3+1], temp[i*3+2]);
|
||||
}
|
||||
delete [] temp;
|
||||
LOGln("Animation * Color loading done.");
|
||||
DBG("Animation * Color loading done.");
|
||||
|
||||
LOG("Animation * Loading frame times...");
|
||||
DBG("Animation * Loading frame times...");
|
||||
_frame_times = new uint16_t[_frame_count];
|
||||
for (int i=0; i<_frame_count; i++) {
|
||||
_frame_times[i] = (file.read() << 8) | file.read();
|
||||
}
|
||||
LOGln(" done.");
|
||||
DBG(" done.");
|
||||
|
||||
LOGln("Animation * Loading frame lengths...");
|
||||
DBG("Animation * Loading frame lengths...");
|
||||
_frame_data_lengths = new uint16_t[_frame_count];
|
||||
temp = new char[_frame_count*2];
|
||||
bytes_read = file.readBytes(temp, _frame_count*2);
|
||||
LOGln("Animation * Read %d bytes.", bytes_read);
|
||||
DBG("Animation * Read %d bytes.", bytes_read);
|
||||
for (int i=0; i<_frame_count; i++) {
|
||||
//LOGln("Animation * Raw frame lengths: %d, %d", temp[i*2], temp[i*2+1]);
|
||||
_frame_data_lengths[i] = (temp[i*2]<<8) | temp[i*2+1];
|
||||
}
|
||||
delete [] temp;
|
||||
LOGln("Animation * Frame length loading done.");
|
||||
DBG("Animation * Frame length loading done.");
|
||||
|
||||
LOGln("Animation * Loading frame data...");
|
||||
DBG("Animation * Loading frame data...");
|
||||
_frame_data = new uint8_t*[_frame_count];
|
||||
for (int i=0; i<_frame_count; i++) {
|
||||
uint16_t fl = _frame_data_lengths[i];
|
||||
LOGln("Animation * Loading frame %d with %d bytes...", i, fl);
|
||||
DBG("Animation * Loading frame %d/%d with %d bytes...", i, _frame_count, fl);
|
||||
_frame_data[i] = new uint8_t[fl];
|
||||
/*for (int b=0; b<fl; b++) {
|
||||
_frame_data[i][b] = file.read();
|
||||
}*/
|
||||
file.readBytes((char*)_frame_data[i], fl);
|
||||
}
|
||||
LOGln("Animation * Frame data loaded.");
|
||||
@ -207,27 +204,27 @@ void Animation::setSingleFrame(uint8_t frame) {
|
||||
|
||||
Animation::~Animation() {
|
||||
for (int i=0; i<_color_count; i++) delete _colors[i];
|
||||
LOGln("Deleting _colors...");
|
||||
if (_colors) delete [] _colors;
|
||||
LOGln("Deleting fgColor...");
|
||||
|
||||
DBG("Animation * Deleting _colors...");
|
||||
if (_colors) delete[] _colors;
|
||||
|
||||
DBG("Animation * Deleting fgColor...");
|
||||
if (fgColor != NULL) delete fgColor;
|
||||
LOGln("Deleting bgColor...");
|
||||
|
||||
DBG("Animation * Deleting bgColor...");
|
||||
if (bgColor != NULL) delete bgColor;
|
||||
LOGln("Deleting _frame_data_lengths...");
|
||||
|
||||
if (_frame_data_lengths) delete [] _frame_data_lengths;
|
||||
LOGln("Deleting _frame_times...");
|
||||
DBG("Animation * Deleting _frame_data_lengths...");
|
||||
if (_frame_data_lengths) delete[] _frame_data_lengths;
|
||||
|
||||
if (_frame_times) delete [] _frame_times;
|
||||
DBG("Animation * Deleting _frame_times...");
|
||||
if (_frame_times) delete[] _frame_times;
|
||||
for (int i=0; i<_frame_count; i++) {
|
||||
delete [] _frame_data[i];
|
||||
delete[] _frame_data[i];
|
||||
}
|
||||
LOGln("Deleting _frame_data...");
|
||||
|
||||
if (_frame_data) delete [] _frame_data;
|
||||
LOGln("Deleteion done.");
|
||||
DBG("Animation * Deleting _frame_data...");
|
||||
if (_frame_data) delete[] _frame_data;
|
||||
LOGln("Animation * Deletion done.");
|
||||
}
|
||||
|
||||
void Animation::draw() {
|
||||
|
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,10 +1,9 @@
|
||||
#include "Window.h"
|
||||
#include "functions.h"
|
||||
|
||||
Window* Window::getFullWindow() {
|
||||
static Window win;
|
||||
return &win;
|
||||
}
|
||||
Window Window::window_full = Window();
|
||||
Window Window::window_with_clock = Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
|
||||
Window Window::window_clock = Window(0, LED_HEIGHT-6, LED_WIDTH, 6);
|
||||
|
||||
void Window::setPixel(uint8_t x, uint8_t y, CRGB* color) {
|
||||
if (x>=this->width || y>=this->height) return;
|
||||
@ -42,13 +41,13 @@ void Window::clear(CRGB* color) {
|
||||
}
|
||||
|
||||
void Window::drawText(Font* font, uint16_t x, uint16_t y, String text, CRGB* color) {
|
||||
for (int i=0; i<text.length(); i++) {
|
||||
drawChar(font, (x+(i*(font->width + 1))<<8), (y<<8), text[i], color);
|
||||
for (uint16_t i=0; i<text.length(); i++) {
|
||||
drawChar(font, (x+((i*(font->width + 1))<<8)), (y<<8), text[i], color);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::drawSubText(Font* font, accum88 x, accum88 y, String text, CRGB* color) {
|
||||
for (int i=0; i<text.length(); i++) {
|
||||
for (uint16_t i=0; i<text.length(); i++) {
|
||||
drawChar(font, x+(i*((font->width + 1)<<8)), y, text[i], color);
|
||||
}
|
||||
}
|
||||
@ -150,26 +149,29 @@ void Window::fadeToBlackBy(fract8 speed) {
|
||||
}
|
||||
}
|
||||
|
||||
void Window::line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, CRGB* color) {
|
||||
void Window::line(saccum78 x1, saccum78 y1, saccum78 x2, saccum78 y2, CRGB* color) {
|
||||
// Bresenham algorithm
|
||||
int dx = x2-x1;
|
||||
int dy = y2-y1;
|
||||
|
||||
int x = x1;
|
||||
int y = y1;
|
||||
|
||||
int p = 2*dy - dx;
|
||||
|
||||
while (x < x2) {
|
||||
if (p >= 0) {
|
||||
setPixel(x, y, color);
|
||||
y++;
|
||||
p = p + 2*dy - 2*dx;
|
||||
} else {
|
||||
setPixel(x, y, color);
|
||||
p = p + 2*dy;
|
||||
const uint8_t stepsize = 64;
|
||||
saccum78 dx = abs(x2 - x1);
|
||||
saccum78 dy = -abs(y2 - y1);
|
||||
int8_t sx = x1<x2 ? 1 : -1;
|
||||
int8_t sy = y1<y2 ? 1 : -1;
|
||||
saccum78 err = dx + dy;
|
||||
saccum78 e2;
|
||||
uint8_t step = 0;
|
||||
while (1) {
|
||||
if (step == 0) setSubPixel(x1, y1, color, SUBPIXEL_RENDERING_RAISE);
|
||||
if (++step >= stepsize) step=0;
|
||||
if (x1>>8==x2>>8 && y1>>8==y2>>8) break;
|
||||
e2 = 2*err;
|
||||
if (e2 > dy) {
|
||||
err += dy;
|
||||
x1 += sx;
|
||||
}
|
||||
if (e2 < dx) {
|
||||
err += dx;
|
||||
y1 += sy;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,22 +203,28 @@ void Window::circle(uint8_t x0, uint8_t y0, uint8_t radius, CRGB* color) {
|
||||
}
|
||||
}
|
||||
|
||||
void Window::lineWithAngle(uint8_t x, uint8_t y, uint8_t angle, uint8_t length, CRGB* color) {
|
||||
void Window::lineWithAngle(uint8_t x, uint8_t y, uint16_t angle, uint8_t length, CRGB* color) {
|
||||
lineWithAngle(x, y, angle, 0, length, color);
|
||||
}
|
||||
|
||||
void Window::lineWithAngle(uint8_t x, uint8_t y, uint8_t angle, uint8_t startdist, uint8_t length, CRGB* color) {
|
||||
int16_t x1 = x;
|
||||
int16_t y1 = y;
|
||||
void Window::lineWithAngle(uint8_t x, uint8_t y, uint16_t angle, uint8_t startdist, uint8_t length, CRGB* color) {
|
||||
//LOGln("lineWithAngle called. x: %d.%03d, y: %d.%03d, angle: %d", x>>8, x&0xFF, y>>8, y&0xFF, angle);
|
||||
saccum78 x1 = x<<8;
|
||||
saccum78 y1 = y<<8;
|
||||
|
||||
if (startdist > 0) {
|
||||
x1 = x + scale8(startdist, cos8(angle));
|
||||
y1 = y + scale8(startdist, sin8(angle));
|
||||
x1 = (x<<8) + (startdist<<8) * cos16(angle) / 0x10000;
|
||||
y1 = (y<<8) + (startdist<<8) * sin16(angle) / 0x10000;
|
||||
}
|
||||
|
||||
int16_t x2 = x + scale8(startdist + length, cos8(angle));
|
||||
int16_t y2 = y + scale8(startdist + length, sin8(angle));
|
||||
if (length==0) {
|
||||
setSubPixel(x1, y1, color);
|
||||
return;
|
||||
}
|
||||
|
||||
saccum78 x2 = (x<<8) + ((startdist + length)<<8) * cos16(angle) / 0x10000;
|
||||
saccum78 y2 = (y<<8) + ((startdist + length)<<8) * sin16(angle) / 0x10000;
|
||||
//LOGln("x1: %d.%03d, y1: %d.%03d, x2: %d.%03d, y2: %d.%03d", x1>>8, x1&0xFF, y1>>8, y1&0xFF, x2>>8, x2&0xFF, y2>>8, y2&0xFF);
|
||||
line(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
@ -264,3 +272,14 @@ void Window::_subpixel_render(uint8_t x, uint8_t y, CRGB* color, SubpixelRenderi
|
||||
case SUBPIXEL_RENDERING_SET: setPixel(x, y, color); break;
|
||||
}
|
||||
}
|
||||
|
||||
void Window::fill_with_checkerboard() {
|
||||
CRGB pink(0xFF00FF);
|
||||
CRGB black(0x000000);
|
||||
uint8_t s = (uint8_t)(millis() / 1000);
|
||||
for(int x=0; x<this->width; x++) {
|
||||
for(int y=0; y<this->height; y++) {
|
||||
this->setPixel(x, y, ((x+y+s) % 2)?&pink:&black);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,3 +9,14 @@ __attribute__ ((aligned(4))) extern const TProgmemRGBGradientPalette_byte palett
|
||||
__attribute__ ((aligned(4))) extern const TProgmemRGBGradientPalette_byte palette_matrix[] FL_PROGMEM = {
|
||||
0, 0, 0, 0, // black
|
||||
255, 0,255, 0 }; // green
|
||||
|
||||
// Gradient palette "purplefly_gp", originally from
|
||||
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/rc/tn/purplefly.png.index.html
|
||||
// converted for FastLED with gammas (2.6, 2.2, 2.5)
|
||||
// Size: 16 bytes of program space.
|
||||
|
||||
__attribute__ ((aligned(4))) extern const TProgmemRGBGradientPalette_byte palette_purplefly_gp[] FL_PROGMEM = {
|
||||
0, 0, 0, 0,
|
||||
63, 239, 0,122,
|
||||
191, 252,255, 78,
|
||||
255, 0, 0, 0};
|
||||
|
@ -1,23 +0,0 @@
|
||||
#include "effect_analogclock.h"
|
||||
#include "my_fastled.h"
|
||||
#include "ntp.h"
|
||||
|
||||
void AnalogClockEffect::loop() {
|
||||
window->clear();
|
||||
CRGB white(0xFFFFFF);
|
||||
CRGB red(0xFF0000);
|
||||
window->circle(8, 8, 7, &white);
|
||||
|
||||
uint8_t seconds = ntpClient.getSeconds();
|
||||
uint8_t angle = 6 * seconds;
|
||||
window->lineWithAngle(8, 8, angle, 0, 10, &red);
|
||||
/*for (uint8_t i=0; i<=12; i++) {
|
||||
window->lineWithAngle(8, 8, 255/12*i, 5, 2, &white);
|
||||
}
|
||||
|
||||
uint8_t minutes = ntpClient.getMinutes();
|
||||
uint8_t hours = ntpClient.getHours();
|
||||
|
||||
window->lineWithAngle(8, 8, 255/60*minutes, 6, &white);
|
||||
window->lineWithAngle(8, 8, 255/12*(hours % 12), 4, &white);*/
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
#include "effect_animation.h"
|
||||
#include "functions.h"
|
||||
|
||||
AnimationEffect::AnimationEffect(const char* name, uint32_t bg, int x, int y) {
|
||||
this->name = name;
|
||||
this->xOffset = x;
|
||||
this->yOffset = y;
|
||||
|
||||
this->animation = new Animation(name, window);
|
||||
this->animation->setBgColor(bg);
|
||||
this->animation->setOffsets(this->xOffset, this->yOffset);
|
||||
}
|
||||
|
||||
AnimationEffect* AnimationEffect::setFgColor(uint32_t c) {
|
||||
animation->setFgColor(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
AnimationEffect::~AnimationEffect() {
|
||||
delete this->animation;
|
||||
}
|
||||
|
||||
void AnimationEffect::loop() {
|
||||
this->animation->drawFrame();
|
||||
this->animation->advance();
|
||||
}
|
||||
|
||||
String AnimationEffect::get_name() {
|
||||
String s = "animation/";
|
||||
s += this->name;
|
||||
return s;
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
#include "Effect.h"
|
||||
#include "effect_big_clock.h"
|
||||
#include "fonts.h"
|
||||
#include "ntp.h"
|
||||
|
||||
void BigClockEffect::loop() {
|
||||
window->clear();
|
||||
uint8_t h = ntpClient.getHours();
|
||||
window->drawChar(&font_numbers3x5_blocky, 6<<8, 2<<8, '0' + (h / 10), &_color_font);
|
||||
window->drawChar(&font_numbers3x5_blocky, 11<<8, 2<<8, '0' + (h % 10), &_color_font);
|
||||
|
||||
uint8_t m = ntpClient.getMinutes();
|
||||
window->drawChar(&font_numbers3x5_blocky, 6<<8, 9<<8, '0' + (m / 10), &_color_font);
|
||||
window->drawChar(&font_numbers3x5_blocky, 11<<8, 9<<8, '0' + (m % 10), &_color_font);
|
||||
|
||||
uint8_t s = ntpClient.getSeconds();
|
||||
if (s & 1) {
|
||||
window->setPixel(3, 10, &_color_font);
|
||||
window->setPixel(3, 12, &_color_font);
|
||||
}
|
||||
|
||||
_draw_seconds();
|
||||
}
|
||||
|
||||
void BigClockEffect::_draw_seconds() {
|
||||
uint8_t seconds = ntpClient.getSeconds();
|
||||
for (int i=1; i<=seconds; i++) {
|
||||
_draw_border_pixel(i, &_color_seconds);
|
||||
}
|
||||
uint16_t millis = ntpClient.getEpochMillis() % 1000;
|
||||
if (millis > 0) {
|
||||
uint8_t part = 60 - ((60 - seconds) * millis / 1000);
|
||||
_draw_border_pixel(part, &_color_seconds);
|
||||
}
|
||||
}
|
||||
|
||||
void BigClockEffect::_draw_border_pixel(uint8_t i, CRGB* color) {
|
||||
uint8_t x, y;
|
||||
if (i<=8) {
|
||||
x = 7 + i;
|
||||
y = 0;
|
||||
} else if (i<=23) {
|
||||
x = 15;
|
||||
y = i - 8;
|
||||
} else if (i<= 38) {
|
||||
x = 15 - i + 23;
|
||||
y = 15;
|
||||
} else if (i <= 53) {
|
||||
x = 0;
|
||||
y = 15 - i + 38;
|
||||
} else {
|
||||
x = i - 53;
|
||||
y = 0;
|
||||
}
|
||||
window->setPixel(x, y, color);
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
#include "effect_blur2d.h"
|
||||
|
||||
boolean Blur2DEffect::can_be_shown_with_clock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Blur2DEffect::loop() {
|
||||
uint8_t blur_amount = dim8_raw(beatsin8(3, 128, 224));
|
||||
window->blur(blur_amount);
|
||||
|
||||
uint8_t x1 = beatsin8(7, 0, window->width-1);
|
||||
uint8_t y1 = beatsin8(11, 0, window->height-1);
|
||||
|
||||
uint8_t x2 = beatsin8(13, 0, window->width-1);
|
||||
uint8_t y2 = beatsin8(8, 0, window->height-1);
|
||||
|
||||
uint8_t x3 = beatsin8(11, 0, window->width-1);
|
||||
uint8_t y3 = beatsin8(13, 0, window->height-1);
|
||||
|
||||
uint16_t ms = millis();
|
||||
CRGB c1 = CHSV(ms / 29, 200, 255);
|
||||
CRGB c2 = CHSV(ms / 41, 200, 255);
|
||||
CRGB c3 = CHSV(ms / 73, 200, 255);
|
||||
window->addPixelColor(x1, y1, &c1);
|
||||
window->addPixelColor(x2, y2, &c2);
|
||||
window->addPixelColor(x3, y3, &c3);
|
||||
}
|
||||
|
||||
Blur2DEffect::~Blur2DEffect() {
|
||||
delete window;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#include "effect_confetti.h"
|
||||
#include "config.h"
|
||||
#include "functions.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
void ConfettiEffect::loop() {
|
||||
window->fadeToBlackBy(3);
|
||||
for (int i=0; i<EFFECT_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,60 +0,0 @@
|
||||
#include "effect_cycle.h"
|
||||
#include "effects.h"
|
||||
#include <ErriezCRC32.h>
|
||||
|
||||
CycleEffect::CycleEffect() {
|
||||
changeEffect();
|
||||
}
|
||||
|
||||
CycleEffect::~CycleEffect() {
|
||||
delete effect;
|
||||
}
|
||||
|
||||
void CycleEffect::changeEffect() {
|
||||
int new_id;
|
||||
if (EFFECT_CYCLE_RANDOM) {
|
||||
do {
|
||||
new_id = random8(cycle_effects_count);
|
||||
} while (new_id == effect_id);
|
||||
} else {
|
||||
new_id = (effect_id + 1) % cycle_effects_count;
|
||||
}
|
||||
LOGln("CycleEffect * Changing effect from #%d to #%d", effect_id, new_id);
|
||||
delay(25);
|
||||
if (effect) delete effect;
|
||||
LOGln("CycleEffect * Searching for new effect '%s'", cycle_effects[new_id]);
|
||||
delay(25);
|
||||
effect = select_effect( crc32String(cycle_effects[new_id]) );
|
||||
if (effect) {
|
||||
effect_id = new_id;
|
||||
effectSince = millis();
|
||||
LOGln("CycleEffect * Effect %s found", effect->get_name().c_str());
|
||||
} else {
|
||||
LOGln("CycleEffect * Effect NOT found");
|
||||
}
|
||||
}
|
||||
|
||||
boolean CycleEffect::can_be_shown_with_clock() {
|
||||
return effect->can_be_shown_with_clock();
|
||||
};
|
||||
boolean CycleEffect::clock_as_mask() {
|
||||
return effect->clock_as_mask();
|
||||
};
|
||||
|
||||
void CycleEffect::loop() {
|
||||
if (!effect) changeEffect(); // If this is the first run, we have to select an effect first!
|
||||
effect->loop();
|
||||
// Don't use EVERY_N_SECONDS(config_effect_cycle_time) here because that function isn't relly made
|
||||
// to be used with changing values.
|
||||
EVERY_N_SECONDS(1) {
|
||||
if (effectSince + EFFECT_CYCLE_TIME*1000 < millis()) {
|
||||
changeEffect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String CycleEffect::get_name() {
|
||||
String s = "cycle/";
|
||||
s += effect->get_name();
|
||||
return s;
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
#include "effect_dvd.h"
|
||||
#include "my_fastled.h"
|
||||
|
||||
void DvdEffect::loop() {
|
||||
bool dir_changed = false;
|
||||
EVERY_N_MILLISECONDS( 250 ) {
|
||||
_x += _x_dir;
|
||||
_y += _y_dir;
|
||||
|
||||
if (_x == 0 || _x + EFFECT_DVD_WIDTH >= window->width) {
|
||||
_x_dir = -_x_dir;
|
||||
dir_changed = true;
|
||||
}
|
||||
if (_y == 0 || _y + EFFECT_DVD_HEIGHT >= window->height) {
|
||||
_y_dir = -_y_dir;
|
||||
dir_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
window->clear();
|
||||
|
||||
for (int x=0; x<EFFECT_DVD_WIDTH; x++) for (int y=0; y<EFFECT_DVD_HEIGHT; y++) {
|
||||
window->setPixel(_x + x, _y + y, (CRGB*)&_color);
|
||||
}
|
||||
|
||||
if (dir_changed) _color = (CRGB)CHSV(random8(), 255, 255);
|
||||
}
|
||||
|
||||
bool DvdEffect::can_be_shown_with_clock() { return true; }
|
||||
|
||||
DvdEffect::DvdEffect() {
|
||||
_color = CHSV(random8(), 255, 255);
|
||||
}
|
||||
|
||||
DvdEffect::~DvdEffect() {
|
||||
delete window;
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
#include "effect_dynamic.h"
|
||||
#include "functions.h"
|
||||
#include "config.h"
|
||||
|
||||
SingleDynamicEffect::SingleDynamicEffect() {
|
||||
init();
|
||||
}
|
||||
|
||||
void SingleDynamicEffect::init() {
|
||||
for (int i=0; i<tile_count; i++) tiles[i] = CHSV(baseHue + random8(64), 180, 255);
|
||||
}
|
||||
|
||||
void SingleDynamicEffect::loop() {
|
||||
EVERY_N_MILLISECONDS( EFFECT_SINGLE_DYNAMIC_LOOP_TIME ) {
|
||||
tiles[random8(tile_count)] = CHSV(baseHue + random8(64), 180, 255);
|
||||
}
|
||||
this->draw();
|
||||
}
|
||||
|
||||
void SingleDynamicEffect::draw() {
|
||||
for (int x=0; x<window->width; x++) for (int y=0; y<window->height; y++) {
|
||||
int index = y/2 * window->width/2 + x/2;
|
||||
window->setPixel(x, y, &tiles[index]);
|
||||
}
|
||||
}
|
||||
|
||||
boolean SingleDynamicEffect::can_be_shown_with_clock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void MultiDynamicEffect::loop() {
|
||||
EVERY_N_MILLISECONDS( EFFECT_MULTI_DYNAMIC_LOOP_TIME ) {
|
||||
for (int i=0; i<tile_count; i++) tiles[i] = CHSV(baseHue + random8(64), 180, 255);
|
||||
}
|
||||
this->draw();
|
||||
}
|
||||
|
||||
BigDynamicEffect::~BigDynamicEffect() {
|
||||
delete window;
|
||||
}
|
||||
|
||||
void BigDynamicEffect::loop() {
|
||||
EVERY_N_MILLISECONDS( EFFECT_BIG_DYNAMIC_LOOP_TIME ) {
|
||||
uint8_t x = random8(0, window->width - EFFECT_BIG_DYNAMIC_SIZE + 1);
|
||||
uint8_t y = random8(0, window->height - EFFECT_BIG_DYNAMIC_SIZE + 1);
|
||||
CRGB color = CHSV(random8(), 255, 255);
|
||||
CRGB black(0x000000);
|
||||
|
||||
for (uint8_t ix=0; ix<EFFECT_BIG_DYNAMIC_SIZE; ix++) for (uint8_t iy=0; iy<EFFECT_BIG_DYNAMIC_SIZE; iy++) {
|
||||
window->setPixel(x+ix, y+iy, &color);
|
||||
}
|
||||
/*for (uint8_t ix=0; ix<EFFECT_BIG_DYNAMIC_SIZE+2; ix++) {
|
||||
window->setPixel(x-1+ix, y-1, &black);
|
||||
window->setPixel(x-1+ix, y+EFFECT_BIG_DYNAMIC_SIZE+1, &black);
|
||||
}
|
||||
for (uint8_t iy=0; iy<EFFECT_BIG_DYNAMIC_SIZE+2; iy++) {
|
||||
window->setPixel(x-1, y-1+iy, &black);
|
||||
window->setPixel(x+EFFECT_BIG_DYNAMIC_SIZE+1, y-1+iy, &black);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
boolean BigDynamicEffect::can_be_shown_with_clock() {
|
||||
return true;
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
#include "effect_sines.h"
|
||||
|
||||
SinesEffectSinus::SinesEffectSinus(Window* w) {
|
||||
_window = w;
|
||||
_frequency = random8(40)+8;
|
||||
_amplitude = random(5)+2;
|
||||
_x = random8(_window->width);
|
||||
_step = 0;
|
||||
_color = CHSV(random8(), 255, 255);
|
||||
}
|
||||
|
||||
void SinesEffectSinus::loop() {
|
||||
_value += _frequency;
|
||||
if ((_value == 0 || _value==128) && random8(16)==0) {
|
||||
int8_t sign = _value == 0 ? -1 : +1;
|
||||
if (_x > 200) sign = -1;
|
||||
else if (_x >= _window->width) sign = 1;
|
||||
_amplitude = random(3)+2;
|
||||
_frequency = random8(40)+8;
|
||||
_color = CHSV(random8(), 255, 255);
|
||||
_x = _x - sign*_amplitude;
|
||||
}
|
||||
uint8_t x = _x + ((sin8(_value) - 128) * _amplitude / 128);
|
||||
_window->setPixel(x, 0, &_color);
|
||||
}
|
||||
|
||||
SinesEffect::SinesEffect() {
|
||||
for (int i=0; i<EFFECT_SINES_COUNT; i++) {
|
||||
_sinus[i] = new SinesEffectSinus(window);
|
||||
}
|
||||
}
|
||||
|
||||
SinesEffect::~SinesEffect() {
|
||||
for (int i=0; i<EFFECT_SINES_COUNT; i++) { delete _sinus[i]; }
|
||||
}
|
||||
|
||||
boolean SinesEffect::can_be_shown_with_clock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SinesEffect::loop() {
|
||||
// do stuff
|
||||
if (_step++ % 4) return; // Skip 3 out of 4 steps.
|
||||
window->shift_down_and_blur();
|
||||
for (int i=0; i<EFFECT_SINES_COUNT; i++) {
|
||||
_sinus[i]->loop();
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
#include "effect_snake.h"
|
||||
#include "functions.h"
|
||||
|
||||
SnakeEffect::SnakeEffect() {
|
||||
this->coords = {0, 0};
|
||||
this->window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
|
||||
}
|
||||
|
||||
SnakeEffect::~SnakeEffect() {
|
||||
delete window;
|
||||
}
|
||||
|
||||
void SnakeEffect::loop() {
|
||||
if (run++ % EFFECT_SNAKE_SLOWDOWN == 0) { // Change the coordinates only on every n-th run.
|
||||
if (random8(EFFECT_SNAKE_DIRECTION_CHANGE)==0 || is_turn_needed()) turn_random();
|
||||
|
||||
this->coords = update_position(this->coords, this->direction);
|
||||
}
|
||||
|
||||
window->fadeToBlackBy(2);
|
||||
CRGB color(CHSV(hue, 200, 255));
|
||||
window->setPixel(this->coords.x, this->coords.y, &color);
|
||||
hue++;
|
||||
}
|
||||
|
||||
void SnakeEffect::turn_random() {
|
||||
if ((random8() & 1) == 0) {
|
||||
turn_right() || turn_left();
|
||||
} else {
|
||||
turn_left() || turn_right();
|
||||
}
|
||||
}
|
||||
|
||||
bool SnakeEffect::turn_left() {
|
||||
if (!is_direction_okay(this->direction - 1)) return false;
|
||||
this->direction--;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SnakeEffect::turn_right() {
|
||||
if (!is_direction_okay(this->direction + 1)) return false;
|
||||
this->direction++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SnakeEffect::is_turn_needed() {
|
||||
return !is_direction_okay(this->direction);
|
||||
}
|
||||
|
||||
bool SnakeEffect::is_direction_okay(uint8_t dir) {
|
||||
Coords c = update_position(this->coords, dir);
|
||||
return c.x<window->width && c.y<window->height;
|
||||
}
|
||||
|
||||
Coords SnakeEffect::update_position(Coords original, uint8_t direction) {
|
||||
direction = direction % 4;
|
||||
if (direction == 0) original.y--;
|
||||
else if (direction == 1) original.x++;
|
||||
else if (direction == 2) original.y++;
|
||||
else if (direction == 3) original.x--;
|
||||
return original;
|
||||
}
|
||||
|
||||
boolean SnakeEffect::can_be_shown_with_clock() { return true; }
|
162
src/effects.cpp
162
src/effects.cpp
@ -1,67 +1,98 @@
|
||||
#include "effects.h"
|
||||
#include "config.h"
|
||||
#include "my_fastled.h"
|
||||
#include <ErriezCRC32.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 "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;
|
||||
|
||||
ClockEffect effect_clock;
|
||||
TimerEffect effect_timer;
|
||||
|
||||
Effect* select_effect(uint32_t code) {
|
||||
switch (code) {
|
||||
// use e.g. https://crccalc.com/ for the conversion of name to crc.
|
||||
case 0: case 0xD682E3C8 /* sinematrix3 */ : return new Sinematrix3Effect();
|
||||
case 1: case 0x90A887DA /* big_clock */ : return new BigClockEffect();
|
||||
case 2: case 0xBE7BBE92 /* clock */ : return new ClockEffect();
|
||||
case 3: case 0x733BE087 /* bell */ : return new BellEffect(); //(new AnimationEffect("/bell.pia", 0x000000, 0, 0))->setFgColor(0xFFFF00);
|
||||
case 4: case 0x2BBC5D43 /* off */ : return new StaticEffect(0x000000);
|
||||
case 5: case 0x1D84F231 /* koopa */ : return new AnimationEffect("/koopa.pia", CRGB(0x000000), 0, 0);
|
||||
case 6: case 0xAC43BCF1 /* couple_rain */ : return new AnimationEffect("/couple_rain.pia", CRGB(0x000000), -8, -16);
|
||||
case 7: case 0xF1B117F7 /* single_dynamic */ : return new SingleDynamicEffect();
|
||||
case 8: case 0xF52F2804 /* multi_dynamic */ : return new MultiDynamicEffect();
|
||||
case 9: case 0xF83341CF /* matrix */ : return new MatrixEffect();
|
||||
case 10: case 0xD2B79DD0 /* rainbow_matrix */ : return new RainbowMatrixEffect();
|
||||
case 11: case 0xE8DD3433 /* random_matrix */ : return new RandomMatrixEffect();
|
||||
case 12: case 0xB086D193 /* cycle */ : return new CycleEffect();
|
||||
case 13: case 0x2293EF9F /* twirl */ : return new TwirlEffect();
|
||||
case 14: case 0x60ECC3E6 /* heart */ : return new AnimationEffect("/heart.pia", CRGB(0x000000), 0, 0);
|
||||
case 15: case 0x42090A49 /* confetti */ : return new ConfettiEffect();
|
||||
case 16: case 0x516D6B9E /* snake */ : return new SnakeEffect();
|
||||
case 17: case 0x58DE09CF /* fire */ : return new FireEffect();
|
||||
case 18: case 0x08BA9C08 /* firework */ : return new FireworkEffect();
|
||||
case 19: case 0x14B85EAC /* gol */ : return new GolEffect();
|
||||
case 20: case 0xFA13015D /* cake */ : return new AnimationEffect("/cake.pia", CRGB(0x000000), 0, 0);
|
||||
case 21: case 0xA2B0D68B /* pixel_clock */ : return new PixelClockEffect();
|
||||
case 22: case 0x2C0E6962 /* big_dynamic */ : return new BigDynamicEffect();
|
||||
case 23: case 0xDA6F31A5 /* random_confetti */ : return new RandomConfettiEffect();
|
||||
case 24: case 0x8325C1DF /* dvd */ : return new DvdEffect();
|
||||
case 25: case 0x8CA97519 /* analog_clock */ : return new AnalogClockEffect();
|
||||
case 26: case 0xADB18CC5 /* sines */ : return new SinesEffect();
|
||||
case 27: case 0x0407881E /* blur2d */ : return new Blur2DEffect();
|
||||
case 28: case 0x935CFA7C /* marquee */ : return new MarqueeEffect();
|
||||
case 29: case 0xE27D739E /* night_clock */ : return new NightClockEffect();
|
||||
default : return NULL;
|
||||
};
|
||||
// We're using 0 instead of false to get a better visual difference between true and false.
|
||||
EffectEntry effects[] = {
|
||||
/* 0 */ {"sinematrix3", true, [](){ return new Sinematrix3Effect(); }},
|
||||
/* 1 */ {"big_clock", true, [](){ return new BigClockEffect(); }},
|
||||
/* 2 */ {"clock", 0, [](){ return new ClockEffect(); }},
|
||||
/* 3 */ {"bell", 0, [](){ return AnimationEffect::Blinker("/bell.pia", 300, 0xFFFF00); }},
|
||||
/* 4 */ {"off", 0, [](){ return new StaticEffect(0x000000); }},
|
||||
/* 5 */ {"single_dynamic", true, [](){ return new SingleDynamicEffect(); }},
|
||||
/* 6 */ {"multi_dynamic", true, [](){ return new MultiDynamicEffect(); }},
|
||||
/* 7 */ {"big_dynamic", true, [](){ return new BigDynamicEffect(); }},
|
||||
/* 8 */ {"matrix", true, [](){ return new MatrixEffect(); }},
|
||||
/* 9 */ {"random_matrix", true, [](){ return new RandomMatrixEffect(); }},
|
||||
/* 10 */ {"rainbow_matrix", true, [](){ return new RainbowMatrixEffect(); }},
|
||||
/* 11 */ {"cycle", 0, [](){ return new CycleEffect(); }},
|
||||
/* 12 */ {"twirl", true, [](){ return new TwirlEffect(); }},
|
||||
/* 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(); }},
|
||||
/* 18 */ {"pixel_clock", 0, [](){ return new PixelClockEffect(); }},
|
||||
/* 19 */ {"dvd", true, [](){ return new DvdEffect(); }},
|
||||
/* 20 */ {"analog_clock", 0, [](){ return new AnalogClockEffect(); }},
|
||||
/* 21 */ {"sines", true, [](){ return new SinesEffect(); }},
|
||||
/* 22 */ {"blur2d", true, [](){ return new Blur2DEffect(); }},
|
||||
/* 23 */ {"marquee", 0, [](){ return new MarqueeEffect(); }},
|
||||
/* 24 */ {"night_clock", 0, [](){ return new NightClockEffect(); }},
|
||||
/* 25 */ {"tv_static", 0, [](){ return new TvStaticEffect(); }},
|
||||
/* 26 */ {"sinematrix3_rainbow", true, [](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_RAINBOW); }},
|
||||
/* 27 */ {"sinematrix3_purplefly", true, [](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_PURPLEFLY); }},
|
||||
/* 28 */ {"lightspeed", true, [](){ return new LightspeedEffect(); }},
|
||||
/* 29 */ {"koopa", 0, [](){ return new AnimationEffect("/koopa.pia"); }},
|
||||
/* 30 */ {"cake", 0, [](){ return new AnimationEffect("/cake.pia"); }},
|
||||
/* 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 = 40;
|
||||
|
||||
|
||||
Effect* select_effect(const char* name) {
|
||||
for(int i=0; i<effects_size; i++) {
|
||||
if (strcmp(effects[i].name, name)==0) {
|
||||
return effects[i].create();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Effect* select_effect(uint8_t id) {
|
||||
if (id < effects_size) {
|
||||
return effects[id].create();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool change_current_effect(String payload) {
|
||||
@ -74,7 +105,7 @@ bool change_current_effect(String payload) {
|
||||
LOGln("Effects * Cleaned effect name: %s", payload.c_str());
|
||||
}
|
||||
|
||||
Effect* new_effect = select_effect( crc32String(payload.c_str()) );
|
||||
Effect* new_effect = select_effect( payload.c_str() );
|
||||
if (new_effect == NULL) {
|
||||
LOGln("Effects * Could not find effect with name %s", payload.c_str());
|
||||
return false;
|
||||
@ -101,21 +132,6 @@ bool change_current_effect(String payload) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* cycle_effects[] = {
|
||||
"sinematrix3",
|
||||
"single_dynamic", "multi_dynamic", "big_dynamic",
|
||||
"matrix", "rainbow_matrix", "random_matrix",
|
||||
"confetti", "random_confetti",
|
||||
"snake",
|
||||
"gol",
|
||||
"twirl",
|
||||
"sines",
|
||||
"blur2d",
|
||||
"firework",
|
||||
"big_clock",
|
||||
"dvd"};
|
||||
uint8_t cycle_effects_count = 17;
|
||||
|
||||
void setup_effects() {
|
||||
current_effect = new CycleEffect();
|
||||
}
|
||||
|
33
src/effects/analogclock.cpp
Normal file
33
src/effects/analogclock.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "effects/analogclock.h"
|
||||
#include "my_fastled.h"
|
||||
#include "ntp.h"
|
||||
#include <time.h>
|
||||
|
||||
void AnalogClockEffect::loop(uint16_t ms) {
|
||||
window->clear();
|
||||
CRGB white(0xFFFFFF);
|
||||
CRGB red(0xFF0000);
|
||||
window->circle(8, 8, 7, &white);
|
||||
|
||||
time_t now;
|
||||
tm timeinfo;
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
uint16_t seconds = timeinfo.tm_sec * 1000 + (millis()%1000);
|
||||
uint16_t angle = seconds * 0x10000 / 60000;
|
||||
window->lineWithAngle(8, 8, angle, 12, &red);
|
||||
//window->line(0<<8, 0<<8, 7<<8, 7<<8, &white);
|
||||
//window->line(15<<8, 0<<8, 8<<8, 7<<8, &red);
|
||||
//window->line(0<<8, 15<<8, 7<<8, 8<<8, &blue);
|
||||
//window->line(15<<8, 15<<8, 8<<8, 8<<8, &green);
|
||||
|
||||
/*for (uint8_t i=0; i<=12; i++) {
|
||||
window->lineWithAngle(8, 8, 255/12*i, 5, 2, &white);
|
||||
}
|
||||
|
||||
uint8_t minutes = ntpClient.getMinutes();
|
||||
uint8_t hours = ntpClient.getHours();
|
||||
|
||||
window->lineWithAngle(8, 8, 255/60*minutes, 6, &white);
|
||||
window->lineWithAngle(8, 8, 255/12*(hours % 12), 4, &white);*/
|
||||
}
|
53
src/effects/animation.cpp
Normal file
53
src/effects/animation.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "effects/animation.h"
|
||||
#include "functions.h"
|
||||
|
||||
AnimationEffect::AnimationEffect(const char* name, uint32_t bg, int x, int y) {
|
||||
this->name = name;
|
||||
this->xOffset = x;
|
||||
this->yOffset = y;
|
||||
|
||||
this->animation = new Animation(name, window);
|
||||
this->animation->setBgColor(bg);
|
||||
this->animation->setOffsets(this->xOffset, this->yOffset);
|
||||
|
||||
_last_blink_at = millis();
|
||||
}
|
||||
|
||||
AnimationEffect* AnimationEffect::setFgColor(uint32_t c) {
|
||||
animation->setFgColor(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
AnimationEffect* AnimationEffect::setBlinkFrequency(uint16_t ms) {
|
||||
_blink_freq = ms;
|
||||
return this;
|
||||
}
|
||||
|
||||
AnimationEffect::~AnimationEffect() {
|
||||
delete this->animation;
|
||||
}
|
||||
|
||||
void AnimationEffect::loop(uint16_t ms) {
|
||||
if (_blink_freq > 0) {
|
||||
unsigned long mil = millis();
|
||||
if (mil < _last_blink_at || _last_blink_at + _blink_freq <= mil) {
|
||||
this->animation->invert();
|
||||
_last_blink_at = mil;
|
||||
}
|
||||
}
|
||||
this->animation->drawFrame();
|
||||
this->animation->advance();
|
||||
}
|
||||
|
||||
String AnimationEffect::get_name() {
|
||||
String s = "animation/";
|
||||
s += this->name;
|
||||
return s;
|
||||
}
|
||||
|
||||
AnimationEffect* AnimationEffect::Blinker(const char* name, uint16_t interval, uint32_t color, uint32_t background_color) {
|
||||
AnimationEffect* anim = new AnimationEffect(name, background_color);
|
||||
anim->setFgColor(color);
|
||||
anim->setBlinkFrequency(interval);
|
||||
return anim;
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
#include "Effect.h"
|
||||
#include "functions.h"
|
||||
#include "effect_bell.h"
|
||||
#include "effects/bell.h"
|
||||
#include "sprites.h"
|
||||
|
||||
void BellEffect::loop() {
|
||||
void BellEffect::loop(uint16_t ms) {
|
||||
Serial.println("This is Bell.loop()");
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int x = 0; x < 2; x++) {
|
74
src/effects/big_clock.cpp
Normal file
74
src/effects/big_clock.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
#include "Effect.h"
|
||||
#include "effects/big_clock.h"
|
||||
#include "fonts.h"
|
||||
#include <time.h>
|
||||
#include "settings.h"
|
||||
|
||||
void BigClockEffect::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 = _get_color_font();
|
||||
window->drawChar(&font_numbers3x5_blocky, 6<<8, 2<<8, '0' + (h / 10), &color);
|
||||
window->drawChar(&font_numbers3x5_blocky, 11<<8, 2<<8, '0' + (h % 10), &color);
|
||||
|
||||
uint8_t m = timeinfo.tm_min;
|
||||
window->drawChar(&font_numbers3x5_blocky, 6<<8, 9<<8, '0' + (m / 10), &color);
|
||||
window->drawChar(&font_numbers3x5_blocky, 11<<8, 9<<8, '0' + (m % 10), &color);
|
||||
|
||||
uint8_t s = timeinfo.tm_sec;
|
||||
_draw_colon(s & 1);
|
||||
|
||||
_draw_seconds(timeinfo.tm_sec);
|
||||
}
|
||||
|
||||
void BigClockEffect::_draw_colon(bool odd) {
|
||||
if (odd) {
|
||||
CRGB color = _get_color_font();
|
||||
window->setPixel(3, 10, &color);
|
||||
window->setPixel(3, 12, &color);
|
||||
}
|
||||
}
|
||||
|
||||
void BigClockEffect::_draw_seconds(uint8_t seconds) {
|
||||
for (int i=1; i<=seconds; i++) {
|
||||
_draw_border_pixel(i<<8, (i%5==0) ? &_color_seconds_light : &_color_seconds_dark);
|
||||
}
|
||||
|
||||
/*timeval tv;
|
||||
gettimeofday(&tv, nullptr);
|
||||
uint16_t mil = (tv.tv_usec / 1000) % 1000;
|
||||
accum88 pos = (seconds<<8) + ((settings.effects.big_clock.spacing-1)<<8) * (1000 - mil) / 1000 + (1<<8);
|
||||
uint8_t sec = seconds + 1;
|
||||
while (pos < (60<<8)) {
|
||||
_draw_border_pixel(pos, sec%5==0 ? &_color_seconds_moving_light : &_color_seconds_moving_dark);
|
||||
pos += settings.effects.big_clock.spacing<<8;
|
||||
sec++;
|
||||
}*/
|
||||
}
|
||||
|
||||
void BigClockEffect::_draw_border_pixel(accum88 i, CRGB* color) {
|
||||
accum88 x, y;
|
||||
if (i<(8<<8)) {
|
||||
x = i + (7<<8);
|
||||
y = 0;
|
||||
} else if (i<(23<<8)) {
|
||||
x = 15<<8;
|
||||
y = i - (8<<8);
|
||||
} else if (i<(38<<8)) {
|
||||
x = (38<<8) - i;
|
||||
y = 15<<8;
|
||||
} else if (i<(53<<8)) {
|
||||
x = 0;
|
||||
y = (53<<8) - i;
|
||||
} else if (i<=(60<<8)) {
|
||||
x = i - (53<<8);
|
||||
y = 0;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
window->setSubPixel(x, y, color);
|
||||
}
|
48
src/effects/blur2d.cpp
Normal file
48
src/effects/blur2d.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "effects/blur2d.h"
|
||||
Blur2DBlob::Blur2DBlob() {
|
||||
_x_freq = random16(6<<8, 15<<8);
|
||||
_y_freq = random16(6<<8, 15<<8);
|
||||
_color_freq = random8(25, 80);
|
||||
}
|
||||
|
||||
void Blur2DBlob::render(Window* window) {
|
||||
uint8_t x = beatsin16(_x_freq, 0, window->width-1);
|
||||
uint8_t y = beatsin16(_y_freq, 0, window->height-1);
|
||||
|
||||
CRGB c = CHSV(millis() / _color_freq, 200, 255);
|
||||
window->addPixelColor(x, y, &c);
|
||||
}
|
||||
|
||||
|
||||
boolean Blur2DEffect::can_be_shown_with_clock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Blur2DEffect::loop(uint16_t ms) {
|
||||
if (_count != settings.effects.blur2d.count) {
|
||||
_delete();
|
||||
_init();
|
||||
}
|
||||
uint8_t blur_amount = dim8_raw(beatsin8(3, 128, 224));
|
||||
window->blur(blur_amount);
|
||||
for (int i=0; i<_count; i++) {
|
||||
_blobs[i].render(window);
|
||||
}
|
||||
}
|
||||
|
||||
Blur2DEffect::Blur2DEffect() {
|
||||
_init();
|
||||
}
|
||||
|
||||
void Blur2DEffect::_init() {
|
||||
_count = settings.effects.blur2d.count;
|
||||
_blobs = new Blur2DBlob[_count];
|
||||
}
|
||||
|
||||
void Blur2DEffect::_delete() {
|
||||
delete[] _blobs;
|
||||
}
|
||||
|
||||
Blur2DEffect::~Blur2DEffect() {
|
||||
_delete();
|
||||
}
|
@ -1,22 +1,10 @@
|
||||
#include "effect_clock.h"
|
||||
#include "effects/clock.h"
|
||||
#include <FastLED.h>
|
||||
#include "functions.h"
|
||||
#include "fonts.h"
|
||||
#include "ntp.h"
|
||||
|
||||
NightClockEffect::NightClockEffect() {
|
||||
window = Window::getFullWindow();
|
||||
}
|
||||
|
||||
void NightClockEffect::loop() {
|
||||
uint16_t minutes = minutes16();
|
||||
//uint8_t y = minutes % ((window->height - 5) * 2 - 2);
|
||||
//if (y > window->height - 5) y = 2*window->height - 2*y;
|
||||
uint8_t y = minutes % 10;
|
||||
ClockEffect::loop(false, CRGB(0x200000), CRGB(0x000000), y);
|
||||
}
|
||||
|
||||
void ClockEffect::loop() {
|
||||
void ClockEffect::loop(uint16_t ms) {
|
||||
loop_with_invert(false);
|
||||
}
|
||||
|
||||
@ -42,23 +30,26 @@ void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t yPo
|
||||
}
|
||||
fg_color = bg_color;
|
||||
}
|
||||
if (ntpClient.isTimeSet()==false && (ntpClient.getSeconds() & 1)==0) {
|
||||
/*if (ntpClient.isTimeSet()==false && (ntpClient.getSeconds() & 1)==0) {
|
||||
window->clear(&bg_color);
|
||||
return;
|
||||
}
|
||||
int h = ntpClient.getHours();
|
||||
}*/
|
||||
time_t now;
|
||||
tm timeinfo;
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
int h = timeinfo.tm_hour;
|
||||
//void drawChar(Font f, uint8_t x, uint8_t y, const char c, CRGB* color, bool mask=false);
|
||||
window->drawChar(&font_numbers3x5, 0<<8, yPos<<8, '0' + (h / 10), &fg_color, invert);
|
||||
window->drawChar(&font_numbers3x5, 4<<8, yPos<<8, '0' + (h % 10), &fg_color, invert);
|
||||
int m = ntpClient.getMinutes();
|
||||
int m = timeinfo.tm_min;
|
||||
window->drawChar(&font_numbers3x5, 9<<8, yPos<<8, '0' + (m / 10), &fg_color, invert);
|
||||
window->drawChar(&font_numbers3x5, 13<<8, yPos<<8, '0' + (m % 10), &fg_color, invert);
|
||||
if (ntpClient.getSeconds() & 1) {
|
||||
if (timeinfo.tm_sec & 1) {
|
||||
window->setPixel(7, yPos+1, &fg_color);
|
||||
window->setPixel(7, yPos+3, &fg_color);
|
||||
}
|
||||
}
|
||||
|
||||
ClockEffect::~ClockEffect() {
|
||||
delete window;
|
||||
}
|
100
src/effects/cycle.cpp
Normal file
100
src/effects/cycle.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
#include "effects/cycle.h"
|
||||
#include "effects.h"
|
||||
|
||||
CycleEffect::CycleEffect() {
|
||||
_effects_count = 0;
|
||||
for (uint8_t i=0; i<effects_size; i++) {
|
||||
if (effects[i].use_in_cycle) _effects_count++;
|
||||
}
|
||||
LOGln("Cycle * Found %d effects to use in cycle.", _effects_count);
|
||||
changeEffect();
|
||||
}
|
||||
|
||||
CycleEffect::~CycleEffect() {
|
||||
delete effect;
|
||||
}
|
||||
|
||||
void CycleEffect::changeEffect() {
|
||||
uint8_t new_id;
|
||||
if (settings.effects.cycle.random && _effects_count>1) {
|
||||
do {
|
||||
new_id = random8(_effects_count);
|
||||
} while (new_id == effect_id);
|
||||
} else {
|
||||
new_id = (effect_id + 1) % _effects_count;
|
||||
}
|
||||
LOGln("CycleEffect * Changing effect from #%d to #%d", effect_id, new_id);
|
||||
delay(25);
|
||||
|
||||
String old_effect_name = String("UNKNOWN");
|
||||
if (effect) {
|
||||
old_effect_name = effect->get_name();
|
||||
delete effect;
|
||||
}
|
||||
|
||||
int16_t diff = 0;
|
||||
uint16_t old_heap = _heap_free;
|
||||
_heap_free = ESP.getFreeHeap();
|
||||
if (old_heap) {
|
||||
// diff positive = More heap used (baad)
|
||||
// diff negative = Less heap used (good-ish)
|
||||
diff = old_heap - _heap_free;
|
||||
LOGln("CycleEffect * Heap usage: #%d,%s,%d,%+d", effect_id, old_effect_name.c_str(), _heap_free, diff);
|
||||
}
|
||||
|
||||
delay(25);
|
||||
LOGln("CycleEffect * Searching for new effect #%d", new_id);
|
||||
uint8_t count = 0;
|
||||
EffectEntry* e = nullptr;
|
||||
for (uint8_t i=0; i<effects_size; i++) {
|
||||
if (effects[i].use_in_cycle) {
|
||||
if (count == new_id) {
|
||||
e = &effects[i];
|
||||
effect = e->create();
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (e) {
|
||||
#ifdef MQTT_REPORT_METRICS
|
||||
e->heap_change_sum += diff;
|
||||
e->run_count++;
|
||||
LOGln("CycleEffect * Last effect stats: name:%s, runs:%d, total_change:%d", old_effect_name.c_str(), e->run_count, e->heap_change_sum);
|
||||
String topic = "metrics/effects/";
|
||||
topic.concat(old_effect_name);
|
||||
String message = String("runs:") + e->run_count + ", total_heap_change:" + e->heap_change_sum;
|
||||
mqtt_publish(topic.c_str(), message.c_str(), true);
|
||||
#endif
|
||||
effect_id = new_id;
|
||||
effectSince = millis();
|
||||
LOGln("CycleEffect * Effect %s found", effect->get_name().c_str());
|
||||
} else {
|
||||
LOGln("CycleEffect * Effect NOT found");
|
||||
}
|
||||
}
|
||||
|
||||
boolean CycleEffect::can_be_shown_with_clock() {
|
||||
return effect->can_be_shown_with_clock();
|
||||
};
|
||||
boolean CycleEffect::clock_as_mask() {
|
||||
return effect->clock_as_mask();
|
||||
};
|
||||
|
||||
void CycleEffect::loop(uint16_t ms) {
|
||||
if (!effect) changeEffect(); // If this is the first run, we have to select an effect first!
|
||||
effect->loop(ms);
|
||||
// Don't use EVERY_N_SECONDS(config_effect_cycle_time) here because that function isn't relly made
|
||||
// to be used with changing values.
|
||||
EVERY_N_SECONDS(1) {
|
||||
if (effectSince + settings.effects.cycle.time*1000 < millis()) {
|
||||
changeEffect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String CycleEffect::get_name() {
|
||||
String s = "cycle/";
|
||||
s += effect->get_name();
|
||||
return s;
|
||||
}
|
14
src/effects/diamond.cpp
Normal file
14
src/effects/diamond.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "effects/diamond.h"
|
||||
#include "my_fastled.h"
|
||||
|
||||
void DiamondEffect::loop(uint16_t ms) {
|
||||
for (int x=0; x<window->width; x++) {
|
||||
for (int y=0; y<window->height; y++) {
|
||||
uint8_t distance = abs(window->height/2 - y) + abs(window->width/2 - x);
|
||||
CRGB col = CHSV(distance*8 - (millis()>>5)%255, 255, 255);
|
||||
window->setPixel(x, y, &col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DiamondEffect::can_be_shown_with_clock() { return true; }
|
50
src/effects/dvd.cpp
Normal file
50
src/effects/dvd.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include "effects/dvd.h"
|
||||
#include "my_fastled.h"
|
||||
|
||||
void DvdEffect::loop(uint16_t ms) {
|
||||
bool dir_changed = false;
|
||||
|
||||
_x += _x_dir * settings.effects.dvd.speed;
|
||||
_y += _y_dir * settings.effects.dvd.speed;
|
||||
|
||||
if (_x <= 0) {
|
||||
_x = -_x;
|
||||
_x_dir = -_x_dir;
|
||||
dir_changed = true;
|
||||
//LOGln("speed: %d", settings.effects.dvd.speed);
|
||||
} else if (_x + (settings.effects.dvd.width << 8) >= (window->width << 8)) {
|
||||
_x -= 2*settings.effects.dvd.speed;
|
||||
_x_dir = -_x_dir;
|
||||
dir_changed = true;
|
||||
}
|
||||
|
||||
if (_y <= 0) {
|
||||
_y = -_y;
|
||||
_y_dir = -_y_dir;
|
||||
dir_changed = true;
|
||||
} else if (_y + (settings.effects.dvd.height << 8) >= (window->height << 8)) {
|
||||
_y -= 2*settings.effects.dvd.speed;
|
||||
_y_dir = -_y_dir;
|
||||
dir_changed = true;
|
||||
}
|
||||
|
||||
window->clear();
|
||||
|
||||
if (dir_changed) _color = (CRGB)CHSV(random8(), 255, 255);
|
||||
|
||||
for (int x=0; x<settings.effects.dvd.width; x++) for (int y=0; y<settings.effects.dvd.height; y++) {
|
||||
window->setSubPixel(_x + (x<<8), _y + (y<<8), (CRGB*)&_color);
|
||||
}
|
||||
for (int x=1; x<settings.effects.dvd.width; x++) for (int y=1; y<settings.effects.dvd.height; y++) {
|
||||
window->setPixel((_x>>8) + x, (_y>>8) + y, (CRGB*)&_color);
|
||||
}
|
||||
}
|
||||
|
||||
bool DvdEffect::can_be_shown_with_clock() { return true; }
|
||||
|
||||
DvdEffect::DvdEffect() {
|
||||
_color = CHSV(random8(), 255, 255);
|
||||
}
|
||||
|
||||
DvdEffect::~DvdEffect() {
|
||||
}
|
56
src/effects/dynamic.cpp
Normal file
56
src/effects/dynamic.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include "effects/dynamic.h"
|
||||
#include "functions.h"
|
||||
#include "config.h"
|
||||
|
||||
SingleDynamicEffect::SingleDynamicEffect() {
|
||||
init();
|
||||
}
|
||||
|
||||
void SingleDynamicEffect::init() {
|
||||
for (int i=0; i<tile_count; i++) tiles[i] = CHSV(baseHue + random8(64), 180, 255);
|
||||
}
|
||||
|
||||
void SingleDynamicEffect::loop(uint16_t ms) {
|
||||
EVERY_N_MILLISECONDS( settings.effects.dynamic.single_loop_time ) {
|
||||
tiles[random8(tile_count)] = CHSV(baseHue + random8(64), 180, 255);
|
||||
}
|
||||
this->draw();
|
||||
}
|
||||
|
||||
void SingleDynamicEffect::draw() {
|
||||
for (int x=0; x<window->width; x++) for (int y=0; y<window->height; y++) {
|
||||
int index = y/2 * window->width/2 + x/2;
|
||||
window->setPixel(x, y, &tiles[index]);
|
||||
}
|
||||
}
|
||||
|
||||
boolean SingleDynamicEffect::can_be_shown_with_clock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void MultiDynamicEffect::loop(uint16_t ms) {
|
||||
EVERY_N_MILLISECONDS( settings.effects.dynamic.multi_loop_time ) {
|
||||
for (int i=0; i<tile_count; i++) tiles[i] = CHSV(baseHue + random8(64), 180, 255);
|
||||
}
|
||||
this->draw();
|
||||
}
|
||||
|
||||
BigDynamicEffect::~BigDynamicEffect() {
|
||||
}
|
||||
|
||||
void BigDynamicEffect::loop(uint16_t ms) {
|
||||
EVERY_N_MILLISECONDS( settings.effects.dynamic.big_loop_time ) {
|
||||
uint8_t x = random8(0, window->width - settings.effects.dynamic.big_size + 1);
|
||||
uint8_t y = random8(0, window->height - settings.effects.dynamic.big_size + 1);
|
||||
CRGB color = CHSV(random8(), 255, 255);
|
||||
CRGB black(0x000000);
|
||||
|
||||
for (uint8_t ix=0; ix<settings.effects.dynamic.big_size; ix++) for (uint8_t iy=0; iy<settings.effects.dynamic.big_size; iy++) {
|
||||
window->setPixel(x+ix, y+iy, &color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean BigDynamicEffect::can_be_shown_with_clock() {
|
||||
return true;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
#include "effect_fire.h"
|
||||
#include "effects/fire.h"
|
||||
#include "my_color_palettes.h"
|
||||
#include "config.h"
|
||||
#include "my_fastled.h"
|
||||
@ -14,7 +14,7 @@ FireEffect::~FireEffect() {
|
||||
delete [] this->data;
|
||||
}
|
||||
|
||||
void FireEffect::loop() {
|
||||
void FireEffect::loop(uint16_t ms) {
|
||||
cooldown();
|
||||
spark();
|
||||
propagate();
|
||||
@ -22,11 +22,11 @@ void FireEffect::loop() {
|
||||
}
|
||||
|
||||
void FireEffect::cooldown() {
|
||||
for(int i=0; i<(this->window->width * this->window->height); i++) this->data[i] = scale8(this->data[i], EFFECT_FIRE_COOLDOWN); // 240 or something
|
||||
for(int i=0; i<(this->window->width * this->window->height); i++) this->data[i] = scale8(this->data[i], settings.effects.fire.cooldown);
|
||||
}
|
||||
|
||||
void FireEffect::spark() {
|
||||
for(int x=0; x<this->window->width; x++) if (random8(EFFECT_FIRE_SPARK_CHANCE)==0) this->data[x] = this->spark_temp();
|
||||
for(int x=0; x<this->window->width; x++) if (random8(settings.effects.fire.spark_chance)==0) this->data[x] = this->spark_temp();
|
||||
}
|
||||
|
||||
inline uint8_t FireEffect::spark_temp() {
|
@ -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;
|
||||
@ -49,20 +49,20 @@ void FireworkEffectDot::draw() {
|
||||
dim8_video( scale8( scale8( _color.g, ye), xe)),
|
||||
dim8_video( scale8( scale8( _color.b, ye), xe)));
|
||||
_window->addPixelColor(ix, iy, &c00);
|
||||
_window->addPixelColor(ix, iy+1, &c01);
|
||||
_window->addPixelColor(ix, iy-1, &c01);
|
||||
_window->addPixelColor(ix+1, iy, &c10);
|
||||
_window->addPixelColor(ix+1, iy+1, &c11);
|
||||
_window->addPixelColor(ix+1, iy-1, &c11);
|
||||
}
|
||||
|
||||
void FireworkEffectDot::move() {
|
||||
if (!show) return;
|
||||
_yv -= EFFECT_FIREWORK_GRAVITY;
|
||||
_xv = _scale15by8_local(_xv, EFFECT_FIREWORK_DRAG);
|
||||
_yv = _scale15by8_local(_yv, EFFECT_FIREWORK_DRAG);
|
||||
_yv -= settings.effects.firework.gravity;
|
||||
_xv = _scale15by8_local(_xv, settings.effects.firework.drag);
|
||||
_yv = _scale15by8_local(_yv, settings.effects.firework.drag);
|
||||
|
||||
if (type == FIREWORK_DOT_SPARK) {
|
||||
_xv = _scale15by8_local(_xv, EFFECT_FIREWORK_DRAG);
|
||||
_yv = _scale15by8_local(_yv, EFFECT_FIREWORK_DRAG);
|
||||
_xv = _scale15by8_local(_xv, settings.effects.firework.drag);
|
||||
_yv = _scale15by8_local(_yv, settings.effects.firework.drag);
|
||||
_color.nscale8(255);
|
||||
if (!_color) {
|
||||
show = 0;
|
||||
@ -70,12 +70,12 @@ void FireworkEffectDot::move() {
|
||||
}
|
||||
|
||||
// Bounce if we hit the ground
|
||||
if (_xv < 0 && _y - _window->height < (-_yv)) {
|
||||
if (_yv < 0 && _y - _window->height < (-_yv)) {
|
||||
if (type == FIREWORK_DOT_SPARK) {
|
||||
show = 0;
|
||||
} else {
|
||||
_yv = -_yv;
|
||||
_yv = _scale15by8_local(_yv, EFFECT_FIREWORK_BOUNCE);
|
||||
_yv = _scale15by8_local(_yv, settings.effects.firework.bounce);
|
||||
if (_yv < 500) {
|
||||
show = 0;
|
||||
}
|
||||
@ -139,11 +139,11 @@ boolean FireworkEffect::can_be_shown_with_clock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void FireworkEffect::loop() {
|
||||
void FireworkEffect::loop(uint16_t ms) {
|
||||
window->clear();
|
||||
_dot->move();
|
||||
_dot->draw();
|
||||
for (int i=0; i<EFFECT_FIREWORK_SPARKS; i++) {
|
||||
for (int i=0; i<settings.effects.firework.sparks; i++) {
|
||||
_sparks[i]->move();
|
||||
_sparks[i]->draw();
|
||||
}
|
||||
@ -159,7 +159,7 @@ void FireworkEffect::loop() {
|
||||
}
|
||||
|
||||
if (_skyburst) {
|
||||
int nsparks = random8(EFFECT_FIREWORK_SPARKS / 2, EFFECT_FIREWORK_SPARKS + 1);
|
||||
int nsparks = random8(settings.effects.firework.sparks / 2, settings.effects.firework.sparks + 1);
|
||||
for (int i=0; i<nsparks; i++) {
|
||||
_sparks[i]->sky_burst(_burst_x, _burst_y, _burst_yv, _burst_color);
|
||||
_skyburst = 0;
|
||||
@ -169,14 +169,14 @@ void FireworkEffect::loop() {
|
||||
|
||||
FireworkEffect::FireworkEffect() {
|
||||
_dot = new FireworkEffectDot(window, this);
|
||||
for (int i=0; i<EFFECT_FIREWORK_SPARKS; i++) {
|
||||
_sparks = new FireworkEffectDot*[settings.effects.firework.sparks];
|
||||
for (int i=0; i<settings.effects.firework.sparks; i++) {
|
||||
_sparks[i] = new FireworkEffectDot(window, this);
|
||||
}
|
||||
}
|
||||
|
||||
FireworkEffect::~FireworkEffect() {
|
||||
delete window;
|
||||
for (int i=0; i<EFFECT_FIREWORK_SPARKS; i++) {
|
||||
for (int i=0; i<settings.effects.firework.sparks; i++) {
|
||||
delete _sparks[i];
|
||||
}
|
||||
delete _dot;
|
@ -1,8 +1,8 @@
|
||||
#include "effect_gol.h"
|
||||
#include "effects/gol.h"
|
||||
#include "my_fastled.h"
|
||||
|
||||
GolEffect::GolEffect() {
|
||||
this->window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
|
||||
this->window = &Window::window_with_clock;
|
||||
|
||||
_data = new uint8_t[this->window->count];
|
||||
_old = new uint8_t[this->window->count];
|
||||
@ -16,7 +16,7 @@ bool GolEffect::can_be_shown_with_clock() { return true; }
|
||||
|
||||
void GolEffect::_initialize() {
|
||||
for(uint16_t i=0; i<this->window->count; i++) {
|
||||
_data[i] = random8() < EFFECT_GOL_START_PERCENTAGE ? 1 : 0;
|
||||
_data[i] = random8() < settings.effects.gol.start_percentage ? 1 : 0;
|
||||
}
|
||||
_old_hue = _hue;
|
||||
_hue = random8();
|
||||
@ -26,15 +26,14 @@ void GolEffect::_initialize() {
|
||||
GolEffect::~GolEffect() {
|
||||
delete[] _data;
|
||||
delete[] _old;
|
||||
delete window;
|
||||
}
|
||||
|
||||
void GolEffect::loop() {
|
||||
if (EFFECT_GOL_BLEND_SPEED + _blend > 255) {
|
||||
void GolEffect::loop(uint16_t ms) {
|
||||
if (settings.effects.gol.blend_speed + _blend > 255) {
|
||||
_blend = 0;
|
||||
_advance();
|
||||
} else {
|
||||
_blend += EFFECT_GOL_BLEND_SPEED;
|
||||
_blend += settings.effects.gol.blend_speed;
|
||||
}
|
||||
|
||||
_draw();
|
||||
@ -43,7 +42,7 @@ void GolEffect::loop() {
|
||||
void GolEffect::_advance() {
|
||||
_step++;
|
||||
_old_hue = _hue;
|
||||
if (_step >= EFFECT_GOL_RESTART_AFTER_STEPS) {
|
||||
if (_step >= settings.effects.gol.restart_after_steps) {
|
||||
_initialize();
|
||||
} else {
|
||||
for(uint16_t i=0; i<this->window->count; i++) {
|
65
src/effects/lightspeed.cpp
Normal file
65
src/effects/lightspeed.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
#include "effects/lightspeed.h"
|
||||
#include "config.h"
|
||||
#include "functions.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
LightspeedEffect::LightspeedEffect() {
|
||||
window = &Window::window_with_clock;
|
||||
_init();
|
||||
}
|
||||
|
||||
LightspeedEffect::~LightspeedEffect() {
|
||||
_delete();
|
||||
}
|
||||
|
||||
void LightspeedEffect::_init() {
|
||||
_count = settings.effects.lightspeed.count;
|
||||
_stars = new LightspeedEffectStar[_count];
|
||||
for (int i=0; i<_count; i++) {
|
||||
_stars[i] = LightspeedEffectStar();
|
||||
}
|
||||
}
|
||||
|
||||
void LightspeedEffect::_delete() {
|
||||
delete[] _stars;
|
||||
}
|
||||
|
||||
void LightspeedEffect::loop(uint16_t ms) {
|
||||
if (settings.effects.lightspeed.count != _count) {
|
||||
_delete();
|
||||
_init();
|
||||
}
|
||||
window->clear();
|
||||
for (int i=0; i<_count; i++) {
|
||||
_stars[i].loop(window);
|
||||
}
|
||||
}
|
||||
|
||||
boolean LightspeedEffect::can_be_shown_with_clock() { return true; };
|
||||
|
||||
LightspeedEffectStar::LightspeedEffectStar() {
|
||||
_init();
|
||||
_distance = random16(10<<8);
|
||||
}
|
||||
|
||||
void LightspeedEffectStar::_init() {
|
||||
_angle = random16();
|
||||
_distance = 0;
|
||||
_speed = random16(128, 2<<8);
|
||||
_target = random16(25<<8, 35<<8);
|
||||
_saturation = random8(100);
|
||||
}
|
||||
|
||||
void LightspeedEffectStar::loop(Window* win) {
|
||||
CRGB col = CHSV(192, _saturation, 255);
|
||||
accum88 current_speed = _speed * beatsin16(0x100, 0, 65535) / 65535;
|
||||
uint8_t length = (current_speed>>6);
|
||||
if (_distance < (length<<8)) {
|
||||
win->lineWithAngle(win->width/2, win->height/2, _angle, 0, _distance>>8, &col);
|
||||
} else {
|
||||
win->lineWithAngle(win->width/2, win->height/2, _angle, (_distance>>8) - length, length, &col);
|
||||
}
|
||||
_distance += current_speed;
|
||||
//_angle+=8<<8;
|
||||
if (_distance > _target) _init();
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
#include "effect_marquee.h"
|
||||
#include "effects/marquee.h"
|
||||
#include "fonts.h"
|
||||
|
||||
boolean MarqueeEffect::can_be_shown_with_clock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void MarqueeEffect::loop() {
|
||||
static int loop_counter = 0;
|
||||
void MarqueeEffect::loop(uint16_t ms) {
|
||||
window->clear();
|
||||
CRGB color = CHSV(0, 255, 255);
|
||||
uint16_t width = _text.length() * 6;
|
@ -1,4 +1,4 @@
|
||||
#include "effect_matrix.h"
|
||||
#include "effects/matrix.h"
|
||||
#include "my_color_palettes.h"
|
||||
#include "functions.h"
|
||||
|
||||
@ -38,28 +38,28 @@ void MatrixEffectColumn::restart(bool completely_random) {
|
||||
}
|
||||
}
|
||||
|
||||
length = random8(EFFECT_MATRIX_LENGTH_MIN, EFFECT_MATRIX_LENGTH_MAX);
|
||||
length = random8(settings.effects.matrix.length_min, settings.effects.matrix.length_max);
|
||||
running = true;
|
||||
speed = random8(EFFECT_MATRIX_SPEED_MIN, EFFECT_MATRIX_SPEED_MAX);
|
||||
speed = random8(settings.effects.matrix.speed_min, settings.effects.matrix.speed_max);
|
||||
}
|
||||
|
||||
void MatrixEffectColumn::advance() {
|
||||
void MatrixEffectColumn::advance(uint16_t ms) {
|
||||
switch(_direction) {
|
||||
case DIR_NORTH:
|
||||
y-=speed;
|
||||
if ((y>>8) > window->height && (y>>8) + length > window->height) running=false;
|
||||
y-=speed * ms;
|
||||
if ((y>>8) + length < 0) running=false;
|
||||
break;
|
||||
case DIR_EAST:
|
||||
x+=speed;
|
||||
x+=speed * ms;
|
||||
if ((x>>8) - length > window->width) running=false;
|
||||
break;
|
||||
case DIR_SOUTH:
|
||||
y+=speed;
|
||||
y+=speed * ms;
|
||||
if ((y>>8) - length > window->height) running=false;
|
||||
break;
|
||||
case DIR_WEST:
|
||||
x-=speed;
|
||||
if ((x>>8) > window->width && (y>>8) + length > window->width) running=false;
|
||||
x-=speed * ms;
|
||||
if ((x>>8) + length < 0) running=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -79,14 +79,14 @@ void MatrixEffectColumn::draw() {
|
||||
}
|
||||
}
|
||||
|
||||
void MatrixEffectColumn::loop() {
|
||||
void MatrixEffectColumn::loop(uint16_t ms) {
|
||||
if (!running) {
|
||||
if (random8() < 20) {
|
||||
// Start the column again.
|
||||
restart(false);
|
||||
}
|
||||
} else {
|
||||
advance();
|
||||
advance(ms);
|
||||
draw();
|
||||
}
|
||||
}
|
||||
@ -127,6 +127,17 @@ void RandomMatrixEffectColumn::restart(bool completely_random) {
|
||||
_hue = random8();
|
||||
}
|
||||
|
||||
CRGB ColumnMatrixEffectColumn::_getColor(uint8_t i) {
|
||||
CRGB color;
|
||||
uint8_t dist = abs(length / 2 - i);
|
||||
color = CHSV(_hue, 255, 255 - dist * 5);
|
||||
return color;
|
||||
}
|
||||
|
||||
void ColumnMatrixEffectColumn::restart(bool completely_random) {
|
||||
MatrixEffectColumn::restart(completely_random);
|
||||
_hue = random8();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -136,31 +147,71 @@ void RandomMatrixEffectColumn::restart(bool completely_random) {
|
||||
|
||||
|
||||
|
||||
boolean MatrixEffect::can_be_shown_with_clock() { return true; };
|
||||
|
||||
boolean MatrixEffectBase::can_be_shown_with_clock() { return true; };
|
||||
|
||||
void MatrixEffectBase::_init() {
|
||||
_count = _get_count();
|
||||
_columns = new MatrixEffectColumn* [_count];
|
||||
}
|
||||
|
||||
uint8_t MatrixEffectBase::_get_count() { return settings.effects.matrix.count; }
|
||||
|
||||
MatrixEffect::MatrixEffect() {
|
||||
_columns = new MatrixEffectColumn* [window->width];
|
||||
for (int i=0; i<window->width; i++) _columns[i] = new MatrixEffectColumn(window, MatrixEffectColumn::DIR_SOUTH);
|
||||
_init();
|
||||
_create();
|
||||
}
|
||||
|
||||
void MatrixEffect::_create() {
|
||||
for (int i=0; i<_count; i++) _columns[i] = new MatrixEffectColumn(window, MatrixEffectColumn::DIR_SOUTH);
|
||||
}
|
||||
|
||||
RandomMatrixEffect::RandomMatrixEffect() {
|
||||
_columns = new MatrixEffectColumn* [window->width];
|
||||
for (int i=0; i<window->width; i++) _columns[i] = new RandomMatrixEffectColumn(window, random8(4), true);
|
||||
_init();
|
||||
_create();
|
||||
}
|
||||
|
||||
void RandomMatrixEffect::_create() {
|
||||
for (int i=0; i<_count; i++) _columns[i] = new RandomMatrixEffectColumn(window, random8(4), true);
|
||||
}
|
||||
|
||||
uint8_t RandomMatrixEffect::_get_count() { return settings.effects.matrix.random_count; }
|
||||
|
||||
RainbowMatrixEffect::RainbowMatrixEffect() {
|
||||
_columns = new MatrixEffectColumn* [window->width];
|
||||
for (int i=0; i<window->width; i++) _columns[i] = new RainbowMatrixEffectColumn(window, MatrixEffectColumn::DIR_SOUTH);
|
||||
_init();
|
||||
_create();
|
||||
}
|
||||
|
||||
MatrixEffect::~MatrixEffect() {
|
||||
for (int i=0; i<window->width; i++) {
|
||||
void RainbowMatrixEffect::_create() {
|
||||
for (int i=0; i<_count; i++) _columns[i] = new RainbowMatrixEffectColumn(window, MatrixEffectColumn::DIR_SOUTH);
|
||||
}
|
||||
|
||||
ColumnMatrixEffect::ColumnMatrixEffect() {
|
||||
_init();
|
||||
_create();
|
||||
}
|
||||
|
||||
void ColumnMatrixEffect::_create() {
|
||||
for (int i=0; i<_count; i++) _columns[i] = new ColumnMatrixEffectColumn(window, MatrixEffectColumn::DIR_NORTH);
|
||||
}
|
||||
|
||||
MatrixEffectBase::~MatrixEffectBase() {
|
||||
_delete();
|
||||
}
|
||||
|
||||
void MatrixEffectBase::_delete() {
|
||||
for (int i=0; i<_count; i++) {
|
||||
delete _columns[i];
|
||||
}
|
||||
delete[] _columns;
|
||||
}
|
||||
|
||||
void MatrixEffect::loop() {
|
||||
void MatrixEffectBase::loop(uint16_t ms) {
|
||||
if (_count != _get_count()) {
|
||||
_delete();
|
||||
_init();
|
||||
_create();
|
||||
}
|
||||
window->clear();
|
||||
for (int i=0; i<window->width; i++) _columns[i]->loop();
|
||||
for (int i=0; i<_count; i++) _columns[i]->loop(ms);
|
||||
}
|
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,8 +1,8 @@
|
||||
#include "effect_pixelclock.h"
|
||||
#include "effects/pixelclock.h"
|
||||
#include "ntp.h"
|
||||
|
||||
PixelClockEffect::PixelClockEffect() {
|
||||
window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
|
||||
window = &Window::window_with_clock;
|
||||
_color_seconds = new CRGB(0x00FF00);
|
||||
_color_minutes = new CRGB(0xFFFF00);
|
||||
}
|
||||
@ -10,21 +10,25 @@ PixelClockEffect::PixelClockEffect() {
|
||||
PixelClockEffect::~PixelClockEffect() {
|
||||
delete _color_seconds;
|
||||
delete _color_minutes;
|
||||
delete window;
|
||||
}
|
||||
|
||||
void PixelClockEffect::loop() {
|
||||
void PixelClockEffect::loop(uint16_t ms) {
|
||||
uint8_t x, y; // Temporary variables for calculating positions
|
||||
window->clear();
|
||||
time_t now;
|
||||
tm timeinfo;
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
|
||||
// Seconds
|
||||
uint8_t seconds = ntpClient.getSeconds();
|
||||
uint8_t seconds = timeinfo.tm_sec;
|
||||
for (uint8_t s=0; s<60; s++) {
|
||||
x = window->width - 1 - s/10;
|
||||
y = window->height - 1 - (s % 10);
|
||||
if (s<seconds) window->setPixel(x, y, _color_seconds);
|
||||
}
|
||||
|
||||
uint8_t minutes = ntpClient.getMinutes();
|
||||
uint8_t minutes = timeinfo.tm_min;
|
||||
for (uint8_t m=0; m<60; m++) {
|
||||
x = 6 - m/10;
|
||||
y = window->height - 1 - (m % 10);
|
@ -1,11 +1,11 @@
|
||||
#include "effect_sinematrix3.h"
|
||||
#include "effects/sinematrix3.h"
|
||||
#include "prototypes.h"
|
||||
#include "functions.h"
|
||||
#include "Effect.h"
|
||||
#include "my_color_palettes.h"
|
||||
|
||||
boolean Sinematrix3Effect::can_be_shown_with_clock() { return true; };
|
||||
boolean Sinematrix3Effect::clock_as_mask() { return true; };
|
||||
void Sinematrix3Effect::loop() {
|
||||
void Sinematrix3Effect::loop(uint16_t ms) {
|
||||
pangle = addmodpi( pangle, 0.0133 + (angle / 256) );
|
||||
angle = cos(pangle) * PI;
|
||||
sx = addmodpi( sx, 0.00673 );
|
||||
@ -44,8 +44,22 @@ void Sinematrix3Effect::loop() {
|
||||
for ( int y = 0; y < LED_HEIGHT; y++ ) {
|
||||
Vector c = add(multiply( multiply(rotate, zoom), { .x1 = x - rcx, .x2 = y - rcy } ), translate);
|
||||
int sat = (basecol + basefield(c.x1, c.x2)) * 255;
|
||||
CRGB color(CHSV(sat, 120, 255));
|
||||
CRGB color(_get_color(sat));
|
||||
window->setPixel(x, y, &color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CRGB Sinematrix3Effect::_get_color(int sat) {
|
||||
switch(_color_scheme) {
|
||||
case SINEMATRIX_COLOR_PASTEL_RAINBOW: return CRGB(CHSV(sat, 120, 255));
|
||||
case SINEMATRIX_COLOR_RAINBOW: return CRGB(CHSV(sat, 255, 255));
|
||||
case SINEMATRIX_COLOR_PURPLEFLY: return ColorFromPalette((CRGBPalette16)palette_purplefly_gp, (uint8_t)sat);
|
||||
}
|
||||
return CRGB(0xFF00FF);
|
||||
}
|
||||
|
||||
boolean Sinematrix3Effect::clock_as_mask() {
|
||||
if (_color_scheme == SINEMATRIX_COLOR_PASTEL_RAINBOW) return true;
|
||||
return false;
|
||||
};
|
57
src/effects/sines.cpp
Normal file
57
src/effects/sines.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include "effects/sines.h"
|
||||
|
||||
SinesEffectSinus::SinesEffectSinus(Window* w) {
|
||||
_window = w;
|
||||
_frequency = random16(6<<8, 30<<8);
|
||||
_color_frequency = random16(128, 2<<8);
|
||||
_x = random16(1<<8, (_window->width-2)<<8);
|
||||
accum88 diff = (_window->width<<8) - _x;
|
||||
if (_x > diff) diff=_x;
|
||||
_amplitude = random16(1<<8, diff);
|
||||
_offset = random16();
|
||||
}
|
||||
|
||||
void SinesEffectSinus::loop(uint16_t ms) {
|
||||
accum88 x = beatsin88(_frequency, _x-_amplitude, _x+_amplitude, _offset);
|
||||
CRGB color = CHSV(beat88(_color_frequency, _offset)>>8, 255, 255);
|
||||
_window->setSubPixel(x, 0, &color);
|
||||
}
|
||||
|
||||
SinesEffect::SinesEffect() {
|
||||
_init();
|
||||
}
|
||||
|
||||
void SinesEffect::_init() {
|
||||
_count = settings.effects.sines.count;
|
||||
_sinus = new SinesEffectSinus*[_count];
|
||||
for (int i=0; i<_count; i++) {
|
||||
_sinus[i] = new SinesEffectSinus(window);
|
||||
}
|
||||
}
|
||||
|
||||
SinesEffect::~SinesEffect() {
|
||||
_delete();
|
||||
}
|
||||
|
||||
void SinesEffect::_delete() {
|
||||
for (int i=0; i<_count; i++) {
|
||||
delete _sinus[i];
|
||||
}
|
||||
delete [] _sinus;
|
||||
}
|
||||
|
||||
boolean SinesEffect::can_be_shown_with_clock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SinesEffect::loop(uint16_t ms) {
|
||||
if (settings.effects.sines.count != _count) {
|
||||
_delete();
|
||||
_init();
|
||||
}
|
||||
// do stuff
|
||||
window->shift_down_and_blur();
|
||||
for (int i=0; i<_count; i++) {
|
||||
_sinus[i]->loop(ms);
|
||||
}
|
||||
}
|
344
src/effects/snake.cpp
Normal file
344
src/effects/snake.cpp
Normal file
@ -0,0 +1,344 @@
|
||||
#include "effects/snake.h"
|
||||
#include "functions.h"
|
||||
|
||||
SnakeEffect::SnakeEffect() {
|
||||
window = &Window::window_with_clock;
|
||||
_pixels = window->width * window->height;
|
||||
_map = new uint8_t[_pixels];
|
||||
_init();
|
||||
}
|
||||
|
||||
void SnakeEffect::_init() {
|
||||
_dying = 0;
|
||||
_round = 0;
|
||||
_last_apple_at = millis();
|
||||
_last_move_at = millis();
|
||||
_dir = SNAKE_DIR_NORTH;
|
||||
_length = 4;
|
||||
_pos = {(uint8_t)(window->width/2), (uint8_t)(window->height/2)};
|
||||
for (int i=0; i<_pixels; i++) _map[i]=0;
|
||||
_map[_xy2i(_pos)]=1;
|
||||
_map[_xy2i(_pos)+window->width*1]=2;
|
||||
_map[_xy2i(_pos)+window->width*2]=3;
|
||||
_map[_xy2i(_pos)+window->width*3]=4;
|
||||
_place_apple();
|
||||
}
|
||||
|
||||
SnakeEffect::~SnakeEffect() {
|
||||
delete _map;
|
||||
}
|
||||
|
||||
void SnakeEffect::_place_apple() {
|
||||
if (_length < _pixels) {
|
||||
uint8_t start = random8(_pixels);
|
||||
for (int i=0; i<_pixels; i++) {
|
||||
if (_map[start + i]==0) {
|
||||
_apple = _i2xy(start + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SnakeEffect::_decide() {
|
||||
uint8_t f_l = _free_spaces(_dir - 1);
|
||||
uint8_t f_s = _free_spaces(_dir);
|
||||
uint8_t f_r = _free_spaces(_dir + 1);
|
||||
uint8_t a_l = _to_apple(_dir - 1);
|
||||
uint8_t a_s = _to_apple(_dir);
|
||||
uint8_t a_r = _to_apple(_dir + 1);
|
||||
|
||||
float* inputs = new float[6];
|
||||
inputs[0] = f_l;
|
||||
inputs[1] = f_s;
|
||||
inputs[2] = f_r;
|
||||
inputs[3] = a_l;
|
||||
inputs[4] = a_s;
|
||||
inputs[5] = a_r;
|
||||
if (SNAKE_DEBUG) DBG("SnakeEffect * Position: %d, %d - Inputs: %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f", _pos.x, _pos.y, inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5]);
|
||||
float* outputs = NULL;
|
||||
uint8_t i=0;
|
||||
for (uint8_t layer=1; layer<_net_layers; layer++) {
|
||||
outputs = new float[_net_layout[layer]];
|
||||
for (uint8_t j=0; j<_net_layout[layer]; j++) {
|
||||
outputs[j] = 0.0;
|
||||
}
|
||||
for (uint8_t idx_out=0; idx_out<_net_layout[layer]; idx_out++) {
|
||||
for (uint8_t idx_in=0; idx_in<_net_layout[layer-1]; idx_in++) {
|
||||
float weight;
|
||||
memcpy(&weight, &(_weights[i]), sizeof(weight));
|
||||
outputs[idx_out] += weight * inputs[idx_in];
|
||||
//outputs[idx_out] += (*(float*)&(_weights[i])) * inputs[idx_in];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
delete inputs;
|
||||
inputs = outputs;
|
||||
}
|
||||
|
||||
int8_t decision = 0;
|
||||
float last;
|
||||
for (uint8_t i=0; i<_net_layout[_net_layers - 1]; i++) {
|
||||
if (i==0 || outputs[i]>last) {
|
||||
last = outputs[i];
|
||||
decision = i;
|
||||
}
|
||||
}
|
||||
decision = decision - 1;
|
||||
delete outputs;
|
||||
|
||||
if (SNAKE_DEBUG) DBG("SnakeEffect * Decision: %d", decision);
|
||||
|
||||
_dir += decision;
|
||||
if (_dir < 0) _dir += 4;
|
||||
if (_dir > 3) _dir -= 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is old (and hence disabled) code, showing
|
||||
* a simple, hand-crafted "AI" for plaing snake.
|
||||
**
|
||||
int8_t SnakeEffect::_manual_decision() {
|
||||
bool free_l = _is_free(_dir - 1);
|
||||
bool free_s = _is_free(_dir);
|
||||
bool free_r = _is_free(_dir + 1);
|
||||
bool apple_l = _to_apple(_dir - 1);
|
||||
bool apple_s = _to_apple(_dir);
|
||||
bool apple_r = _to_apple(_dir + 1);
|
||||
|
||||
if (!free_s) {
|
||||
if (apple_l && free_l) return -1;
|
||||
if (apple_r && free_r) return 1;
|
||||
if (free_l) return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (apple_s) return 0;
|
||||
if (apple_l && free_l) return -1;
|
||||
if (apple_r && free_r) return 1;
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
/* This uses a predefined meandering path through the complete field.
|
||||
The snake always tries to reach the field matching following criteria:
|
||||
(1) Being free.
|
||||
(2) Having a number smaller than the field the apple is on. (Watch out for "overflows".)
|
||||
*/
|
||||
int8_t SnakeEffect::_manual_decision() {
|
||||
uint8_t head_index = _coords_to_field_id(_pos);
|
||||
uint8_t apple_index = _coords_to_field_id(_apple);
|
||||
uint8_t tail_index = _coords_to_field_id(_tail);
|
||||
if (SNAKE_DEBUG) DBG("SnakeEffect * Decision. head: %d, apple: %d, tail: %d", head_index, apple_index, tail_index);
|
||||
|
||||
uint16_t best_distance = 0xFFFF;
|
||||
int8_t decision = 0;
|
||||
|
||||
for (int i=-1; i<=1; i++) { // Test all thre possible directions (left, ahead, right)
|
||||
Coords new_pos = _new_pos(_dir + i);
|
||||
uint8_t new_index = _coords_to_field_id(new_pos);
|
||||
|
||||
int16_t distance;
|
||||
if (apple_index >= new_index) {
|
||||
distance = apple_index - new_index;
|
||||
} else {
|
||||
distance = (window->width * window->height) - apple_index + new_index;
|
||||
}
|
||||
if (SNAKE_DEBUG) DBG("SnakeEffect * Decision: %d would have distance %d", i, distance);
|
||||
if (distance < best_distance && _is_free(_dir + i)) {
|
||||
best_distance = distance;
|
||||
decision = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (SNAKE_DEBUG) DBG("SnakeEffect * Decision taken: %d with distance %d", decision, best_distance);
|
||||
|
||||
/* apple_index > new_index && head_index > apple_index
|
||||
apple_index > new_index && head_index < apple_index && new_index > head_index
|
||||
|
||||
uint16_t head_index = (_head_rounds<<8) | _coords_to_field_id(_pos);
|
||||
uint16_t apple_index = (_head_rounds<<8) | _coords_to_field_id(_apple);
|
||||
uint16_t tail_index = (_tail_rounds<<8) | _coords_to_field_id(_tail);
|
||||
|
||||
if (apple_index < head_index) apple_index += 0x100;
|
||||
|
||||
uint8_t best_dist = 0xFF;
|
||||
int8_t decision = 0;
|
||||
for (int i=-1; i<=1; i++) {
|
||||
Coords new_pos = _new_pos(_dir + i);
|
||||
uint16_t theoretical_index = (_head_rounds<<8) | _coords_to_field_id(new_pos);
|
||||
if (theoretical_index < head_index) theoretical_index += 0x100;
|
||||
int16_t dist = apple_index - theoretical_index;
|
||||
if (dist < 0) dist += window->height * window->width;
|
||||
if (dist < best_dist && _is_free(_dir + i) && theoretical_index<tail_index && theoretical_index<tail_index) {
|
||||
decision = i;
|
||||
best_dist = dist;
|
||||
}
|
||||
}*/
|
||||
_dir = (_dir + decision) % 4;
|
||||
return decision;
|
||||
}
|
||||
|
||||
bool SnakeEffect::_is_free(uint8_t dir) {
|
||||
return _free_spaces(dir)!=0;
|
||||
}
|
||||
|
||||
uint8_t SnakeEffect::_free_spaces(uint8_t dir) {
|
||||
int8_t x=0;
|
||||
int8_t y=0;
|
||||
uint8_t d = dir % 4;
|
||||
switch(d) {
|
||||
case SNAKE_DIR_NORTH: y=-1; break;
|
||||
case SNAKE_DIR_EAST: x=1; break;
|
||||
case SNAKE_DIR_SOUTH: y=1; break;
|
||||
case SNAKE_DIR_WEST: x=-1; break;
|
||||
}
|
||||
Coords p(_pos);
|
||||
uint8_t i=0;
|
||||
while (true) {
|
||||
p.x += x;
|
||||
p.y += y;
|
||||
if (p.x<0 || p.x>=window->width || p.y<0 || p.y>=window->height || _map[_xy2i(p)]!=0) {
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t SnakeEffect::_coords_to_field_id(Coords c) {
|
||||
if (c.y==0) return window->width - c.x;
|
||||
if (c.x % 2 == 0) {
|
||||
// even columns
|
||||
return window->width + c.x*(window->height - 1) + c.y - 1;
|
||||
} else {
|
||||
// odd columns
|
||||
return window->width + (c.x+1)*(window->height-1) - c.y;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t SnakeEffect::_to_apple(uint8_t dir) {
|
||||
uint8_t d = dir % 4;
|
||||
int8_t d_x = _apple.x - _pos.x;
|
||||
int8_t d_y = _apple.y - _pos.y;
|
||||
|
||||
switch(d) {
|
||||
case SNAKE_DIR_NORTH: return d_y < 0 ? -d_y : 0;
|
||||
case SNAKE_DIR_EAST: return d_x > 0 ? d_x : 0;
|
||||
case SNAKE_DIR_SOUTH: return d_y > 0 ? d_y : 0;
|
||||
case SNAKE_DIR_WEST: return d_x < 0 ? -d_x : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Coords SnakeEffect::_new_pos(uint8_t dir) {
|
||||
uint8_t d = dir % 4;
|
||||
Coords p(_pos);
|
||||
switch(d) {
|
||||
case SNAKE_DIR_NORTH: p.y--; break;
|
||||
case SNAKE_DIR_EAST: p.x++; break;
|
||||
case SNAKE_DIR_SOUTH: p.y++; break;
|
||||
case SNAKE_DIR_WEST: p.x--; break;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
uint16_t SnakeEffect::_xy2i(Coords c) {
|
||||
return _xy2i(c.x, c.y);
|
||||
}
|
||||
|
||||
uint16_t SnakeEffect::_xy2i(uint8_t x, uint8_t y) {
|
||||
return y*window->width + x;
|
||||
}
|
||||
|
||||
Coords SnakeEffect::_i2xy(uint16_t i) {
|
||||
return {(uint16_t)(i%window->width), (uint16_t)(i/window->width)};
|
||||
}
|
||||
|
||||
void SnakeEffect::_move() {
|
||||
|
||||
|
||||
if (_dying > 0) {
|
||||
_dying--;
|
||||
|
||||
if (_dying==0) {
|
||||
_init();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned long now = millis();
|
||||
if (_last_move_at < now && now - _last_move_at < 50) {
|
||||
return;
|
||||
}
|
||||
_round++;
|
||||
_last_move_at = now;
|
||||
_manual_decision();
|
||||
|
||||
if (_dying==0 && !_is_free(_dir)) {
|
||||
_dying = 150;
|
||||
return;
|
||||
}
|
||||
|
||||
_pos = _new_pos(_dir);
|
||||
|
||||
uint8_t index_head = _coords_to_field_id(_pos);
|
||||
uint8_t index_tail = _coords_to_field_id(_tail);
|
||||
|
||||
if (SNAKE_DEBUG) LOGln("SnakeEffect * new_pos: %d, %d", _pos.x, _pos.y);
|
||||
if (SNAKE_DEBUG) LOGln("SnakeEffect * apple: %d, %d", _apple.x, _apple.y);
|
||||
if (_pos.x==_apple.x && _pos.y==_apple.y) {
|
||||
_last_apple_at = millis();
|
||||
_length++;
|
||||
}
|
||||
for (int i=0; i<_pixels; i++) {
|
||||
if (_map[i]>0 && _map[i]<_length-1) {
|
||||
_map[i]++;
|
||||
if (_map[i]==_length-1) {
|
||||
_tail = _i2xy(i);
|
||||
}
|
||||
}
|
||||
else _map[i]=0;
|
||||
}
|
||||
_map[_xy2i(_pos)] = 1;
|
||||
if (_pos.x==_apple.x && _pos.y==_apple.y) {
|
||||
_place_apple();
|
||||
}
|
||||
|
||||
if (index_head > _coords_to_field_id(_pos)) _head_rounds++;
|
||||
if (index_tail > _coords_to_field_id(_tail)) _tail_rounds++;
|
||||
if (_head_rounds > 0 && _head_rounds > 0) {
|
||||
uint8_t min = (_head_rounds < _tail_rounds) ? _tail_rounds : _head_rounds;
|
||||
_head_rounds -= min;
|
||||
_tail_rounds -= min;
|
||||
}
|
||||
}
|
||||
|
||||
void SnakeEffect::_draw() {
|
||||
if (_dying) {
|
||||
window->fadeToBlackBy(4);
|
||||
return;
|
||||
}
|
||||
window->clear();
|
||||
CRGB red(0xBB0000);
|
||||
for (int i=0; i<_pixels; i++) {
|
||||
if (_map[i]>0) window->setPixelByIndex(i, &red);
|
||||
}
|
||||
CRGB white(0xFFFFFF);
|
||||
window->setPixel(_pos.x, _pos.y, &white);
|
||||
CRGB green(0xFFFF00);
|
||||
window->setPixel(_apple.x, _apple.y, &green);
|
||||
}
|
||||
|
||||
void SnakeEffect::loop(uint16_t ms) {
|
||||
//window->fadeToBlackBy(2);
|
||||
//CRGB color(CHSV(hue, 200, 255));
|
||||
//window->setPixel(this->coords.x, this->coords.y, &color);
|
||||
//hue++;
|
||||
if (_dying==0 && (millis() < _last_apple_at || millis() - _last_apple_at > 30000)) {
|
||||
_dying = 150;
|
||||
}
|
||||
_move();
|
||||
_draw();
|
||||
}
|
||||
|
||||
boolean SnakeEffect::can_be_shown_with_clock() { return true; }
|
@ -1,4 +1,4 @@
|
||||
#include "effect_static.h"
|
||||
#include "effects/static.h"
|
||||
#include "functions.h"
|
||||
#include "my_fastled.h"
|
||||
|
||||
@ -6,7 +6,7 @@ StaticEffect::StaticEffect(CRGB col) {
|
||||
color = col;
|
||||
}
|
||||
|
||||
void StaticEffect::loop() {
|
||||
void StaticEffect::loop(uint16_t ms) {
|
||||
EVERY_N_SECONDS(1) {
|
||||
window->clear(&color);
|
||||
}
|
38
src/effects/timer.cpp
Normal file
38
src/effects/timer.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "effects/timer.h"
|
||||
#include <FastLED.h>
|
||||
#include "functions.h"
|
||||
#include "fonts.h"
|
||||
#include "ntp.h"
|
||||
|
||||
void TimerEffect::loop(uint16_t ms) {
|
||||
if (timer==0) return;
|
||||
|
||||
CRGB bg_color(0x000000);
|
||||
CRGB fg_color(0xCCCCCC);
|
||||
time_t now;
|
||||
time(&now);
|
||||
long diff = timer - now;
|
||||
window->clear(&bg_color);
|
||||
if (diff < 0 && (now & 1)==0) return;
|
||||
if (diff < 0) diff = 0;
|
||||
int hours = diff / 3600;
|
||||
int minutes = diff / 60;
|
||||
int seconds = diff % 60;
|
||||
if (minutes > 99) {
|
||||
seconds = minutes % 60;
|
||||
minutes = hours;
|
||||
}
|
||||
//void drawChar(Font f, uint8_t x, uint8_t y, const char c, CRGB* color, bool mask=false);
|
||||
window->drawChar(&font_numbers3x5, 0<<8, 0<<8, '0' + (minutes / 10), &fg_color);
|
||||
window->drawChar(&font_numbers3x5, 4<<8, 0<<8, '0' + (minutes % 10), &fg_color);
|
||||
window->drawChar(&font_numbers3x5, 9<<8, 0<<8, '0' + (seconds / 10), &fg_color);
|
||||
window->drawChar(&font_numbers3x5, 13<<8, 0<<8, '0' + (seconds % 10), &fg_color);
|
||||
if (now & 1) {
|
||||
window->setPixel(7, 1, &fg_color);
|
||||
window->setPixel(7, 3, &fg_color);
|
||||
}
|
||||
}
|
||||
|
||||
TimerEffect::~TimerEffect() {
|
||||
delete window;
|
||||
}
|
181
src/effects/tpm2_net.cpp
Normal file
181
src/effects/tpm2_net.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
#include "effects/tpm2_net.h"
|
||||
#include "my_fastled.h"
|
||||
|
||||
void Tpm2NetEffect::loop(uint16_t ms) {
|
||||
int packetsize = _udp.parsePacket();
|
||||
uint8_t data[255];
|
||||
uint8_t type = 0x00;
|
||||
if (packetsize > 0) {
|
||||
_last_packet_at = millis();
|
||||
DBG("TPM2.Net * Received %d bytes from %s", packetsize, _udp.remoteIP().toString().c_str());
|
||||
if (packetsize < 7) {
|
||||
LOGln("TPM2.Net * Packet is too short. Ignoring it.");
|
||||
return;
|
||||
}
|
||||
_udp.read(data, 6);
|
||||
if (data[0] != 0x9C) {
|
||||
LOGln("TPM2.Net * Block start byte is 0x%02X, expected 0x9C", data[0]);
|
||||
return;
|
||||
}
|
||||
if (data[1] == 0xC0) {
|
||||
DBG("TPM2.Net * Received a command packet.");
|
||||
type = 0xC0;
|
||||
} else if (data[1] == 0xDA) {
|
||||
DBG("TPM2.Net * Received a data packet.");
|
||||
type = 0xDA;
|
||||
} else {
|
||||
LOGln("TPM2.Net * Unexpected packet type 0x%02X, expected 0xC0 or 0xDA.", data[1]);
|
||||
}
|
||||
uint16_t framesize = (data[2]<<8) | data[3];
|
||||
uint8_t packet_number = data[4];
|
||||
//uint8_t packet_count = data[5];
|
||||
|
||||
if (packetsize != framesize + 7) {
|
||||
LOGln("TPM2.Net * Invalid packet size. Expected %d bytes, was %d bytes.", framesize+7, packetsize);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type==0xC0) {
|
||||
_parse_command(framesize, packet_number);
|
||||
} else if (type==0xDA) {
|
||||
_parse_data(framesize, packet_number);
|
||||
}
|
||||
} else if (_last_packet_at + 5000 < millis()) {
|
||||
window->fill_with_checkerboard();
|
||||
}
|
||||
}
|
||||
|
||||
void Tpm2NetEffect::_parse_command(uint16_t size, uint8_t packet_number) {
|
||||
if (packet_number!=0) {
|
||||
LOGln("TPM2.Net * Command packet with packet_number > 0 (%d). Ignoring it.", packet_number);
|
||||
return;
|
||||
}
|
||||
if (size < 2) {
|
||||
LOGln("TPM2.Net * Command packet need at least 2 data bytes.");
|
||||
return;
|
||||
}
|
||||
uint8_t ctrl = _udp.read();
|
||||
bool write = ctrl & 0x80;
|
||||
bool respond = ctrl & 0x40;
|
||||
uint8_t cmd = _udp.read();
|
||||
uint8_t data = 0;
|
||||
if (write) {
|
||||
if (size<3) {
|
||||
LOGln("TPM2.Net * Got a write command, but no data to write.");
|
||||
return;
|
||||
}
|
||||
data = _udp.read();
|
||||
}
|
||||
|
||||
if (cmd == 0x0A) { // Master Brightness
|
||||
if (write) {
|
||||
FastLED.setBrightness(data);
|
||||
} else {
|
||||
uint8_t data[1] = {FastLED.getBrightness()};
|
||||
_respond_with_data(data, 1);
|
||||
}
|
||||
} else if (cmd == 0x10 && !write) {
|
||||
uint16_t pixels = window->width * window->height;
|
||||
uint8_t data[2] = {(uint8_t)(pixels >> 8), (uint8_t)(pixels & 0xFF)};
|
||||
_respond_with_data(data, 2);
|
||||
} else {
|
||||
LOGln("TPM2.Net * Unknown command. write:%d, command:0x%02X", write, cmd);
|
||||
if (respond) {
|
||||
_respond_unknown_command();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tpm2NetEffect::_parse_data(uint16_t framesize, uint8_t packet_number) {
|
||||
if (packet_number==0) {
|
||||
_pixel_index=0;
|
||||
}
|
||||
uint8_t len;
|
||||
uint8_t data[3];
|
||||
CRGB color;
|
||||
while ((len = _udp.read(data, 3))==3) {
|
||||
// We got 3 bytes
|
||||
color.setRGB(data[0], data[1], data[2]);
|
||||
window->setPixelByIndex(_pixel_index, &color);
|
||||
_pixel_index++;
|
||||
}
|
||||
|
||||
/*
|
||||
bool dir_changed = false;
|
||||
|
||||
_x += _x_dir * settings.effects.dvd.speed;
|
||||
_y += _y_dir * settings.effects.dvd.speed;
|
||||
|
||||
if (_x <= 0) {
|
||||
_x = -_x;
|
||||
_x_dir = -_x_dir;
|
||||
dir_changed = true;
|
||||
//LOGln("speed: %d", settings.effects.dvd.speed);
|
||||
} else if (_x + (settings.effects.dvd.width << 8) >= (window->width << 8)) {
|
||||
_x -= 2*settings.effects.dvd.speed;
|
||||
_x_dir = -_x_dir;
|
||||
dir_changed = true;
|
||||
}
|
||||
|
||||
if (_y <= 0) {
|
||||
_y = -_y;
|
||||
_y_dir = -_y_dir;
|
||||
dir_changed = true;
|
||||
} else if (_y + (settings.effects.dvd.height << 8) >= (window->height << 8)) {
|
||||
_y -= 2*settings.effects.dvd.speed;
|
||||
_y_dir = -_y_dir;
|
||||
dir_changed = true;
|
||||
}
|
||||
|
||||
window->clear();
|
||||
|
||||
if (dir_changed) _color = (CRGB)CHSV(random8(), 255, 255);
|
||||
|
||||
for (int x=0; x<settings.effects.dvd.width; x++) for (int y=0; y<settings.effects.dvd.height; y++) {
|
||||
window->setSubPixel(_x + (x<<8), _y + (y<<8), (CRGB*)&_color);
|
||||
}
|
||||
for (int x=1; x<settings.effects.dvd.width; x++) for (int y=1; y<settings.effects.dvd.height; y++) {
|
||||
window->setPixel((_x>>8) + x, (_y>>8) + y, (CRGB*)&_color);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void Tpm2NetEffect::_respond(uint8_t* data, uint8_t len) {
|
||||
_udp.beginPacket(_udp.remoteIP(), 65442);
|
||||
_udp.write(data, len);
|
||||
_udp.endPacket();
|
||||
}
|
||||
|
||||
void Tpm2NetEffect::_respond_ack() {
|
||||
uint8_t data[8] = {0x9C, 0xAC, 0x00, 0x01, 0x00, 0x01, 0x00, 0x36};
|
||||
_respond(data, 8);
|
||||
}
|
||||
|
||||
void Tpm2NetEffect::_respond_unknown_command() {
|
||||
uint8_t data[8] = {0x9C, 0xAC, 0x00, 0x01, 0x00, 0x01, 0x02, 0x36};
|
||||
_respond(data, 8);
|
||||
}
|
||||
|
||||
void Tpm2NetEffect::_respond_with_data(uint8_t* dat, uint8_t len) {
|
||||
uint8_t data[8 + len];
|
||||
data[0] = 0x9C;
|
||||
data[1] = 0xAD;
|
||||
data[2] = (len+1)>>8;
|
||||
data[3] = (len+1)&0xFF;
|
||||
data[4] = 0x00;
|
||||
data[5] = 0x01;
|
||||
data[6] = 0x00;
|
||||
memcpy(&(data[7]), dat, len);
|
||||
data[8 + len - 1] = 0x36;
|
||||
_respond(data, 8 + len);
|
||||
}
|
||||
|
||||
bool Tpm2NetEffect::can_be_shown_with_clock() { return false; }
|
||||
|
||||
Tpm2NetEffect::Tpm2NetEffect() {
|
||||
_udp.begin(65506);
|
||||
}
|
||||
|
||||
Tpm2NetEffect::~Tpm2NetEffect() {
|
||||
_udp.stop();
|
||||
}
|
27
src/effects/tv_static.cpp
Normal file
27
src/effects/tv_static.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#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;
|
||||
accum88 dark_position = (beat16(settings.effects.tv_static.black_bar_speed) * _window->width) >> 8;
|
||||
for (uint8_t y=0; y<_window->height; y++) {
|
||||
accum88 row_dark_position = (dark_position + (y<<8)/3) % (_window->width<<8);
|
||||
for (uint8_t x=0; x<_window->width; x++) {
|
||||
uint8_t brightness = random8();
|
||||
uint8_t darkening = 0;
|
||||
accum88 distance = (x<<8) - row_dark_position;
|
||||
if (distance < 256) darkening = random8(distance, 255);
|
||||
else if (distance < (4<<8)) darkening = random8(distance >> 2, 255);
|
||||
|
||||
if (darkening > brightness) brightness = 0;
|
||||
else brightness -= darkening;
|
||||
CRGB color(brightness, brightness, brightness);
|
||||
_window->setPixel(x, y, &color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TvStaticEffect::can_be_shown_with_clock() { return true; }
|
||||
|
||||
TvStaticEffect::~TvStaticEffect() {
|
||||
delete _window;
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
#include "effect_twirl.h"
|
||||
#include "effects/twirl.h"
|
||||
#include "functions.h"
|
||||
|
||||
boolean TwirlEffect::can_be_shown_with_clock() { return true; };
|
||||
boolean TwirlEffect::clock_as_mask() { return true; };
|
||||
boolean TwirlEffect::clock_as_mask() { return false; };
|
||||
|
||||
void TwirlEffect::loop() {
|
||||
void TwirlEffect::loop(uint16_t ms) {
|
||||
double center_x = _real_center_x; // - (cos8(_center_offset_angle)>>6);
|
||||
double center_y = _real_center_y; // + (sin8(_center_offset_angle)>>6);
|
||||
for (int x=0; x<window->width; x++) for (int y=0; y<window->height; y++) {
|
@ -16,13 +16,29 @@ bool font_numbers3x5_check(const char c) { return c>='0' && c<='9'; }
|
||||
uint16_t font_numbers3x5_get(const char c) { return c - '0'; }
|
||||
Font font_numbers3x5 = {3, 5, &font_numbers3x5_data[0], font_numbers3x5_check, font_numbers3x5_get};
|
||||
|
||||
const uint8_t font_numbers3x3_data[] PROGMEM = {
|
||||
B111, B101, B111, // 0
|
||||
B101, B111, B001, // 1
|
||||
B100, B111, B001, // 2
|
||||
B101, B111, B111, // 3
|
||||
B110, B010, B111, // 4
|
||||
B001, B111, B100, // 5
|
||||
B111, B011, B011, // 6
|
||||
B100, B100, B111, // 7
|
||||
B011, B111, B111, // 8
|
||||
B110, B110, B111, // 9
|
||||
};
|
||||
bool font_numbers3x3_check(const char c) { return c>='0' && c<='9'; }
|
||||
uint16_t font_numbers3x3_get(const char c) { return c - '0'; }
|
||||
Font font_numbers3x3 = {3, 3, &font_numbers3x3_data[0], font_numbers3x3_check, font_numbers3x3_get};
|
||||
|
||||
const uint8_t font_numbers3x5_blocky_data[] PROGMEM = {
|
||||
B11111, B10001, B11111, // 0
|
||||
B00000, B11111, B00000, // 1
|
||||
B10111, B10101, B11101, // 2
|
||||
B10001, B10101, B11111, // 3
|
||||
B11100, B00100, B11111, // 4
|
||||
B11101, B10101, B11111, // 5
|
||||
B11101, B10101, B10111, // 5
|
||||
B11111, B10101, B10111, // 6
|
||||
B10000, B10000, B11111, // 7
|
||||
B11111, B10101, B11111, // 8
|
||||
@ -150,12 +166,6 @@ const uint8_t font5x7_data[] PROGMEM = {
|
||||
0x08, 0x08, 0x2A, 0x1C, 0x08, // ->
|
||||
0x08, 0x1C, 0x2A, 0x08, 0x08, // <-
|
||||
};
|
||||
|
||||
bool font5x7_check(const char c) { return c>=' ' && c<='}'; }
|
||||
|
||||
uint16_t font5x7_get(const char c) { return c - ' '; }
|
||||
|
||||
Font font5x7 = {5, 7, &font5x7_data[0], font5x7_check, font5x7_get};
|
||||
|
||||
|
||||
|
||||
|
@ -5,130 +5,378 @@
|
||||
#include "http_server.h"
|
||||
#include "effects.h"
|
||||
#include "my_wifi.h"
|
||||
#include "functions.h"
|
||||
#include "prototypes.h"
|
||||
#include <FS.h>
|
||||
|
||||
#if defined( ESP8266 )
|
||||
ESP8266WebServer http_server(HTTP_SERVER_PORT);
|
||||
#elif defined( ESP32 )
|
||||
ESP32WebServer http_server(HTTP_SERVER_PORT);
|
||||
#endif
|
||||
AsyncWebServer http_server(HTTP_SERVER_PORT);
|
||||
AsyncWebSocket ws("/ws");
|
||||
uint32_t monitor_client = 0;
|
||||
|
||||
File upload_file;
|
||||
|
||||
void http_server_handle_file_upload() {
|
||||
if (http_server.uri() != "/upload") return;
|
||||
|
||||
HTTPUpload upload = http_server.upload();
|
||||
|
||||
if (upload.status == UPLOAD_FILE_START) {
|
||||
String filename = upload.filename;
|
||||
if (!filename.startsWith("/")) filename = "/" + filename;
|
||||
LOGln("HTTP * Upload of %s starting...", upload.filename.c_str());
|
||||
void http_server_handle_file_upload(AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final) {
|
||||
File upload_file;
|
||||
if (index == 0) { // Start of upload
|
||||
LOGln("HTTP * Upload of %s starting...", filename.c_str());
|
||||
upload_file = SPIFFS.open(filename, "w");
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
if (upload_file) upload_file.write(upload.buf, upload.currentSize);
|
||||
} else if (upload.status == UPLOAD_FILE_END) {
|
||||
if (upload_file) upload_file.close();
|
||||
LOGln("HTTP * Upload of %s with %d bytes done.", upload.filename.c_str(), upload.totalSize);
|
||||
} else {
|
||||
upload_file = SPIFFS.open(filename, "a");
|
||||
}
|
||||
|
||||
upload_file.write(data, len);
|
||||
|
||||
if (final) {
|
||||
LOGln("HTTP * Upload of %s done.", filename.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void http_server_400() {
|
||||
http_server.send(400);
|
||||
void ws_send_effects(AsyncWebSocketClient* client) {
|
||||
String msg = "{\"effects\": [";
|
||||
for (int i=0; i<effects_size; i++) {
|
||||
if (i>0) msg += ", ";
|
||||
msg += '"';
|
||||
msg += effects[i].name;
|
||||
msg += '"';
|
||||
}
|
||||
msg += "]}";
|
||||
client->text(msg);
|
||||
}
|
||||
|
||||
void ws_send_settings(AsyncWebSocketClient* client) {
|
||||
String msg = "{\"settings\": [";
|
||||
for (int i=0; i<all_settings_size; i++) {
|
||||
if (i>0) msg += ", ";
|
||||
msg += "{\"name\":\"";
|
||||
msg += all_settings[i].name;
|
||||
msg += "\",\"value\":";
|
||||
msg += *(all_settings[i].value);
|
||||
msg += ",\"type\":\"";
|
||||
switch (all_settings[i].type) {
|
||||
case TYPE_UINT8: msg += "uint8"; break;
|
||||
case TYPE_UINT16: msg += "uint16"; break;
|
||||
case TYPE_BOOL: msg += "bool"; break;
|
||||
default: msg += "unknown";
|
||||
}
|
||||
msg += "\"}";
|
||||
}
|
||||
msg += "]}";
|
||||
client->text(msg);
|
||||
}
|
||||
|
||||
void ws_set_setting(String s) {
|
||||
int8_t index = s.indexOf(":");
|
||||
if (index < 1) return;
|
||||
String key = s.substring(0, index);
|
||||
String value = s.substring(index+1);
|
||||
change_setting(key.c_str(), value.toInt());
|
||||
}
|
||||
|
||||
void handle_ws(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len) {
|
||||
if (type == WS_EVT_CONNECT) {
|
||||
LOGln("Websocket * Client connected. ID: %d", client->id());
|
||||
} else if (type == WS_EVT_DISCONNECT) {
|
||||
if (monitor_client == client->id()) monitor_client=0;
|
||||
LOGln("Websocket * Client disconnected.");
|
||||
} else if (type == WS_EVT_DATA) {
|
||||
AwsFrameInfo* info = (AwsFrameInfo*)arg;
|
||||
if (info->opcode == WS_TEXT) {
|
||||
data[len] = 0;
|
||||
String msg = String((char*)data);
|
||||
LOGln("Websocket * In: %s", msg.c_str());
|
||||
if (msg.startsWith("effect:")) {
|
||||
change_current_effect(msg.substring(7));
|
||||
} else if (msg.equals("effects?")) {
|
||||
ws_send_effects(client);
|
||||
} else if (msg.equals("settings?")) {
|
||||
ws_send_settings(client);
|
||||
} else if (msg.startsWith("setting:")) {
|
||||
ws_set_setting(msg.substring(8));
|
||||
} else if (msg.equals("monitor:1")) {
|
||||
monitor_client = client->id();
|
||||
} else if (msg.equals("monitor:0")) {
|
||||
if (monitor_client == client->id()) monitor_client=0;
|
||||
} else {
|
||||
client->text("Unknown command. Accepted commands:\neffects?\nsettings?\nsetting:<key>:<value>\neffect:<effect>\nmonitor:<0/1>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void http_server_setup() {
|
||||
PGM_P text_plain = PSTR("text/plain");
|
||||
http_server.on("/", HTTP_GET, [&](){
|
||||
static const char* PROGMEM text_plain = "text/plain";
|
||||
|
||||
http_server.on("/", HTTP_GET, [&](AsyncWebServerRequest* request){
|
||||
LOGln("HTTP * GET /");
|
||||
String message = "<html><head><title>Pitrix</title></head><body><h1>Pitrix</h1><p>Known animations:</p>";
|
||||
String response = String(F("<html><head><title>Pitrix</title></head><body><h1>Pitrix</h1><p><a href='/settings'>Settings</a></p><p><a href='/effects'>Effect</a></p><p>Known animations:</p>"));
|
||||
if (!SPIFFS.begin()) {
|
||||
message += "<strong>No SPIFFS file system found.</strong>";
|
||||
response += F("<strong>No SPIFFS file system found.</strong>");
|
||||
} else {
|
||||
message += "<ul>";
|
||||
response += F("<ul>");
|
||||
Dir dir = SPIFFS.openDir("/");
|
||||
while (dir.next()) {
|
||||
message += "<li>" + dir.fileName() + " (<a href='/delete?" + dir.fileName() + "'>delete</a>)</li>";
|
||||
char buffer[100];
|
||||
snprintf_P(buffer, 100, PSTR("<li>%s (<a href='/delete?%s'>delete</a>)</li>"), dir.fileName().c_str(), dir.fileName().c_str());
|
||||
response += buffer;
|
||||
}
|
||||
message += "</ul>";
|
||||
message += "<form action='/upload' method='POST'><input type='file' name='file' /><input type='submit' value='Upload file' /></form>";
|
||||
response += F("</ul>");
|
||||
response += F("<form action='/upload' method='POST'><input type='file' name='file' /><input type='submit' value='Upload file' /></form>");
|
||||
}
|
||||
message += "</body></html>";
|
||||
http_server.send(200, "text/html", message);
|
||||
response += F("</body></html>");
|
||||
request->send(200, "text/html", response);
|
||||
});
|
||||
http_server.on("/delete", HTTP_GET, [&]() {
|
||||
LOGln("HTTP * GET /delete");
|
||||
if (http_server.args()==0) {
|
||||
http_server.send_P(400, text_plain, PSTR("No filename given"));
|
||||
http_server.on("/settings", HTTP_GET, [&](AsyncWebServerRequest* request) {
|
||||
String message = F("<html><head><title>Pitrix settings</title></head><body><h1>Pitrix settings</h1><a href='/'>Back to main page</a><table>\n");
|
||||
for (int i=0; i<all_settings_size; i++) {
|
||||
Setting s = all_settings[i];
|
||||
uint16_t default_value = setting_default(&s);
|
||||
uint16_t value = *(s.value);
|
||||
|
||||
message += F("<tr><td>");
|
||||
if (default_value != value) {
|
||||
message += F("<strong>");
|
||||
}
|
||||
message += s.name;
|
||||
if (default_value != value) {
|
||||
message += F("<strong>");
|
||||
}
|
||||
message += F("</td><td>");
|
||||
message += value;
|
||||
if (default_value != value) {
|
||||
message += " (";
|
||||
message += default_value;
|
||||
message += ")";
|
||||
}
|
||||
char buffer[150];
|
||||
snprintf_P(buffer, 150, PSTR("</td><td><form method='POST' action='/settings?redir=1'><input type='hidden' name='key' value='%s'/>"), s.name);
|
||||
message += buffer;
|
||||
if (s.type==TYPE_UINT8 || s.type==TYPE_UINT16) {
|
||||
snprintf_P(buffer, 150, PSTR("<input type='number' name='value' value='%d' min='0' max='%d' />"), value, s.type==TYPE_UINT8 ? 255 : 65535);
|
||||
} else if (s.type==TYPE_BOOL) {
|
||||
snprintf_P(buffer, 150, PSTR("<input type='radio' name='value' value='0' %s> Off / <input type='radio' name='value' value='1' %s> On"), value==0?"checked":"", value==1?"checked":"");
|
||||
}
|
||||
message += buffer;
|
||||
message += F("<input type='submit' value='Save' /></form></td></tr>\n");
|
||||
}
|
||||
message += F("</table></body></html>");
|
||||
request->send(200, "text/html", message);
|
||||
});
|
||||
http_server.on("/settings", HTTP_POST, [&](AsyncWebServerRequest* request) {
|
||||
if (!request->hasParam("key", true) || !request->hasParam("value", true)) {
|
||||
request->send(400, "text/plain", "Missing argument.");
|
||||
return;
|
||||
}
|
||||
String file = http_server.arg(0);
|
||||
String name = request->getParam("key", true)->value();
|
||||
uint16_t value = request->getParam("value", true)->value().toInt();
|
||||
|
||||
if (change_setting(name.c_str(), value)) {
|
||||
if (request->hasParam("redir")) {
|
||||
request->redirect("/settings");
|
||||
} else {
|
||||
request->send(200, "text/plain", "OK");
|
||||
}
|
||||
save_settings();
|
||||
} else {
|
||||
request->send(400, "text/plain", "Could not change setting.");
|
||||
}
|
||||
});
|
||||
http_server.on("/settings/load", HTTP_POST, [&](AsyncWebServerRequest* request) {
|
||||
load_settings();
|
||||
request->send(200, "text/plain", "OK");
|
||||
});
|
||||
http_server.on("/settings/save", HTTP_POST, [&](AsyncWebServerRequest* request) {
|
||||
save_settings();
|
||||
request->send(200, "text/plain", "OK");
|
||||
});
|
||||
http_server.on("/settings.txt", HTTP_GET, [&](AsyncWebServerRequest* request) {
|
||||
File f;
|
||||
if (SPIFFS.begin()) {
|
||||
f=SPIFFS.open("/pitrix_settings.txt", "r");
|
||||
if (f) {
|
||||
String s = f.readString();
|
||||
f.close();
|
||||
request->send(200, "text/plain", s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
request->send(500, "text/plain", "Could not read settings.");
|
||||
});
|
||||
http_server.on("/effects", HTTP_GET, [&](AsyncWebServerRequest* request) {
|
||||
String message = F("<html><head><title>Pitrix effects</title></head><body><h1>Pitrix settings</h1><a href='/'>Back to main page</a><table>");
|
||||
char buffer[500];
|
||||
for (int i=0; i<effects_size; i++) {
|
||||
snprintf_P(buffer, 500, PSTR("<tr><td>%s</td><td><form method='post' action='/effects'><input type='hidden' name='name' value='%s'><input type='hidden' name='redir' value='1'><input type='submit' value='Select'></form></td></tr>"), effects[i].name, effects[i].name);
|
||||
message += buffer;
|
||||
}
|
||||
message += F("</table></body></html>");
|
||||
request->send(200, "text/html", message);
|
||||
});
|
||||
http_server.on("/effects", HTTP_POST, [&](AsyncWebServerRequest* request) {
|
||||
if (!request->hasParam("name", true)) {
|
||||
request->send(400, "text/plain", "Missing argument 'name'.");
|
||||
return;
|
||||
}
|
||||
String name = request->getParam("name", true)->value();
|
||||
if (change_current_effect(name)) {
|
||||
if (request->hasParam("redir")) {
|
||||
request->redirect("/effects");
|
||||
} else {
|
||||
request->send(200, "text/plain", "OK");
|
||||
}
|
||||
} else {
|
||||
request->send(404, "text/plain", "Effect not found.");
|
||||
}
|
||||
});
|
||||
http_server.on("/delete", HTTP_GET, [&](AsyncWebServerRequest* request) {
|
||||
LOGln("HTTP * GET /delete");
|
||||
if (request->params()==0) {
|
||||
request->send_P(400, text_plain, PSTR("No filename given"));
|
||||
return;
|
||||
}
|
||||
String file = request->getParam(0)->value();
|
||||
if (file == "/") {
|
||||
http_server.send_P(400, text_plain, PSTR("Invalid path"));
|
||||
request->send_P(400, text_plain, PSTR("Invalid path"));
|
||||
return;
|
||||
}
|
||||
if (!SPIFFS.exists(file)) {
|
||||
http_server.send_P(400, text_plain, PSTR("File does not exist."));
|
||||
request->send_P(400, text_plain, PSTR("File does not exist."));
|
||||
return;
|
||||
}
|
||||
SPIFFS.remove(file);
|
||||
http_server.send_P(200, text_plain, PSTR("OK"));
|
||||
request->send_P(200, text_plain, PSTR("OK"));
|
||||
});
|
||||
http_server.on("/upload", HTTP_POST, []() {
|
||||
LOGln("HTTP * POST /upload");
|
||||
http_server.send(200, "text/plain", "OK");
|
||||
http_server.on("/upload", HTTP_POST, [](AsyncWebServerRequest* request) {
|
||||
request->send(200);
|
||||
}, http_server_handle_file_upload);
|
||||
http_server.on("/free_heap", HTTP_GET, [&](){
|
||||
http_server.on("/free_heap", HTTP_GET, [&](AsyncWebServerRequest* request){
|
||||
LOGln("HTTP * GET /free_heap");
|
||||
http_server.send(200, "text/plain", String(ESP.getFreeHeap()));
|
||||
request->send(200, "text/plain", String(ESP.getFreeHeap()));
|
||||
});
|
||||
http_server.on("/uptime", HTTP_GET, [&](){
|
||||
http_server.on("/uptime", HTTP_GET, [&](AsyncWebServerRequest* request){
|
||||
LOGln("HTTP * GET /uptime");
|
||||
http_server.send(200, "text/plain", String(millis()/1000));
|
||||
request->send(200, "text/plain", String(millis()/1000));
|
||||
});
|
||||
http_server.on("/fps", HTTP_GET, [](){
|
||||
http_server.on("/fps", HTTP_GET, [](AsyncWebServerRequest* request){
|
||||
LOGln("HTTP * GET /fps");
|
||||
http_server.send(200, "text/plain", String(FastLED.getFPS()));
|
||||
request->send(200, "text/plain", String(FastLED.getFPS()));
|
||||
});
|
||||
http_server.on("/reboot", HTTP_POST, [](){
|
||||
http_server.on("/reboot", HTTP_POST, [](AsyncWebServerRequest* request){
|
||||
LOGln("HTTP * POST /reboot");
|
||||
ESP.restart();
|
||||
});
|
||||
http_server.on("/brightness", HTTP_POST, [&](){
|
||||
LOGln("HTTP * POST /brightness with value %s", http_server.arg("plain").c_str());
|
||||
if (!http_server.hasArg("plain")) {
|
||||
http_server.send_P(400, text_plain, PSTR("No brightness given"));
|
||||
http_server.on("/mode", HTTP_POST, [&](AsyncWebServerRequest* request){
|
||||
LOGln("HTTP * POST /mode with value %s", request->getParam("plain", true)->value().c_str());
|
||||
if (!request->hasParam("plain", true)) {
|
||||
request->send_P(400, text_plain, PSTR("No effect given."));
|
||||
return;
|
||||
}
|
||||
long val = http_server.arg("plain").toInt();
|
||||
if (val==0 || val>255) {
|
||||
http_server.send_P(400, text_plain, PSTR("New value out of bounds. (1-255)"));
|
||||
return;
|
||||
}
|
||||
FastLED.setBrightness(val);
|
||||
http_server.send(200, "text/plain", "OK");
|
||||
});
|
||||
http_server.on("/mode", HTTP_POST, [&](){
|
||||
LOGln("HTTP * POST /mode with value %s", http_server.arg("plain").c_str());
|
||||
if (!http_server.hasArg("plain")) {
|
||||
http_server.send_P(400, text_plain, PSTR("No effect given."));
|
||||
return;
|
||||
}
|
||||
String val = http_server.arg("plain");
|
||||
String val = request->getParam("plain", true)->value();
|
||||
if (change_current_effect(val)) {
|
||||
http_server.send(200, "text/plain", "OK");
|
||||
request->send(200, "text/plain", "OK");
|
||||
} else {
|
||||
http_server.send_P(400, text_plain, PSTR("Unknown effect."));
|
||||
request->send_P(400, text_plain, PSTR("Unknown effect."));
|
||||
}
|
||||
});
|
||||
http_server.on("/monitor", HTTP_GET, [&](AsyncWebServerRequest* request) {
|
||||
static const char* html PROGMEM = R"(
|
||||
<html>
|
||||
<head>
|
||||
<title>Pitrix</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
<button id='monitor_off'>Monitor OFF</button>
|
||||
<button id='monitor_on'>Monitor ON</button>
|
||||
</p>
|
||||
<canvas id='target' width='800' height='500'></canvas>
|
||||
<script type='text/javascript'>
|
||||
width = height = 32;
|
||||
active = false;
|
||||
ctx = document.getElementById('target').getContext('2d');
|
||||
socket = new WebSocket((document.location.protocol=='https:' ? 'wss' : 'ws') + '://' + document.location.host + '/ws');
|
||||
socket.onopen = function() {
|
||||
socket.send('effects?');
|
||||
socket.send('settings?');
|
||||
};
|
||||
socket.binaryType = 'arraybuffer';
|
||||
socket.onmessage = function(message) {
|
||||
if ((typeof message.data) == 'string') {
|
||||
var j = JSON.parse(message.data);
|
||||
if (j.effects) {
|
||||
console.log('Got effects.');
|
||||
console.log(j.effects);
|
||||
}
|
||||
if (j.settings) {
|
||||
console.log('Got settings.');
|
||||
console.log(j.settings);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!active) return;
|
||||
var buffer = new Uint8Array(message.data);
|
||||
width = buffer[0];
|
||||
height = buffer[1];
|
||||
if (buffer[2] != 255) return;
|
||||
var offset = 3;
|
||||
ctx.fillStyle = '#000000';
|
||||
ctx.fillRect(0, 0, 20*width, 20*height);
|
||||
for (var y=0; y<height; y++) for (var x=0; x<width; x++) {
|
||||
var r = buffer[offset + 0];
|
||||
var g = buffer[offset + 1];
|
||||
var b = buffer[offset + 2];
|
||||
offset = offset + 3;
|
||||
ctx.fillStyle = 'rgb('+r+','+g+','+b+')';
|
||||
ctx.fillRect(x*20+2, y*20+2, 16, 16);
|
||||
}
|
||||
};
|
||||
document.getElementById('monitor_on').onclick = function() {
|
||||
socket.send('monitor:1');
|
||||
active = true;
|
||||
};
|
||||
document.getElementById('monitor_off').onclick = function() {
|
||||
socket.send('monitor:0');
|
||||
active = false;
|
||||
ctx.fillStyle = '0x80808080';
|
||||
ctx.fillRect(0, 0, width*20, height*20);
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
)";
|
||||
|
||||
request->send_P(200, PSTR("text/html"), html);
|
||||
});
|
||||
|
||||
|
||||
ws.onEvent(handle_ws);
|
||||
http_server.addHandler(&ws);
|
||||
|
||||
|
||||
http_server.begin();
|
||||
|
||||
MDNS.addService("_http", "_tcp", 80);
|
||||
}
|
||||
|
||||
void http_server_loop() {
|
||||
http_server.handleClient();
|
||||
void http_server_send_framedata() {
|
||||
if (ws.count()>0 && monitor_client>0) {
|
||||
if (ws.hasClient(monitor_client)) {
|
||||
uint16_t _size = LED_WIDTH * LED_HEIGHT * 3 + 4;
|
||||
uint8_t* _buffer = new uint8_t[_size];
|
||||
_buffer[0] = LED_WIDTH;
|
||||
_buffer[1] = LED_HEIGHT;
|
||||
_buffer[2] = 255;
|
||||
for (uint8_t y=0; y<LED_HEIGHT; y++) for(uint8_t x=0; x<LED_WIDTH; x++) {
|
||||
uint16_t index = XYsafe(x, y);
|
||||
CRGB pixel = leds[index];
|
||||
_buffer[3 + (y*LED_WIDTH + x)*3 + 0] = (pixel.r==255 ? 254 : pixel.r);
|
||||
_buffer[3 + (y*LED_WIDTH + x)*3 + 1] = (pixel.g==255 ? 254 : pixel.g);
|
||||
_buffer[3 + (y*LED_WIDTH + x)*3 + 2] = (pixel.b==255 ? 254 : pixel.b);
|
||||
}
|
||||
_buffer[_size - 1] = 255;
|
||||
ws.binary(monitor_client, _buffer, _size);
|
||||
delete _buffer;
|
||||
} else {
|
||||
monitor_client = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
49
src/mqtt.cpp
49
src/mqtt.cpp
@ -23,7 +23,7 @@ void mqtt_callback(char* original_topic, byte* pl, unsigned int length) {
|
||||
pl[length] = '\0';
|
||||
String payload((char*)pl);
|
||||
String topic (original_topic);
|
||||
if (topic.equals(MQTT_TOPIC "log") || topic.equals(MQTT_TOPIC "status") || topic.equals(MQTT_TOPIC "metrics")) {
|
||||
if (topic.equals(MQTT_TOPIC "log") || topic.equals(MQTT_TOPIC "status") || topic.equals(MQTT_TOPIC "status_details") || topic.startsWith(MQTT_TOPIC "metrics")) {
|
||||
// Return our own messages
|
||||
return;
|
||||
}
|
||||
@ -31,7 +31,7 @@ void mqtt_callback(char* original_topic, byte* pl, unsigned int length) {
|
||||
if (topic.startsWith(MQTT_TOPIC_WEATHER)) {
|
||||
// Weather stuff
|
||||
topic.remove(0, strlen(MQTT_TOPIC_WEATHER));
|
||||
LOGln("MQTT * Weather stuff.");
|
||||
DBG("MQTT * Weather stuff.");
|
||||
if (topic.startsWith("icons/")) {
|
||||
topic.remove(0, 6);
|
||||
uint8_t id = topic.toInt();
|
||||
@ -39,7 +39,7 @@ void mqtt_callback(char* original_topic, byte* pl, unsigned int length) {
|
||||
uint8_t val = payload.toInt();
|
||||
if (val==0) return;
|
||||
weather_icon_ids[id] = val;
|
||||
LOGln("Set weather_icon_ids[%d] to value %d", id, val);
|
||||
DBG("Set weather_icon_ids[%d] to value %d", id, val);
|
||||
} else if (topic.startsWith("temperatures/")) {
|
||||
topic.remove(0, 13);
|
||||
uint8_t id = topic.toInt();
|
||||
@ -47,9 +47,13 @@ void mqtt_callback(char* original_topic, byte* pl, unsigned int length) {
|
||||
uint8_t val = payload.toInt();
|
||||
if (val==0) return;
|
||||
weather_temperatures[id] = val;
|
||||
LOGln("Set weather_temperatures[%d] to value %d", id, val);
|
||||
DBG("Set weather_temperatures[%d] to value %d", id, val);
|
||||
}
|
||||
return;
|
||||
} else if (topic.equals(MQTT_TOPIC_TIMER)) {
|
||||
timer = payload.toInt();
|
||||
LOGln("Set timer to %lu.", timer);
|
||||
return;
|
||||
}
|
||||
|
||||
topic.remove(0, strlen(MQTT_TOPIC)); // Strip MQTT_TOPIC from the beginning
|
||||
@ -71,10 +75,15 @@ void mqtt_callback(char* original_topic, byte* pl, unsigned int length) {
|
||||
tests::run();
|
||||
return;
|
||||
}
|
||||
|
||||
long value = payload.toInt();
|
||||
LOGln("MQTT * Payload as number: %d", value);
|
||||
|
||||
if (topic.compareTo("brightness")==0) {
|
||||
if (topic.startsWith("settings.")) {
|
||||
topic.remove(0, 9);
|
||||
change_setting(topic.c_str(), value);
|
||||
return;
|
||||
} else if (topic.compareTo("brightness")==0) {
|
||||
if (value > 0 && value <= 255) {
|
||||
LOGln("MQTT * Changing brightness...");
|
||||
FastLED.setBrightness(value);
|
||||
@ -89,13 +98,33 @@ void mqtt_callback(char* original_topic, byte* pl, unsigned int length) {
|
||||
|
||||
boolean mqtt_connect() {
|
||||
LOGln("MQTT * Connecting to MQTT server with client id %s", hostname);
|
||||
mqtt_client.setBufferSize(350);
|
||||
if (mqtt_client.connect(hostname, MQTT_USER, MQTT_PASS, MQTT_TOPIC "status", 0, true, "OFFLINE", true)) {
|
||||
LOGln("MQTT * Connected.");
|
||||
LOGln("Core * Flash chip id: 0x%X. Size: %d bytes. 'Real' size: %d bytes.", ESP.getFlashChipId(), ESP.getFlashChipSize(), ESP.getFlashChipRealSize());
|
||||
char buffer[40];
|
||||
snprintf(buffer, 40, "ONLINE %s %s", hostname, WiFi.localIP().toString().c_str());
|
||||
mqtt_client.publish(MQTT_TOPIC "status", buffer, true);
|
||||
mqtt_client.publish(MQTT_TOPIC "status", "ONLINE", true);
|
||||
mqtt_client.publish(MQTT_TOPIC "status_details", buffer, true);
|
||||
mqtt_client.subscribe(MQTT_TOPIC "+");
|
||||
mqtt_client.subscribe(MQTT_TOPIC_WEATHER "#");
|
||||
mqtt_client.subscribe(MQTT_TOPIC_TIMER);
|
||||
|
||||
#ifdef MQTT_TOPIC_HOMEASSISTANT
|
||||
// Set MQTT values for homeassistant auto device discovery
|
||||
String topic = MQTT_TOPIC_HOMEASSISTANT "/light/";
|
||||
topic += hostname;
|
||||
topic += "/config";
|
||||
String message = "{\"~\":\"" MQTT_TOPIC "\",\"opt\":1,\"avty_t\":\"~status\",\"pl_avail\":\"ONLINE\",\"pl_not_avail\":\"OFFLINE\",";
|
||||
message += "\"bri_cmd_t\": \"~brightness\",\"bri_scl\":255,\"fx_cmd_t\":\"~modus\",\"name\":\"Pitrix\",\"uniq_id\":\"";
|
||||
message += hostname;
|
||||
message += "\",";
|
||||
message += "\"stat_t\":\"~modus\",\"cmd_t\":\"~modus\",\"pl_on\":\"cycle\",\"pl_off\":\"night_clock\"}";
|
||||
mqtt_client.publish(topic.c_str(), message.c_str(), true);
|
||||
DBG("MQTT * Homeassistant data:");
|
||||
DBG("MQTT * Topic: %s", topic.c_str());
|
||||
DBG("MQTT * Data: %s", message.c_str());
|
||||
#endif
|
||||
}
|
||||
return mqtt_client.connected();
|
||||
}
|
||||
@ -122,16 +151,16 @@ void mqtt_loop() {
|
||||
|
||||
String mqtt_log_str = String();
|
||||
|
||||
void mqtt_publish(const char* topic, int number) {
|
||||
void mqtt_publish(const char* topic, int number, bool retain) {
|
||||
char b[32];
|
||||
sprintf(b, "%d", number);
|
||||
mqtt_publish(topic, b);
|
||||
mqtt_publish(topic, b, retain);
|
||||
}
|
||||
|
||||
void mqtt_publish(const char* topic, const char* message) {
|
||||
void mqtt_publish(const char* topic, const char* message, bool retain) {
|
||||
char t[127];
|
||||
sprintf(t, MQTT_TOPIC "%s", topic);
|
||||
mqtt_client.publish(t, message);
|
||||
mqtt_client.publish(t, message, retain);
|
||||
}
|
||||
|
||||
void mqtt_log(const char* message) {
|
||||
|
25
src/ntp.cpp
25
src/ntp.cpp
@ -1,13 +1,26 @@
|
||||
#include <ntp.h>
|
||||
#include <sntp.h>
|
||||
#include <coredecls.h>
|
||||
#include <time.h>
|
||||
#include <TZ.h>
|
||||
#include "my_fastled.h"
|
||||
|
||||
void updateCallback(NTPClient* c) {
|
||||
/*void updateCallback(NTPClient* c) {
|
||||
random16_add_entropy(c->getEpochMillis() & 0xFFFF);
|
||||
}
|
||||
LOGln("Received current time. Epoch is %lu.", ntpClient.getEpochTime());
|
||||
}*/
|
||||
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient ntpClient(ntpUDP, NTP_SERVER, NTP_OFFSET, NTP_INTERVAL);
|
||||
void time_changed() {
|
||||
random16_add_entropy(millis() & 0xFFFF);
|
||||
time_t now;
|
||||
tm timeinfo;
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
char time_s[30];
|
||||
strftime(time_s, 30, "%a %d.%m.%Y %T", &timeinfo);
|
||||
LOGln("NTP * Received time: %s", time_s);
|
||||
}
|
||||
|
||||
void ntp_setup() {
|
||||
ntpClient.setUpdateCallback(updateCallback);
|
||||
settimeofday_cb(time_changed);
|
||||
configTime(TZ_Europe_Berlin, "de.pool.ntp.org");
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <Arduino.h>
|
||||
#include <FS.h>
|
||||
|
||||
#include "ntp.h"
|
||||
#include "config.h"
|
||||
@ -9,13 +10,16 @@
|
||||
#include "functions.h"
|
||||
#include "effects.h"
|
||||
#include "http_server.h"
|
||||
#include "recorder.h"
|
||||
#include "settings.h"
|
||||
|
||||
uint8_t starting_up = OTA_STARTUP_DELAY;
|
||||
int loop_timeouts = 0;
|
||||
long loop_started_at = 0;
|
||||
uint8_t baseHue = 0; // defined as extern in prototypes.h
|
||||
char hostname[30]; // defined as extern in prototypes.h
|
||||
uint16_t frame = 0; // defined as extern in prototypes.h
|
||||
unsigned long _last_effect_loop_finished_at = 0;
|
||||
unsigned long timer = 0;
|
||||
#ifdef RECORDER_ENABLE
|
||||
Recorder* recorder;
|
||||
#endif
|
||||
@ -41,17 +45,23 @@ void setup() {
|
||||
ntp_setup();
|
||||
ota_setup();
|
||||
fastled_setup();
|
||||
ntpClient.begin();
|
||||
#ifdef HTTP_SERVER_ENABLE
|
||||
http_server_setup();
|
||||
#endif
|
||||
#ifdef MQTT_ENABLE
|
||||
mqtt_setup();
|
||||
#endif
|
||||
#ifdef RECORDER_ENABLE
|
||||
recorder = new Recorder();
|
||||
#endif
|
||||
SPIFFS.begin();
|
||||
if (!SPIFFS.begin()) {
|
||||
LOGln("Core * Could not open SPIFFS filesystem");
|
||||
} else {
|
||||
LOGln("Core * Files in SPIFFS filesystem:");
|
||||
Dir d = SPIFFS.openDir("/");
|
||||
while(d.next()) {
|
||||
LOGln("Core * %s", d.fileName().c_str());
|
||||
}
|
||||
LOGln("Core * End of SPIFFS file listing.");
|
||||
}
|
||||
load_settings();
|
||||
LOGln("Core * Setup complete");
|
||||
}
|
||||
|
||||
@ -63,7 +73,7 @@ void loop() {
|
||||
EVERY_N_SECONDS(1) {
|
||||
Serial.print("Core * Waiting for OTA... "); Serial.println(starting_up);
|
||||
starting_up--;
|
||||
Window* w = Window::getFullWindow();
|
||||
Window* w = &Window::window_full;
|
||||
CRGB color(0xFF0000);
|
||||
w->clear();
|
||||
for (int i=0; i<starting_up; i++) {
|
||||
@ -74,35 +84,49 @@ void loop() {
|
||||
return;
|
||||
}
|
||||
|
||||
ntpClient.update();
|
||||
#ifdef MQTT_ENABLE
|
||||
mqtt_loop();
|
||||
#endif
|
||||
#ifdef HTTP_SERVER_ENABLE
|
||||
http_server_loop();
|
||||
#endif
|
||||
|
||||
EVERY_N_MILLISECONDS(100) {
|
||||
baseHue++;
|
||||
}
|
||||
|
||||
EVERY_N_MILLISECONDS(1000 / FPS) {
|
||||
//LOGln("Core * loop running");
|
||||
current_effect->loop();
|
||||
//LOGln("Core * loop ran");
|
||||
frame++;
|
||||
// Calculate the delay since the last time loop() was called.
|
||||
// This way, the effect can handle varying frame rates.
|
||||
uint16_t last_loop_ago;
|
||||
unsigned long now = millis();
|
||||
if (now > _last_effect_loop_finished_at && _last_effect_loop_finished_at) {
|
||||
last_loop_ago = now - _last_effect_loop_finished_at;
|
||||
} else {
|
||||
last_loop_ago = 0;
|
||||
}
|
||||
|
||||
#ifdef MQTT_REPORT_METRICS
|
||||
unsigned long effect_loop_started = millis();
|
||||
#endif
|
||||
|
||||
current_effect->loop(last_loop_ago);
|
||||
|
||||
#ifdef MQTT_REPORT_METRICS
|
||||
metrics_frame_count++;
|
||||
metrics_frame_time += (millis() - effect_loop_started);
|
||||
#endif
|
||||
|
||||
// Save the time for the next run.
|
||||
_last_effect_loop_finished_at = now;
|
||||
|
||||
if (current_effect->can_be_shown_with_clock()) {
|
||||
effect_clock.loop_with_invert(current_effect->clock_as_mask());
|
||||
}
|
||||
FastLED.show();
|
||||
#ifdef MQTT_REPORT_METRICS
|
||||
metrics_frame_count++;
|
||||
metrics_frame_time += (millis() - loop_started_at);
|
||||
#endif
|
||||
|
||||
#ifdef RECORDER_ENABLE
|
||||
recorder->loop();
|
||||
#endif
|
||||
effect_timer.loop(last_loop_ago);
|
||||
|
||||
FastLED.show();
|
||||
|
||||
http_server_send_framedata();
|
||||
}
|
||||
|
||||
#if defined(MQTT_ENABLE) && defined(MQTT_REPORT_METRICS)
|
||||
|
@ -1,71 +0,0 @@
|
||||
#include "recorder.h"
|
||||
#include "my_fastled.h"
|
||||
#include "functions.h"
|
||||
#include "effects.h"
|
||||
#include "Window.h"
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
#ifdef RECORDER_ENABLE
|
||||
|
||||
Recorder::Recorder() {
|
||||
_buffer_len = LED_WIDTH * LED_HEIGHT * 3 + 3;
|
||||
_buffer = (char*)malloc(_buffer_len);
|
||||
_server = new AsyncServer(RECORDER_PORT);
|
||||
_server->onClient([&](void* a, AsyncClient* c) {
|
||||
LOGln("Recorder * New client: %s. Waiting for port number...", c->remoteIP().toString().c_str());
|
||||
if (_client) {
|
||||
LOGln("Recorder * Killing old client.");
|
||||
_client->close();
|
||||
_client_port = 0;
|
||||
delete _client;
|
||||
}
|
||||
_client = c;
|
||||
_msgid = 0;
|
||||
char dim[3] = {LED_WIDTH, LED_HEIGHT, 255};
|
||||
_client->write(dim, 3);
|
||||
_client->onDisconnect([&](void* a, AsyncClient* client) {
|
||||
LOGln("Recorder * Client disconnected");
|
||||
_client_port = 0;
|
||||
}, NULL);
|
||||
_client->onData([&](void* a, AsyncClient* client, void* data, size_t len) {
|
||||
if (*(char*)data == 'P') {
|
||||
LOGln("Found.");
|
||||
if (len >= 3) {
|
||||
uint8_t* d = (uint8_t*)data;
|
||||
_client_port = d[1]<<8 | d[2];
|
||||
LOGln("Recorder * Sending data to port %d", _client_port);
|
||||
}
|
||||
} else if (*(char*)data == 'E') {
|
||||
String effect = String(((char*)(data+1)));
|
||||
LOGln("Recorder * Setting effect %s", effect.c_str());
|
||||
Window::getFullWindow()->clear();
|
||||
change_current_effect(effect);
|
||||
}
|
||||
}, NULL);
|
||||
}, _server);
|
||||
_server->begin();
|
||||
LOGln("Recorder * Listening on port %d", RECORDER_PORT);
|
||||
}
|
||||
|
||||
void Recorder::loop() {
|
||||
if (_client && _client_port) {
|
||||
_skip_next_frame = !_skip_next_frame;
|
||||
if (_skip_next_frame == false) return;
|
||||
_buffer[0] = _msgid >> 8;
|
||||
_buffer[1] = _msgid & 0xFF;
|
||||
for (uint8_t y=0; y<LED_HEIGHT; y++) for(uint8_t x=0; x<LED_WIDTH; x++) {
|
||||
uint16_t index = XYsafe(x, y);
|
||||
CRGB pixel = leds[index];
|
||||
_buffer[2 + (y*LED_WIDTH + x)*3 + 0] = (pixel.r==255 ? 254 : pixel.r);
|
||||
_buffer[2 + (y*LED_WIDTH + x)*3 + 1] = (pixel.g==255 ? 254 : pixel.g);
|
||||
_buffer[2 + (y*LED_WIDTH + x)*3 + 2] = (pixel.b==255 ? 254 : pixel.b);
|
||||
}
|
||||
_buffer[_buffer_len - 1] = 255;
|
||||
_udp.beginPacket("10.10.2.1", 13330);
|
||||
_udp.write(_buffer, _buffer_len);
|
||||
_udp.endPacket();
|
||||
_msgid++;
|
||||
//_client->write(_buffer, _buffer_len);
|
||||
}
|
||||
}
|
||||
#endif
|
153
src/settings.cpp
Normal file
153
src/settings.cpp
Normal file
@ -0,0 +1,153 @@
|
||||
#include "settings.h"
|
||||
#include "config.h"
|
||||
#include <FS.h>
|
||||
|
||||
Settings settings;
|
||||
|
||||
Setting all_settings[] = {
|
||||
{"fps", &settings.fps, TYPE_UINT8},
|
||||
|
||||
{"effects.big_clock.spacing", &settings.effects.big_clock.spacing, TYPE_UINT8},
|
||||
|
||||
{"effects.confetti.pixels_per_loop", &settings.effects.confetti.pixels_per_loop, TYPE_UINT8},
|
||||
|
||||
{"effects.blur2d.count", &settings.effects.blur2d.count, TYPE_UINT8},
|
||||
|
||||
{"effects.cycle.random", &settings.effects.cycle.random, TYPE_BOOL},
|
||||
{"effects.cycle.time", &settings.effects.cycle.time, TYPE_UINT16},
|
||||
|
||||
{"effects.dvd.width", &settings.effects.dvd.width, TYPE_UINT8},
|
||||
{"effects.dvd.height", &settings.effects.dvd.height, TYPE_UINT8},
|
||||
{"effects.dvd.speed", &settings.effects.dvd.speed, TYPE_UINT8},
|
||||
|
||||
{"effects.dynamic.single_loop_time", &settings.effects.dynamic.single_loop_time, TYPE_UINT16},
|
||||
{"effects.dynamic.multi_loop_time", &settings.effects.dynamic.multi_loop_time, TYPE_UINT16},
|
||||
{"effects.dynamic.big_loop_time", &settings.effects.dynamic.big_loop_time, TYPE_UINT16},
|
||||
{"effects.dynamic.big_size", &settings.effects.dynamic.big_size, TYPE_UINT8},
|
||||
|
||||
{"effects.fire.cooldown", &settings.effects.fire.cooldown, TYPE_UINT8},
|
||||
{"effects.fire.spark_chance", &settings.effects.fire.spark_chance, TYPE_UINT8},
|
||||
|
||||
{"effects.firework.drag", &settings.effects.firework.drag, TYPE_UINT8},
|
||||
{"effects.firework.bounce", &settings.effects.firework.bounce, TYPE_UINT8},
|
||||
{"effects.firework.gravity", &settings.effects.firework.gravity, TYPE_UINT8},
|
||||
{"effects.firework.sparks", &settings.effects.firework.sparks, TYPE_UINT8},
|
||||
|
||||
{"effects.gol.start_percentage", &settings.effects.gol.start_percentage, TYPE_UINT8},
|
||||
{"effects.gol.blend_speed", &settings.effects.gol.blend_speed, TYPE_UINT8},
|
||||
{"effects.gol.restart_after_steps", &settings.effects.gol.restart_after_steps, TYPE_UINT8},
|
||||
|
||||
{"effects.lightspeed.count", &settings.effects.lightspeed.count, TYPE_UINT8},
|
||||
|
||||
{"effects.matrix.length_min", &settings.effects.matrix.length_min, TYPE_UINT8},
|
||||
{"effects.matrix.length_max", &settings.effects.matrix.length_max, TYPE_UINT8},
|
||||
{"effects.matrix.speed_min", &settings.effects.matrix.speed_min, TYPE_UINT8},
|
||||
{"effects.matrix.speed_max", &settings.effects.matrix.speed_max, TYPE_UINT8},
|
||||
{"effects.matrix.count", &settings.effects.matrix.count, TYPE_UINT8},
|
||||
{"effects.matrix.random_count", &settings.effects.matrix.random_count, TYPE_UINT8},
|
||||
|
||||
{"effects.sines.count", &settings.effects.sines.count, TYPE_UINT8},
|
||||
|
||||
{"effects.snake.direction_change", &settings.effects.snake.direction_change, TYPE_UINT8},
|
||||
|
||||
{"effects.tv_static.black_bar_speed", &settings.effects.tv_static.black_bar_speed, TYPE_UINT16},
|
||||
};
|
||||
|
||||
const uint8_t all_settings_size = 32;
|
||||
|
||||
bool change_setting(const char* key, uint16_t new_value) {
|
||||
LOGln("Settings * Setting %s to new value %d.", key, new_value);
|
||||
Setting* s = NULL;
|
||||
for (uint8_t i=0; i<all_settings_size; i++) {
|
||||
s = &(all_settings[i]);
|
||||
|
||||
if (strcmp(key, s->name)==0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (s==NULL) {
|
||||
LOGln("Settings * No setting matching the name %s found.", key);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check data size
|
||||
if (s->type == TYPE_BOOL && new_value > 1) {
|
||||
LOGln("Settings * Data type of %s is boolean, but new value is > 1.", key);
|
||||
return false;
|
||||
}
|
||||
if (s->type == TYPE_UINT8 && new_value>0xFF) {
|
||||
LOGln("Settings * Data type of %s is uint8_t, but new value is > 0xFF.", key);
|
||||
return false;
|
||||
}
|
||||
|
||||
*(s->value) = new_value;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t setting_default(Setting* s) {
|
||||
Settings defaults;
|
||||
auto p_settings = std::addressof(settings);
|
||||
auto p_defaults = std::addressof(defaults);
|
||||
uint16_t* p_this = s->value;
|
||||
uint16_t diff = p_this - (uint16_t*)p_settings;
|
||||
uint16_t default_value = *((uint16_t*)p_defaults + diff);
|
||||
return default_value;
|
||||
}
|
||||
|
||||
bool save_settings() {
|
||||
if (!SPIFFS.begin()) {
|
||||
LOGln("Settings * Could not open SPIFFS for saving.");
|
||||
return false;
|
||||
}
|
||||
|
||||
File f = SPIFFS.open("/pitrix_settings.txt", "w");
|
||||
if (!f) {
|
||||
LOGln("Settings * Could not open /pitrix_settings.txt for writing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Setting* s;
|
||||
for (uint8_t i=0; i<all_settings_size; i++) {
|
||||
s = &(all_settings[i]);
|
||||
uint16_t value = *(s->value);
|
||||
uint16_t default_value = setting_default(s);
|
||||
if (default_value != value) {
|
||||
char buf[50];
|
||||
snprintf(buf, 50, "%s=%d", s->name, value);
|
||||
LOGln("Saving: %s", buf);
|
||||
f.println(buf);
|
||||
}
|
||||
}
|
||||
|
||||
f.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool load_settings() {
|
||||
if (!SPIFFS.begin()) {
|
||||
LOGln("Settings * Could not open SPIFFS for loading.");
|
||||
return false;
|
||||
}
|
||||
|
||||
File f = SPIFFS.open("/pitrix_settings.txt", "r");
|
||||
if (!f) {
|
||||
LOGln("Settings * Could not open /pitrix_settings.txt for reading.");
|
||||
return false;
|
||||
}
|
||||
|
||||
String s = f.readString();
|
||||
f.close();
|
||||
|
||||
while (s.length() > 0) {
|
||||
int pos = s.lastIndexOf('\n');
|
||||
String part = s.substring(pos + 1);
|
||||
if (pos==-1) pos=0;
|
||||
s.remove(pos);
|
||||
pos = part.indexOf('=');
|
||||
if (pos < 1) continue;
|
||||
String key = part.substring(0, pos);
|
||||
uint16_t value = part.substring(pos + 1).toInt();
|
||||
change_setting(key.c_str(), value);
|
||||
}
|
||||
return true;
|
||||
}
|
@ -11,15 +11,22 @@ namespace tests {
|
||||
int i=0;
|
||||
Effect* effect;
|
||||
int32_t diffs[3] = {0, 0, 0};
|
||||
String effect_name;
|
||||
while (1) {
|
||||
for (int j=0; j<3; j++) {
|
||||
int free_at_start = ESP.getFreeHeap();
|
||||
effect = select_effect(i);
|
||||
if (effect == NULL) return;
|
||||
effect_name = effect->get_name();
|
||||
if (effect_name && !effect_name.equals("cycle")) {
|
||||
LOGln("Testing effect %s...", effect_name.c_str());
|
||||
delay(1);
|
||||
effect->loop(1);
|
||||
}
|
||||
delete effect;
|
||||
diffs[i] = ESP.getFreeHeap() - free_at_start;
|
||||
}
|
||||
LOGln("Tests * Memory leakage of effect #%d: %d, %d, %d", i, diffs[0], diffs[1], diffs[2]);
|
||||
LOGln("Tests * Memory leakage of effect %s: %d, %d, %d", effect_name.c_str(), diffs[0], diffs[1], diffs[2]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
IP="$1"
|
||||
EFFECTS=`egrep "case" ../effects.cpp | tr -s "\t" " " | cut -d" " -f 7 | sort`
|
||||
EFFECTS=`./list_effects.rb $IP | sort`
|
||||
|
||||
mkdir effects
|
||||
|
||||
|
26
src/tools/list_effects.rb
Executable file
26
src/tools/list_effects.rb
Executable file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'websocket-eventmachine-client'
|
||||
require 'json'
|
||||
|
||||
IP = ARGV[0] or raise "No IP given"
|
||||
uri = "ws://#{IP}:80/ws"
|
||||
|
||||
EM.run do
|
||||
ws = WebSocket::EventMachine::Client.connect(uri: uri)
|
||||
|
||||
ws.onopen do
|
||||
ws.send "effects?"
|
||||
end
|
||||
|
||||
ws.onmessage do |msg, type|
|
||||
if type==:text
|
||||
j = JSON.parse(msg)
|
||||
if j["effects"]
|
||||
j["effects"].each do |effect|
|
||||
puts effect
|
||||
end
|
||||
exit
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user