2016-12-17 23:43:07 +01:00
|
|
|
/*
|
|
|
|
WS2812FX.h - Library for WS2812 LED effects.
|
|
|
|
Harm Aldick - 2016
|
|
|
|
www.aldick.org
|
|
|
|
LICENSE
|
|
|
|
The MIT License (MIT)
|
2018-09-04 15:51:38 +02:00
|
|
|
Copyright (c) 2016 Harm Aldick
|
2016-12-17 23:43:07 +01:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
2019-02-09 16:37:20 +01:00
|
|
|
|
2018-09-04 15:51:38 +02:00
|
|
|
Modified for WLED
|
2016-12-17 23:43:07 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef WS2812FX_h
|
|
|
|
#define WS2812FX_h
|
|
|
|
|
2018-04-13 00:28:29 +02:00
|
|
|
#include "NpbWrapper.h"
|
2018-11-09 17:00:36 +01:00
|
|
|
|
|
|
|
#define FASTLED_INTERNAL //remove annoying pragma messages
|
2018-11-04 20:14:23 +01:00
|
|
|
#include "FastLED.h"
|
2016-12-17 23:43:07 +01:00
|
|
|
|
2018-11-16 19:59:00 +01:00
|
|
|
#define DEFAULT_BRIGHTNESS (uint8_t)127
|
2018-09-04 15:51:38 +02:00
|
|
|
#define DEFAULT_MODE (uint8_t)0
|
2018-11-16 19:59:00 +01:00
|
|
|
#define DEFAULT_SPEED (uint8_t)128
|
2019-03-05 10:59:15 +01:00
|
|
|
#define DEFAULT_COLOR (uint32_t)0xFFAA00
|
2018-09-04 15:51:38 +02:00
|
|
|
|
|
|
|
#define min(a,b) ((a)<(b)?(a):(b))
|
|
|
|
#define max(a,b) ((a)>(b)?(a):(b))
|
|
|
|
|
2019-10-03 16:33:37 +02:00
|
|
|
/* Not used in all effects yet */
|
2019-10-04 01:21:18 +02:00
|
|
|
#define WLED_FPS 42
|
2019-10-03 16:33:37 +02:00
|
|
|
#define FRAMETIME 1000/WLED_FPS
|
|
|
|
|
2019-03-05 10:59:15 +01:00
|
|
|
/* each segment uses 37 bytes of SRAM memory, so if you're application fails because of
|
2018-09-04 15:51:38 +02:00
|
|
|
insufficient memory, decreasing MAX_NUM_SEGMENTS may help */
|
2019-06-20 14:40:12 +02:00
|
|
|
#define MAX_NUM_SEGMENTS 10
|
2019-10-03 16:33:37 +02:00
|
|
|
|
2019-05-22 00:23:09 +02:00
|
|
|
#define NUM_COLORS 3 /* number of colors per segment */
|
2018-09-04 15:51:38 +02:00
|
|
|
#define SEGMENT _segments[_segment_index]
|
2019-05-22 00:23:09 +02:00
|
|
|
#define SEGCOLOR(x) gamma32(_segments[_segment_index].colors[x])
|
|
|
|
#define SEGENV _segment_runtimes[_segment_index]
|
|
|
|
#define SEGLEN SEGMENT.length()
|
2019-06-20 14:40:12 +02:00
|
|
|
#define SEGACT SEGMENT.stop
|
2019-05-22 00:23:09 +02:00
|
|
|
#define SPEED_FORMULA_L 5 + (50*(255 - SEGMENT.speed))/SEGLEN
|
2018-09-04 15:51:38 +02:00
|
|
|
#define RESET_RUNTIME memset(_segment_runtimes, 0, sizeof(_segment_runtimes))
|
2016-12-17 23:43:07 +01:00
|
|
|
|
2018-09-04 15:51:38 +02:00
|
|
|
// some common colors
|
|
|
|
#define RED (uint32_t)0xFF0000
|
|
|
|
#define GREEN (uint32_t)0x00FF00
|
|
|
|
#define BLUE (uint32_t)0x0000FF
|
|
|
|
#define WHITE (uint32_t)0xFFFFFF
|
|
|
|
#define BLACK (uint32_t)0x000000
|
|
|
|
#define YELLOW (uint32_t)0xFFFF00
|
|
|
|
#define CYAN (uint32_t)0x00FFFF
|
|
|
|
#define MAGENTA (uint32_t)0xFF00FF
|
|
|
|
#define PURPLE (uint32_t)0x400080
|
|
|
|
#define ORANGE (uint32_t)0xFF3000
|
|
|
|
#define PINK (uint32_t)0xFF1493
|
|
|
|
#define ULTRAWHITE (uint32_t)0xFFFFFFFF
|
2016-12-17 23:43:07 +01:00
|
|
|
|
2018-09-04 15:51:38 +02:00
|
|
|
// options
|
2019-03-05 10:59:15 +01:00
|
|
|
// bit 7: segment is in transition mode
|
|
|
|
// bits 2-6: TBD
|
|
|
|
// bit 1: reverse segment
|
|
|
|
// bit 0: segment is selected
|
2018-09-04 15:51:38 +02:00
|
|
|
#define NO_OPTIONS (uint8_t)0x00
|
2019-03-05 10:59:15 +01:00
|
|
|
#define TRANSITIONAL (uint8_t)0x80
|
|
|
|
#define REVERSE (uint8_t)0x02
|
|
|
|
#define SELECTED (uint8_t)0x01
|
|
|
|
#define IS_TRANSITIONAL ((SEGMENT.options & TRANSITIONAL) == TRANSITIONAL)
|
|
|
|
#define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE )
|
|
|
|
#define IS_SELECTED ((SEGMENT.options & SELECTED) == SELECTED )
|
2016-12-17 23:43:07 +01:00
|
|
|
|
2019-10-02 01:17:26 +02:00
|
|
|
#define MODE_COUNT 83
|
2016-12-17 23:43:07 +01:00
|
|
|
|
|
|
|
#define FX_MODE_STATIC 0
|
|
|
|
#define FX_MODE_BLINK 1
|
|
|
|
#define FX_MODE_BREATH 2
|
|
|
|
#define FX_MODE_COLOR_WIPE 3
|
|
|
|
#define FX_MODE_COLOR_WIPE_RANDOM 4
|
|
|
|
#define FX_MODE_RANDOM_COLOR 5
|
2018-09-04 15:51:38 +02:00
|
|
|
#define FX_MODE_COLOR_SWEEP 6
|
2018-04-01 00:08:50 +02:00
|
|
|
#define FX_MODE_DYNAMIC 7
|
2016-12-17 23:43:07 +01:00
|
|
|
#define FX_MODE_RAINBOW 8
|
|
|
|
#define FX_MODE_RAINBOW_CYCLE 9
|
|
|
|
#define FX_MODE_SCAN 10
|
|
|
|
#define FX_MODE_DUAL_SCAN 11
|
|
|
|
#define FX_MODE_FADE 12
|
|
|
|
#define FX_MODE_THEATER_CHASE 13
|
|
|
|
#define FX_MODE_THEATER_CHASE_RAINBOW 14
|
|
|
|
#define FX_MODE_RUNNING_LIGHTS 15
|
2019-02-05 21:53:39 +01:00
|
|
|
#define FX_MODE_SAW 16
|
|
|
|
#define FX_MODE_TWINKLE 17
|
2019-01-31 23:42:48 +01:00
|
|
|
#define FX_MODE_DISSOLVE 18
|
|
|
|
#define FX_MODE_DISSOLVE_RANDOM 19
|
2016-12-17 23:43:07 +01:00
|
|
|
#define FX_MODE_SPARKLE 20
|
|
|
|
#define FX_MODE_FLASH_SPARKLE 21
|
|
|
|
#define FX_MODE_HYPER_SPARKLE 22
|
|
|
|
#define FX_MODE_STROBE 23
|
|
|
|
#define FX_MODE_STROBE_RAINBOW 24
|
|
|
|
#define FX_MODE_MULTI_STROBE 25
|
|
|
|
#define FX_MODE_BLINK_RAINBOW 26
|
2018-03-18 23:16:53 +01:00
|
|
|
#define FX_MODE_ANDROID 27
|
2016-12-17 23:43:07 +01:00
|
|
|
#define FX_MODE_CHASE_COLOR 28
|
|
|
|
#define FX_MODE_CHASE_RANDOM 29
|
|
|
|
#define FX_MODE_CHASE_RAINBOW 30
|
|
|
|
#define FX_MODE_CHASE_FLASH 31
|
|
|
|
#define FX_MODE_CHASE_FLASH_RANDOM 32
|
|
|
|
#define FX_MODE_CHASE_RAINBOW_WHITE 33
|
2018-01-10 23:57:58 +01:00
|
|
|
#define FX_MODE_COLORFUL 34
|
2017-12-14 00:12:02 +01:00
|
|
|
#define FX_MODE_TRAFFIC_LIGHT 35
|
2016-12-17 23:43:07 +01:00
|
|
|
#define FX_MODE_COLOR_SWEEP_RANDOM 36
|
|
|
|
#define FX_MODE_RUNNING_COLOR 37
|
|
|
|
#define FX_MODE_RUNNING_RED_BLUE 38
|
|
|
|
#define FX_MODE_RUNNING_RANDOM 39
|
|
|
|
#define FX_MODE_LARSON_SCANNER 40
|
|
|
|
#define FX_MODE_COMET 41
|
|
|
|
#define FX_MODE_FIREWORKS 42
|
2019-02-11 23:49:04 +01:00
|
|
|
#define FX_MODE_RAIN 43
|
2016-12-17 23:43:07 +01:00
|
|
|
#define FX_MODE_MERRY_CHRISTMAS 44
|
|
|
|
#define FX_MODE_FIRE_FLICKER 45
|
2018-03-18 23:16:53 +01:00
|
|
|
#define FX_MODE_GRADIENT 46
|
|
|
|
#define FX_MODE_LOADING 47
|
2017-09-18 09:50:18 +02:00
|
|
|
#define FX_MODE_DUAL_COLOR_WIPE_IN_OUT 48
|
|
|
|
#define FX_MODE_DUAL_COLOR_WIPE_IN_IN 49
|
|
|
|
#define FX_MODE_DUAL_COLOR_WIPE_OUT_OUT 50
|
|
|
|
#define FX_MODE_DUAL_COLOR_WIPE_OUT_IN 51
|
|
|
|
#define FX_MODE_CIRCUS_COMBUSTUS 52
|
2018-09-04 15:51:38 +02:00
|
|
|
#define FX_MODE_HALLOWEEN 53
|
|
|
|
#define FX_MODE_TRICOLOR_CHASE 54
|
|
|
|
#define FX_MODE_TRICOLOR_WIPE 55
|
|
|
|
#define FX_MODE_TRICOLOR_FADE 56
|
|
|
|
#define FX_MODE_LIGHTNING 57
|
|
|
|
#define FX_MODE_ICU 58
|
|
|
|
#define FX_MODE_MULTI_COMET 59
|
|
|
|
#define FX_MODE_DUAL_LARSON_SCANNER 60
|
|
|
|
#define FX_MODE_RANDOM_CHASE 61
|
|
|
|
#define FX_MODE_OSCILLATE 62
|
2018-09-08 16:21:44 +02:00
|
|
|
//Modes that use FastLED -->
|
2018-09-11 00:20:12 +02:00
|
|
|
#define FX_MODE_PRIDE_2015 63
|
|
|
|
#define FX_MODE_JUGGLE 64
|
|
|
|
#define FX_MODE_PALETTE 65
|
|
|
|
#define FX_MODE_FIRE_2012 66
|
2018-09-08 16:21:44 +02:00
|
|
|
#define FX_MODE_COLORWAVES 67
|
|
|
|
#define FX_MODE_BPM 68
|
|
|
|
#define FX_MODE_FILLNOISE8 69
|
|
|
|
#define FX_MODE_NOISE16_1 70
|
|
|
|
#define FX_MODE_NOISE16_2 71
|
|
|
|
#define FX_MODE_NOISE16_3 72
|
|
|
|
#define FX_MODE_NOISE16_4 73
|
2018-11-04 20:14:23 +01:00
|
|
|
#define FX_MODE_COLORTWINKLE 74
|
2018-11-07 20:22:05 +01:00
|
|
|
#define FX_MODE_LAKE 75
|
2018-11-20 21:31:07 +01:00
|
|
|
#define FX_MODE_METEOR 76
|
2018-12-02 02:49:05 +01:00
|
|
|
#define FX_MODE_METEOR_SMOOTH 77
|
|
|
|
#define FX_MODE_RAILWAY 78
|
2019-01-31 23:42:48 +01:00
|
|
|
#define FX_MODE_RIPPLE 79
|
2019-08-30 15:39:34 +02:00
|
|
|
#define FX_MODE_TWINKLEFOX 80
|
2019-10-02 01:17:26 +02:00
|
|
|
#define FX_MODE_TWINKLECAT 81
|
|
|
|
#define FX_MODE_HALLOWEEN_EYES 82
|
2018-11-20 21:31:07 +01:00
|
|
|
|
2018-01-09 23:13:29 +01:00
|
|
|
|
2018-04-13 00:28:29 +02:00
|
|
|
class WS2812FX {
|
2018-09-04 15:51:38 +02:00
|
|
|
typedef uint16_t (WS2812FX::*mode_ptr)(void);
|
|
|
|
|
|
|
|
// segment parameters
|
2016-12-17 23:43:07 +01:00
|
|
|
public:
|
2018-09-06 02:05:56 +02:00
|
|
|
typedef struct Segment { // 21 bytes
|
2018-09-04 15:51:38 +02:00
|
|
|
uint16_t start;
|
2019-03-05 10:59:15 +01:00
|
|
|
uint16_t stop; //segment invalid if stop == 0
|
2018-11-16 19:59:00 +01:00
|
|
|
uint8_t speed;
|
2018-09-04 15:51:38 +02:00
|
|
|
uint8_t intensity;
|
2018-09-06 02:05:56 +02:00
|
|
|
uint8_t palette;
|
2019-03-01 17:10:42 +01:00
|
|
|
uint8_t mode;
|
2019-03-06 01:20:38 +01:00
|
|
|
uint8_t options; //bit pattern: msb first: transitional tbd tbd tbd tbd paused reverse selected
|
2018-09-04 15:51:38 +02:00
|
|
|
uint32_t colors[NUM_COLORS];
|
2019-03-06 01:20:38 +01:00
|
|
|
void setOption(uint8_t n, bool val)
|
|
|
|
{
|
|
|
|
if (val) {
|
|
|
|
options |= 0x01 << n;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
options &= ~(0x01 << n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool getOption(uint8_t n)
|
|
|
|
{
|
|
|
|
return ((options >> n) & 0x01);
|
|
|
|
}
|
2019-06-20 14:40:12 +02:00
|
|
|
bool isSelected()
|
|
|
|
{
|
|
|
|
return getOption(0);
|
|
|
|
}
|
|
|
|
bool isActive()
|
|
|
|
{
|
|
|
|
return stop > start;
|
|
|
|
}
|
|
|
|
uint16_t length()
|
2019-05-22 00:23:09 +02:00
|
|
|
{
|
|
|
|
return stop - start;
|
|
|
|
}
|
2018-09-04 15:51:38 +02:00
|
|
|
} segment;
|
|
|
|
|
|
|
|
// segment runtime parameters
|
2019-03-05 10:59:15 +01:00
|
|
|
typedef struct Segment_runtime { // 16 bytes
|
2018-09-04 15:51:38 +02:00
|
|
|
unsigned long next_time;
|
2019-05-22 00:23:09 +02:00
|
|
|
uint32_t step;
|
|
|
|
uint32_t call;
|
|
|
|
uint16_t aux0;
|
|
|
|
uint16_t aux1;
|
|
|
|
void reset(){next_time = 0; step = 0; call = 0; aux0 = 0; aux1 = 0;};
|
2018-09-04 15:51:38 +02:00
|
|
|
} segment_runtime;
|
2018-01-10 23:57:58 +01:00
|
|
|
|
2018-09-04 15:51:38 +02:00
|
|
|
WS2812FX() {
|
2019-08-30 15:39:34 +02:00
|
|
|
//assign each member of the _mode[] array to its respective function reference
|
2018-09-04 15:51:38 +02:00
|
|
|
_mode[FX_MODE_STATIC] = &WS2812FX::mode_static;
|
|
|
|
_mode[FX_MODE_BLINK] = &WS2812FX::mode_blink;
|
|
|
|
_mode[FX_MODE_COLOR_WIPE] = &WS2812FX::mode_color_wipe;
|
|
|
|
_mode[FX_MODE_COLOR_WIPE_RANDOM] = &WS2812FX::mode_color_wipe_random;
|
|
|
|
_mode[FX_MODE_RANDOM_COLOR] = &WS2812FX::mode_random_color;
|
|
|
|
_mode[FX_MODE_COLOR_SWEEP] = &WS2812FX::mode_color_sweep;
|
|
|
|
_mode[FX_MODE_DYNAMIC] = &WS2812FX::mode_dynamic;
|
|
|
|
_mode[FX_MODE_RAINBOW] = &WS2812FX::mode_rainbow;
|
|
|
|
_mode[FX_MODE_RAINBOW_CYCLE] = &WS2812FX::mode_rainbow_cycle;
|
|
|
|
_mode[FX_MODE_SCAN] = &WS2812FX::mode_scan;
|
|
|
|
_mode[FX_MODE_DUAL_SCAN] = &WS2812FX::mode_dual_scan;
|
|
|
|
_mode[FX_MODE_FADE] = &WS2812FX::mode_fade;
|
|
|
|
_mode[FX_MODE_THEATER_CHASE] = &WS2812FX::mode_theater_chase;
|
|
|
|
_mode[FX_MODE_THEATER_CHASE_RAINBOW] = &WS2812FX::mode_theater_chase_rainbow;
|
2019-02-05 21:53:39 +01:00
|
|
|
_mode[FX_MODE_SAW] = &WS2812FX::mode_saw;
|
2018-09-04 15:51:38 +02:00
|
|
|
_mode[FX_MODE_TWINKLE] = &WS2812FX::mode_twinkle;
|
2019-01-31 23:42:48 +01:00
|
|
|
_mode[FX_MODE_DISSOLVE] = &WS2812FX::mode_dissolve;
|
|
|
|
_mode[FX_MODE_DISSOLVE_RANDOM] = &WS2812FX::mode_dissolve_random;
|
2018-09-04 15:51:38 +02:00
|
|
|
_mode[FX_MODE_SPARKLE] = &WS2812FX::mode_sparkle;
|
|
|
|
_mode[FX_MODE_FLASH_SPARKLE] = &WS2812FX::mode_flash_sparkle;
|
|
|
|
_mode[FX_MODE_HYPER_SPARKLE] = &WS2812FX::mode_hyper_sparkle;
|
|
|
|
_mode[FX_MODE_STROBE] = &WS2812FX::mode_strobe;
|
|
|
|
_mode[FX_MODE_STROBE_RAINBOW] = &WS2812FX::mode_strobe_rainbow;
|
|
|
|
_mode[FX_MODE_MULTI_STROBE] = &WS2812FX::mode_multi_strobe;
|
|
|
|
_mode[FX_MODE_BLINK_RAINBOW] = &WS2812FX::mode_blink_rainbow;
|
|
|
|
_mode[FX_MODE_ANDROID] = &WS2812FX::mode_android;
|
|
|
|
_mode[FX_MODE_CHASE_COLOR] = &WS2812FX::mode_chase_color;
|
|
|
|
_mode[FX_MODE_CHASE_RANDOM] = &WS2812FX::mode_chase_random;
|
|
|
|
_mode[FX_MODE_CHASE_RAINBOW] = &WS2812FX::mode_chase_rainbow;
|
|
|
|
_mode[FX_MODE_CHASE_FLASH] = &WS2812FX::mode_chase_flash;
|
|
|
|
_mode[FX_MODE_CHASE_FLASH_RANDOM] = &WS2812FX::mode_chase_flash_random;
|
|
|
|
_mode[FX_MODE_CHASE_RAINBOW_WHITE] = &WS2812FX::mode_chase_rainbow_white;
|
|
|
|
_mode[FX_MODE_COLORFUL] = &WS2812FX::mode_colorful;
|
|
|
|
_mode[FX_MODE_TRAFFIC_LIGHT] = &WS2812FX::mode_traffic_light;
|
|
|
|
_mode[FX_MODE_COLOR_SWEEP_RANDOM] = &WS2812FX::mode_color_sweep_random;
|
|
|
|
_mode[FX_MODE_RUNNING_COLOR] = &WS2812FX::mode_running_color;
|
|
|
|
_mode[FX_MODE_RUNNING_RED_BLUE] = &WS2812FX::mode_running_red_blue;
|
|
|
|
_mode[FX_MODE_RUNNING_RANDOM] = &WS2812FX::mode_running_random;
|
|
|
|
_mode[FX_MODE_LARSON_SCANNER] = &WS2812FX::mode_larson_scanner;
|
|
|
|
_mode[FX_MODE_COMET] = &WS2812FX::mode_comet;
|
|
|
|
_mode[FX_MODE_FIREWORKS] = &WS2812FX::mode_fireworks;
|
2019-02-11 23:49:04 +01:00
|
|
|
_mode[FX_MODE_RAIN] = &WS2812FX::mode_rain;
|
2018-09-04 15:51:38 +02:00
|
|
|
_mode[FX_MODE_MERRY_CHRISTMAS] = &WS2812FX::mode_merry_christmas;
|
|
|
|
_mode[FX_MODE_FIRE_FLICKER] = &WS2812FX::mode_fire_flicker;
|
|
|
|
_mode[FX_MODE_GRADIENT] = &WS2812FX::mode_gradient;
|
|
|
|
_mode[FX_MODE_LOADING] = &WS2812FX::mode_loading;
|
2017-09-18 09:50:18 +02:00
|
|
|
_mode[FX_MODE_DUAL_COLOR_WIPE_IN_OUT] = &WS2812FX::mode_dual_color_wipe_in_out;
|
|
|
|
_mode[FX_MODE_DUAL_COLOR_WIPE_IN_IN] = &WS2812FX::mode_dual_color_wipe_in_in;
|
|
|
|
_mode[FX_MODE_DUAL_COLOR_WIPE_OUT_OUT] = &WS2812FX::mode_dual_color_wipe_out_out;
|
|
|
|
_mode[FX_MODE_DUAL_COLOR_WIPE_OUT_IN] = &WS2812FX::mode_dual_color_wipe_out_in;
|
|
|
|
_mode[FX_MODE_CIRCUS_COMBUSTUS] = &WS2812FX::mode_circus_combustus;
|
2018-09-04 15:51:38 +02:00
|
|
|
_mode[FX_MODE_HALLOWEEN] = &WS2812FX::mode_halloween;
|
|
|
|
_mode[FX_MODE_TRICOLOR_CHASE] = &WS2812FX::mode_tricolor_chase;
|
|
|
|
_mode[FX_MODE_TRICOLOR_WIPE] = &WS2812FX::mode_tricolor_wipe;
|
|
|
|
_mode[FX_MODE_TRICOLOR_FADE] = &WS2812FX::mode_tricolor_fade;
|
|
|
|
_mode[FX_MODE_BREATH] = &WS2812FX::mode_breath;
|
|
|
|
_mode[FX_MODE_RUNNING_LIGHTS] = &WS2812FX::mode_running_lights;
|
|
|
|
_mode[FX_MODE_LIGHTNING] = &WS2812FX::mode_lightning;
|
|
|
|
_mode[FX_MODE_ICU] = &WS2812FX::mode_icu;
|
|
|
|
_mode[FX_MODE_MULTI_COMET] = &WS2812FX::mode_multi_comet;
|
|
|
|
_mode[FX_MODE_DUAL_LARSON_SCANNER] = &WS2812FX::mode_dual_larson_scanner;
|
|
|
|
_mode[FX_MODE_RANDOM_CHASE] = &WS2812FX::mode_random_chase;
|
|
|
|
_mode[FX_MODE_OSCILLATE] = &WS2812FX::mode_oscillate;
|
|
|
|
_mode[FX_MODE_FIRE_2012] = &WS2812FX::mode_fire_2012;
|
2018-09-08 16:21:44 +02:00
|
|
|
_mode[FX_MODE_PRIDE_2015] = &WS2812FX::mode_pride_2015;
|
2018-09-04 15:51:38 +02:00
|
|
|
_mode[FX_MODE_BPM] = &WS2812FX::mode_bpm;
|
|
|
|
_mode[FX_MODE_JUGGLE] = &WS2812FX::mode_juggle;
|
|
|
|
_mode[FX_MODE_PALETTE] = &WS2812FX::mode_palette;
|
2018-09-08 16:21:44 +02:00
|
|
|
_mode[FX_MODE_COLORWAVES] = &WS2812FX::mode_colorwaves;
|
2018-09-04 15:51:38 +02:00
|
|
|
_mode[FX_MODE_FILLNOISE8] = &WS2812FX::mode_fillnoise8;
|
|
|
|
_mode[FX_MODE_NOISE16_1] = &WS2812FX::mode_noise16_1;
|
|
|
|
_mode[FX_MODE_NOISE16_2] = &WS2812FX::mode_noise16_2;
|
|
|
|
_mode[FX_MODE_NOISE16_3] = &WS2812FX::mode_noise16_3;
|
|
|
|
_mode[FX_MODE_NOISE16_4] = &WS2812FX::mode_noise16_4;
|
2018-11-04 20:14:23 +01:00
|
|
|
_mode[FX_MODE_COLORTWINKLE] = &WS2812FX::mode_colortwinkle;
|
2018-11-07 20:22:05 +01:00
|
|
|
_mode[FX_MODE_LAKE] = &WS2812FX::mode_lake;
|
2018-11-20 21:31:07 +01:00
|
|
|
_mode[FX_MODE_METEOR] = &WS2812FX::mode_meteor;
|
2018-12-02 02:49:05 +01:00
|
|
|
_mode[FX_MODE_METEOR_SMOOTH] = &WS2812FX::mode_meteor_smooth;
|
|
|
|
_mode[FX_MODE_RAILWAY] = &WS2812FX::mode_railway;
|
2019-01-31 23:42:48 +01:00
|
|
|
_mode[FX_MODE_RIPPLE] = &WS2812FX::mode_ripple;
|
2019-08-30 15:39:34 +02:00
|
|
|
_mode[FX_MODE_TWINKLEFOX] = &WS2812FX::mode_twinklefox;
|
2019-10-02 01:17:26 +02:00
|
|
|
_mode[FX_MODE_TWINKLECAT] = &WS2812FX::mode_twinklecat;
|
|
|
|
_mode[FX_MODE_HALLOWEEN_EYES] = &WS2812FX::mode_halloween_eyes;
|
2016-12-17 23:43:07 +01:00
|
|
|
|
|
|
|
_brightness = DEFAULT_BRIGHTNESS;
|
2019-02-09 16:37:20 +01:00
|
|
|
currentPalette = CRGBPalette16(CRGB::Black);
|
|
|
|
targetPalette = CloudColors_p;
|
2019-03-09 21:41:23 +01:00
|
|
|
ablMilliampsMax = 850;
|
2018-12-04 00:58:06 +01:00
|
|
|
currentMilliamps = 0;
|
2019-10-18 12:19:52 +02:00
|
|
|
timebase = 0;
|
2019-03-09 21:41:23 +01:00
|
|
|
_locked = nullptr;
|
2019-02-11 23:49:04 +01:00
|
|
|
_modeUsesLock = false;
|
2018-04-13 00:28:29 +02:00
|
|
|
bus = new NeoPixelWrapper();
|
2019-06-20 14:40:12 +02:00
|
|
|
resetSegments();
|
2016-12-17 23:43:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-05-22 00:23:09 +02:00
|
|
|
init(bool supportWhite, uint16_t countPixels, bool skipFirs),
|
2016-12-17 23:43:07 +01:00
|
|
|
service(void),
|
2019-02-11 23:49:04 +01:00
|
|
|
blur(uint8_t),
|
2018-09-04 15:51:38 +02:00
|
|
|
fade_out(uint8_t r),
|
|
|
|
setMode(uint8_t m),
|
2019-06-20 14:40:12 +02:00
|
|
|
setMode(uint8_t segid, uint8_t m),
|
2018-09-04 15:51:38 +02:00
|
|
|
setSpeed(uint8_t s),
|
|
|
|
setIntensity(uint8_t i),
|
2018-09-06 02:05:56 +02:00
|
|
|
setPalette(uint8_t p),
|
2019-06-20 14:40:12 +02:00
|
|
|
setColor(uint8_t slot, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0),
|
|
|
|
setColor(uint8_t slot, uint32_t c),
|
2018-09-04 15:51:38 +02:00
|
|
|
setBrightness(uint8_t b),
|
2017-12-14 00:12:02 +01:00
|
|
|
driverModeCronixie(bool b),
|
2018-03-14 13:16:28 +01:00
|
|
|
setCronixieDigits(byte* d),
|
2017-12-19 16:12:51 +01:00
|
|
|
setCronixieBacklight(bool b),
|
2018-09-04 15:51:38 +02:00
|
|
|
setIndividual(uint16_t i, uint32_t col),
|
|
|
|
setRange(uint16_t i, uint16_t i2, uint32_t col),
|
|
|
|
lock(uint16_t i),
|
|
|
|
lockRange(uint16_t i, uint16_t i2),
|
|
|
|
unlock(uint16_t i),
|
|
|
|
unlockRange(uint16_t i, uint16_t i2),
|
2016-12-31 17:36:07 +01:00
|
|
|
unlockAll(void),
|
2018-09-06 02:05:56 +02:00
|
|
|
setTransitionMode(bool t),
|
2017-02-04 22:17:28 +01:00
|
|
|
trigger(void),
|
2019-03-06 01:20:38 +01:00
|
|
|
setSegment(uint8_t n, uint16_t start, uint16_t stop),
|
2018-09-04 15:51:38 +02:00
|
|
|
resetSegments(),
|
|
|
|
setPixelColor(uint16_t n, uint32_t c),
|
|
|
|
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0),
|
|
|
|
show(void);
|
2016-12-17 23:43:07 +01:00
|
|
|
|
2018-11-24 11:52:23 +01:00
|
|
|
bool
|
2019-06-20 14:40:12 +02:00
|
|
|
reverseMode = false,
|
2019-05-22 00:23:09 +02:00
|
|
|
gammaCorrectBri = false,
|
|
|
|
gammaCorrectCol = true,
|
2018-11-24 11:52:23 +01:00
|
|
|
setEffectConfig(uint8_t m, uint8_t s, uint8_t i, uint8_t p);
|
|
|
|
|
2018-09-04 15:51:38 +02:00
|
|
|
uint8_t
|
2019-06-20 14:40:12 +02:00
|
|
|
returnedSegment = 0,
|
2019-05-22 00:23:09 +02:00
|
|
|
paletteFade = 0,
|
|
|
|
paletteBlend = 0,
|
|
|
|
colorOrder = 0,
|
2018-09-04 15:51:38 +02:00
|
|
|
getBrightness(void),
|
2016-12-17 23:43:07 +01:00
|
|
|
getMode(void),
|
|
|
|
getSpeed(void),
|
2019-02-22 22:53:33 +01:00
|
|
|
getModeCount(void),
|
|
|
|
getPaletteCount(void),
|
2019-03-06 01:20:38 +01:00
|
|
|
getMaxSegments(void),
|
2019-06-20 14:40:12 +02:00
|
|
|
getFirstSelectedSegment(void),
|
|
|
|
getReturnedSegmentId(void),
|
2019-05-22 00:23:09 +02:00
|
|
|
gamma8(uint8_t),
|
2018-09-04 15:51:38 +02:00
|
|
|
get_random_wheel_index(uint8_t);
|
2016-12-17 23:43:07 +01:00
|
|
|
|
2019-08-30 15:39:34 +02:00
|
|
|
uint16_t
|
|
|
|
ablMilliampsMax,
|
|
|
|
currentMilliamps;
|
|
|
|
|
2016-12-17 23:43:07 +01:00
|
|
|
uint32_t
|
2019-10-18 12:19:52 +02:00
|
|
|
timebase,
|
2018-09-04 15:51:38 +02:00
|
|
|
color_wheel(uint8_t),
|
2018-10-24 02:06:07 +02:00
|
|
|
color_from_palette(uint16_t, bool, bool, uint8_t, uint8_t pbri = 255),
|
2018-09-04 15:51:38 +02:00
|
|
|
color_blend(uint32_t,uint32_t,uint8_t),
|
2019-05-22 00:23:09 +02:00
|
|
|
gamma32(uint32_t),
|
2018-09-04 15:51:38 +02:00
|
|
|
getPixelColor(uint16_t),
|
2016-12-17 23:43:07 +01:00
|
|
|
getColor(void);
|
|
|
|
|
2019-03-06 01:20:38 +01:00
|
|
|
WS2812FX::Segment&
|
|
|
|
getSegment(uint8_t n);
|
2016-12-17 23:43:07 +01:00
|
|
|
|
2018-09-04 15:51:38 +02:00
|
|
|
WS2812FX::Segment_runtime
|
|
|
|
getSegmentRuntime(void);
|
|
|
|
|
|
|
|
WS2812FX::Segment*
|
|
|
|
getSegments(void);
|
|
|
|
|
|
|
|
// builtin modes
|
|
|
|
uint16_t
|
2016-12-17 23:43:07 +01:00
|
|
|
mode_static(void),
|
|
|
|
mode_blink(void),
|
2018-09-04 15:51:38 +02:00
|
|
|
mode_blink_rainbow(void),
|
|
|
|
mode_strobe(void),
|
|
|
|
mode_strobe_rainbow(void),
|
2016-12-17 23:43:07 +01:00
|
|
|
mode_color_wipe(void),
|
2018-09-04 15:51:38 +02:00
|
|
|
mode_color_sweep(void),
|
2016-12-17 23:43:07 +01:00
|
|
|
mode_color_wipe_random(void),
|
2018-09-04 15:51:38 +02:00
|
|
|
mode_color_sweep_random(void),
|
2016-12-17 23:43:07 +01:00
|
|
|
mode_random_color(void),
|
2018-04-01 00:08:50 +02:00
|
|
|
mode_dynamic(void),
|
2016-12-17 23:43:07 +01:00
|
|
|
mode_breath(void),
|
|
|
|
mode_fade(void),
|
|
|
|
mode_scan(void),
|
|
|
|
mode_dual_scan(void),
|
|
|
|
mode_theater_chase(void),
|
|
|
|
mode_theater_chase_rainbow(void),
|
|
|
|
mode_rainbow(void),
|
|
|
|
mode_rainbow_cycle(void),
|
|
|
|
mode_running_lights(void),
|
2019-02-05 21:53:39 +01:00
|
|
|
mode_saw(void),
|
2016-12-17 23:43:07 +01:00
|
|
|
mode_twinkle(void),
|
2019-01-31 23:42:48 +01:00
|
|
|
mode_dissolve(void),
|
|
|
|
mode_dissolve_random(void),
|
2016-12-17 23:43:07 +01:00
|
|
|
mode_sparkle(void),
|
|
|
|
mode_flash_sparkle(void),
|
|
|
|
mode_hyper_sparkle(void),
|
|
|
|
mode_multi_strobe(void),
|
2018-03-18 23:16:53 +01:00
|
|
|
mode_android(void),
|
2016-12-17 23:43:07 +01:00
|
|
|
mode_chase_color(void),
|
|
|
|
mode_chase_random(void),
|
|
|
|
mode_chase_rainbow(void),
|
|
|
|
mode_chase_flash(void),
|
|
|
|
mode_chase_flash_random(void),
|
|
|
|
mode_chase_rainbow_white(void),
|
2018-01-10 23:57:58 +01:00
|
|
|
mode_colorful(void),
|
2017-12-14 00:12:02 +01:00
|
|
|
mode_traffic_light(void),
|
2016-12-17 23:43:07 +01:00
|
|
|
mode_running_color(void),
|
|
|
|
mode_running_red_blue(void),
|
|
|
|
mode_running_random(void),
|
|
|
|
mode_larson_scanner(void),
|
|
|
|
mode_comet(void),
|
|
|
|
mode_fireworks(void),
|
2019-02-11 23:49:04 +01:00
|
|
|
mode_rain(void),
|
2016-12-17 23:43:07 +01:00
|
|
|
mode_merry_christmas(void),
|
2018-09-04 15:51:38 +02:00
|
|
|
mode_halloween(void),
|
2016-12-17 23:43:07 +01:00
|
|
|
mode_fire_flicker(void),
|
2018-03-18 23:16:53 +01:00
|
|
|
mode_gradient(void),
|
|
|
|
mode_loading(void),
|
2017-09-18 09:50:18 +02:00
|
|
|
mode_dual_color_wipe_in_out(void),
|
|
|
|
mode_dual_color_wipe_in_in(void),
|
|
|
|
mode_dual_color_wipe_out_out(void),
|
|
|
|
mode_dual_color_wipe_out_in(void),
|
2017-11-29 23:56:02 +01:00
|
|
|
mode_circus_combustus(void),
|
2018-09-04 15:51:38 +02:00
|
|
|
mode_bicolor_chase(void),
|
|
|
|
mode_tricolor_chase(void),
|
|
|
|
mode_tricolor_wipe(void),
|
|
|
|
mode_tricolor_fade(void),
|
2019-01-31 23:42:48 +01:00
|
|
|
mode_lightning(void),
|
2018-09-04 15:51:38 +02:00
|
|
|
mode_icu(void),
|
|
|
|
mode_multi_comet(void),
|
|
|
|
mode_dual_larson_scanner(void),
|
|
|
|
mode_random_chase(void),
|
|
|
|
mode_oscillate(void),
|
|
|
|
mode_fire_2012(void),
|
2018-09-08 16:21:44 +02:00
|
|
|
mode_pride_2015(void),
|
2018-09-04 15:51:38 +02:00
|
|
|
mode_bpm(void),
|
|
|
|
mode_juggle(void),
|
|
|
|
mode_palette(void),
|
2018-09-08 16:21:44 +02:00
|
|
|
mode_colorwaves(void),
|
2018-09-04 15:51:38 +02:00
|
|
|
mode_fillnoise8(void),
|
|
|
|
mode_noise16_1(void),
|
|
|
|
mode_noise16_2(void),
|
|
|
|
mode_noise16_3(void),
|
|
|
|
mode_noise16_4(void),
|
2018-11-04 20:14:23 +01:00
|
|
|
mode_colortwinkle(void),
|
2018-11-07 20:22:05 +01:00
|
|
|
mode_lake(void),
|
2018-11-20 21:31:07 +01:00
|
|
|
mode_meteor(void),
|
2018-12-02 02:49:05 +01:00
|
|
|
mode_meteor_smooth(void),
|
|
|
|
mode_railway(void),
|
2019-08-30 15:39:34 +02:00
|
|
|
mode_ripple(void),
|
2019-10-02 01:17:26 +02:00
|
|
|
mode_twinklefox(void),
|
|
|
|
mode_twinklecat(void),
|
|
|
|
mode_halloween_eyes(void);
|
2018-09-04 15:51:38 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
NeoPixelWrapper *bus;
|
2018-11-04 20:14:23 +01:00
|
|
|
|
2019-08-30 15:39:34 +02:00
|
|
|
uint32_t crgb_to_col(CRGB fastled);
|
|
|
|
CRGB col_to_crgb(uint32_t);
|
2019-02-09 16:37:20 +01:00
|
|
|
CRGBPalette16 currentPalette;
|
|
|
|
CRGBPalette16 targetPalette;
|
2019-10-02 01:17:26 +02:00
|
|
|
|
|
|
|
uint32_t now;
|
2018-09-04 15:51:38 +02:00
|
|
|
uint16_t _length;
|
|
|
|
uint16_t _rand16seed;
|
|
|
|
uint8_t _brightness;
|
|
|
|
|
2018-09-06 02:05:56 +02:00
|
|
|
void handle_palette(void);
|
2019-02-02 15:31:43 +01:00
|
|
|
void fill(uint32_t);
|
2018-11-04 20:14:23 +01:00
|
|
|
bool modeUsesLock(uint8_t);
|
2019-10-02 01:17:26 +02:00
|
|
|
void twinklefox_base(bool);
|
2018-09-06 02:05:56 +02:00
|
|
|
|
2019-02-11 23:49:04 +01:00
|
|
|
bool
|
|
|
|
_modeUsesLock,
|
2018-04-13 00:28:29 +02:00
|
|
|
_rgbwMode,
|
2017-12-14 00:12:02 +01:00
|
|
|
_cronixieMode,
|
2017-12-19 16:12:51 +01:00
|
|
|
_cronixieBacklightEnabled,
|
2018-09-04 15:51:38 +02:00
|
|
|
_skipFirstMode,
|
|
|
|
_triggered;
|
2016-12-17 23:43:07 +01:00
|
|
|
|
2018-09-04 15:51:38 +02:00
|
|
|
byte* _locked;
|
2019-03-09 21:41:23 +01:00
|
|
|
byte _cronixieDigits[6];
|
2017-12-14 00:12:02 +01:00
|
|
|
|
2018-09-04 15:51:38 +02:00
|
|
|
mode_ptr _mode[MODE_COUNT]; // SRAM footprint: 4 bytes per element
|
2016-12-17 23:43:07 +01:00
|
|
|
|
2019-08-30 15:39:34 +02:00
|
|
|
// mode helper functions
|
|
|
|
uint16_t
|
|
|
|
blink(uint32_t, uint32_t, bool strobe, bool),
|
2019-10-03 20:57:22 +02:00
|
|
|
color_wipe(bool, bool),
|
2019-08-30 15:39:34 +02:00
|
|
|
scan(bool),
|
|
|
|
theater_chase(uint32_t, uint32_t, bool),
|
|
|
|
running_base(bool),
|
|
|
|
dissolve(uint32_t),
|
|
|
|
chase(uint32_t, uint32_t, uint32_t, bool),
|
|
|
|
gradient_base(bool),
|
|
|
|
running(uint32_t, uint32_t),
|
|
|
|
tricolor_chase(uint32_t, uint32_t);
|
|
|
|
|
2019-10-02 01:17:26 +02:00
|
|
|
CRGB twinklefox_one_twinkle(uint32_t ms, uint8_t salt, bool cat);
|
2018-09-06 02:05:56 +02:00
|
|
|
|
|
|
|
uint32_t _lastPaletteChange = 0;
|
2019-03-05 10:59:15 +01:00
|
|
|
uint32_t _lastShow = 0;
|
2018-09-06 02:05:56 +02:00
|
|
|
|
2018-09-04 15:51:38 +02:00
|
|
|
uint8_t _segment_index = 0;
|
2018-09-06 02:05:56 +02:00
|
|
|
uint8_t _segment_index_palette_last = 99;
|
2018-11-16 19:59:00 +01:00
|
|
|
segment _segments[MAX_NUM_SEGMENTS] = { // SRAM footprint: 21 bytes per element
|
2018-11-14 00:05:06 +01:00
|
|
|
// start, stop, speed, intensity, palette, mode, options, color[]
|
2019-03-06 01:20:38 +01:00
|
|
|
{ 0, 7, DEFAULT_SPEED, 128, 0, DEFAULT_MODE, NO_OPTIONS, {DEFAULT_COLOR}}
|
2018-09-04 15:51:38 +02:00
|
|
|
};
|
2019-03-05 10:59:15 +01:00
|
|
|
segment_runtime _segment_runtimes[MAX_NUM_SEGMENTS]; // SRAM footprint: 16 bytes per element
|
2016-12-17 23:43:07 +01:00
|
|
|
};
|
|
|
|
|
2019-02-10 23:05:06 +01:00
|
|
|
|
2019-03-06 01:20:38 +01:00
|
|
|
//10 names per line
|
|
|
|
const char JSON_mode_names[] PROGMEM = R"=====([
|
|
|
|
"Solid","Blink","Breathe","Wipe","Wipe Random","Random Colors","Sweep","Dynamic","Colorloop","Rainbow",
|
|
|
|
"Scan","Dual Scan","Fade","Chase","Chase Rainbow","Running","Saw","Twinkle","Dissolve","Dissolve Rnd",
|
|
|
|
"Sparkle","Dark Sparkle","Sparkle+","Strobe","Strobe Rainbow","Mega Strobe","Blink Rainbow","Android","Chase","Chase Random",
|
|
|
|
"Chase Rainbow","Chase Flash","Chase Flash Rnd","Rainbow Runner","Colorful","Traffic Light","Sweep Random","Running 2","Red & Blue","Stream",
|
|
|
|
"Scanner","Lighthouse","Fireworks","Rain","Merry Christmas","Fire Flicker","Gradient","Loading","In Out","In In",
|
|
|
|
"Out Out","Out In","Circus","Halloween","Tri Chase","Tri Wipe","Tri Fade","Lightning","ICU","Multi Comet",
|
2019-10-02 01:17:26 +02:00
|
|
|
"Dual Scanner","Stream 2","Oscillate","Pride 2015","Juggle","Palette","Fire 2012","Colorwaves","BPM","Fill Noise",
|
|
|
|
"Noise 1","Noise 2","Noise 3","Noise 4","Colortwinkles","Lake","Meteor","Smooth Meteor","Railway","Ripple",
|
|
|
|
"Twinklefox","Twinklecat","Halloween Eyes"
|
2019-03-06 01:20:38 +01:00
|
|
|
])=====";
|
|
|
|
|
|
|
|
|
|
|
|
const char JSON_palette_names[] PROGMEM = R"=====([
|
|
|
|
"Default","Random Cycle","Primary Color","Based on Primary","Set Colors","Based on Set","Party","Cloud","Lava","Ocean",
|
|
|
|
"Forest","Rainbow","Rainbow Bands","Sunset","Rivendell","Breeze","Red & Blue","Yellowout","Analogous","Splash",
|
|
|
|
"Pastel","Sunset 2","Beech","Vintage","Departure","Landscape","Beach","Sherbet","Hult","Hult 64",
|
|
|
|
"Drywet","Jul","Grintage","Rewhi","Tertiary","Fire","Icefire","Cyane","Light Pink","Autumn",
|
2019-08-31 01:41:25 +02:00
|
|
|
"Magenta","Magred","Yelmag","Yelblu","Orange & Teal","Tiamat","April Night","Orangery","C9","Sakura"
|
2019-03-06 01:20:38 +01:00
|
|
|
])=====";
|
2019-02-10 23:05:06 +01:00
|
|
|
|
2016-12-17 23:43:07 +01:00
|
|
|
#endif
|