mirror of
https://github.com/wled/WLED.git
synced 2025-07-21 09:46:32 +00:00
Bugfix & code reduction
- correctly clear segment spacing change - renamed Segment::setUp() to Segment::setGeometry() - removed WS2812FX::setSegment() - removed obsolete/unfunctional word clock usermod .cpp file
This commit is contained in:
parent
210191b251
commit
ef1e24cec2
@ -31,14 +31,14 @@ public:
|
|||||||
//strip.getSegment(1).setOption(SEG_OPTION_SELECTED, true);
|
//strip.getSegment(1).setOption(SEG_OPTION_SELECTED, true);
|
||||||
|
|
||||||
//select first two segments (background color + FX settable)
|
//select first two segments (background color + FX settable)
|
||||||
WS2812FX::Segment &seg = strip.getSegment(0);
|
Segment &seg = strip.getSegment(0);
|
||||||
seg.colors[0] = ((0 << 24) | ((0 & 0xFF) << 16) | ((0 & 0xFF) << 8) | ((0 & 0xFF)));
|
seg.colors[0] = ((0 << 24) | ((0 & 0xFF) << 16) | ((0 & 0xFF) << 8) | ((0 & 0xFF)));
|
||||||
strip.getSegment(0).setOption(0, false);
|
strip.getSegment(0).setOption(0, false);
|
||||||
strip.getSegment(0).setOption(2, false);
|
strip.getSegment(0).setOption(2, false);
|
||||||
//other segments are text
|
//other segments are text
|
||||||
for (int i = 1; i < 10; i++)
|
for (int i = 1; i < 10; i++)
|
||||||
{
|
{
|
||||||
WS2812FX::Segment &seg = strip.getSegment(i);
|
Segment &seg = strip.getSegment(i);
|
||||||
seg.colors[0] = ((0 << 24) | ((0 & 0xFF) << 16) | ((190 & 0xFF) << 8) | ((180 & 0xFF)));
|
seg.colors[0] = ((0 << 24) | ((0 & 0xFF) << 16) | ((190 & 0xFF) << 8) | ((180 & 0xFF)));
|
||||||
strip.getSegment(i).setOption(0, true);
|
strip.getSegment(i).setOption(0, true);
|
||||||
strip.setBrightness(64);
|
strip.setBrightness(64);
|
||||||
@ -80,61 +80,61 @@ public:
|
|||||||
void displayTime(byte hour, byte minute)
|
void displayTime(byte hour, byte minute)
|
||||||
{
|
{
|
||||||
bool isToHour = false; //true if minute > 30
|
bool isToHour = false; //true if minute > 30
|
||||||
strip.setSegment(0, 0, 64); // background
|
strip.getSegment(0).setGeometry(0, 64); // background
|
||||||
strip.setSegment(1, 0, 2); //It is
|
strip.getSegment(1).setGeometry(0, 2); //It is
|
||||||
|
|
||||||
strip.setSegment(2, 0, 0);
|
strip.getSegment(2).setGeometry(0, 0);
|
||||||
strip.setSegment(3, 0, 0); //disable minutes
|
strip.getSegment(3).setGeometry(0, 0); //disable minutes
|
||||||
strip.setSegment(4, 0, 0); //past
|
strip.getSegment(4).setGeometry(0, 0); //past
|
||||||
strip.setSegment(6, 0, 0); //to
|
strip.getSegment(6).setGeometry(0, 0); //to
|
||||||
strip.setSegment(8, 0, 0); //disable o'clock
|
strip.getSegment(8).setGeometry(0, 0); //disable o'clock
|
||||||
|
|
||||||
if (hour < 24) //valid time, display
|
if (hour < 24) //valid time, display
|
||||||
{
|
{
|
||||||
if (minute == 30)
|
if (minute == 30)
|
||||||
{
|
{
|
||||||
strip.setSegment(2, 3, 6); //half
|
strip.getSegment(2).setGeometry(3, 6); //half
|
||||||
strip.setSegment(3, 0, 0); //minutes
|
strip.getSegment(3).setGeometry(0, 0); //minutes
|
||||||
}
|
}
|
||||||
else if (minute == 15 || minute == 45)
|
else if (minute == 15 || minute == 45)
|
||||||
{
|
{
|
||||||
strip.setSegment(3, 0, 0); //minutes
|
strip.getSegment(3).setGeometry(0, 0); //minutes
|
||||||
}
|
}
|
||||||
else if (minute == 10)
|
else if (minute == 10)
|
||||||
{
|
{
|
||||||
//strip.setSegment(5, 6, 8); //ten
|
//strip.getSegment(5).setGeometry(6, 8); //ten
|
||||||
}
|
}
|
||||||
else if (minute == 5)
|
else if (minute == 5)
|
||||||
{
|
{
|
||||||
//strip.setSegment(5, 16, 18); //five
|
//strip.getSegment(5).setGeometry(16, 18); //five
|
||||||
}
|
}
|
||||||
else if (minute == 0)
|
else if (minute == 0)
|
||||||
{
|
{
|
||||||
strip.setSegment(3, 0, 0); //minutes
|
strip.getSegment(3).setGeometry(0, 0); //minutes
|
||||||
//hourChime();
|
//hourChime();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strip.setSegment(3, 18, 22); //minutes
|
strip.getSegment(3).setGeometry(18, 22); //minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
//past or to?
|
//past or to?
|
||||||
if (minute == 0)
|
if (minute == 0)
|
||||||
{ //full hour
|
{ //full hour
|
||||||
strip.setSegment(3, 0, 0); //disable minutes
|
strip.getSegment(3).setGeometry(0, 0); //disable minutes
|
||||||
strip.setSegment(4, 0, 0); //disable past
|
strip.getSegment(4).setGeometry(0, 0); //disable past
|
||||||
strip.setSegment(6, 0, 0); //disable to
|
strip.getSegment(6).setGeometry(0, 0); //disable to
|
||||||
strip.setSegment(8, 60, 64); //o'clock
|
strip.getSegment(8).setGeometry(60, 64); //o'clock
|
||||||
}
|
}
|
||||||
else if (minute > 34)
|
else if (minute > 34)
|
||||||
{
|
{
|
||||||
//strip.setSegment(6, 22, 24); //to
|
//strip.getSegment(6).setGeometry(22, 24); //to
|
||||||
//minute = 60 - minute;
|
//minute = 60 - minute;
|
||||||
isToHour = true;
|
isToHour = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//strip.setSegment(4, 24, 27); //past
|
//strip.getSegment(4).setGeometry(24, 27); //past
|
||||||
//isToHour = false;
|
//isToHour = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,68 +143,68 @@ public:
|
|||||||
|
|
||||||
if (minute <= 4)
|
if (minute <= 4)
|
||||||
{
|
{
|
||||||
strip.setSegment(3, 0, 0); //nothing
|
strip.getSegment(3).setGeometry(0, 0); //nothing
|
||||||
strip.setSegment(5, 0, 0); //nothing
|
strip.getSegment(5).setGeometry(0, 0); //nothing
|
||||||
strip.setSegment(6, 0, 0); //nothing
|
strip.getSegment(6).setGeometry(0, 0); //nothing
|
||||||
strip.setSegment(8, 60, 64); //o'clock
|
strip.getSegment(8).setGeometry(60, 64); //o'clock
|
||||||
}
|
}
|
||||||
else if (minute <= 9)
|
else if (minute <= 9)
|
||||||
{
|
{
|
||||||
strip.setSegment(5, 16, 18); // five past
|
strip.getSegment(5).setGeometry(16, 18); // five past
|
||||||
strip.setSegment(4, 24, 27); //past
|
strip.getSegment(4).setGeometry(24, 27); //past
|
||||||
}
|
}
|
||||||
else if (minute <= 14)
|
else if (minute <= 14)
|
||||||
{
|
{
|
||||||
strip.setSegment(5, 6, 8); // ten past
|
strip.getSegment(5).setGeometry(6, 8); // ten past
|
||||||
strip.setSegment(4, 24, 27); //past
|
strip.getSegment(4).setGeometry(24, 27); //past
|
||||||
}
|
}
|
||||||
else if (minute <= 19)
|
else if (minute <= 19)
|
||||||
{
|
{
|
||||||
strip.setSegment(5, 8, 12); // quarter past
|
strip.getSegment(5).setGeometry(8, 12); // quarter past
|
||||||
strip.setSegment(3, 0, 0); //minutes
|
strip.getSegment(3).setGeometry(0, 0); //minutes
|
||||||
strip.setSegment(4, 24, 27); //past
|
strip.getSegment(4).setGeometry(24, 27); //past
|
||||||
}
|
}
|
||||||
else if (minute <= 24)
|
else if (minute <= 24)
|
||||||
{
|
{
|
||||||
strip.setSegment(5, 12, 16); // twenty past
|
strip.getSegment(5).setGeometry(12, 16); // twenty past
|
||||||
strip.setSegment(4, 24, 27); //past
|
strip.getSegment(4).setGeometry(24, 27); //past
|
||||||
}
|
}
|
||||||
else if (minute <= 29)
|
else if (minute <= 29)
|
||||||
{
|
{
|
||||||
strip.setSegment(5, 12, 18); // twenty-five past
|
strip.getSegment(5).setGeometry(12, 18); // twenty-five past
|
||||||
strip.setSegment(4, 24, 27); //past
|
strip.getSegment(4).setGeometry(24, 27); //past
|
||||||
}
|
}
|
||||||
else if (minute <= 34)
|
else if (minute <= 34)
|
||||||
{
|
{
|
||||||
strip.setSegment(5, 3, 6); // half past
|
strip.getSegment(5).setGeometry(3, 6); // half past
|
||||||
strip.setSegment(3, 0, 0); //minutes
|
strip.getSegment(3).setGeometry(0, 0); //minutes
|
||||||
strip.setSegment(4, 24, 27); //past
|
strip.getSegment(4).setGeometry(24, 27); //past
|
||||||
}
|
}
|
||||||
else if (minute <= 39)
|
else if (minute <= 39)
|
||||||
{
|
{
|
||||||
strip.setSegment(5, 12, 18); // twenty-five to
|
strip.getSegment(5).setGeometry(12, 18); // twenty-five to
|
||||||
strip.setSegment(6, 22, 24); //to
|
strip.getSegment(6).setGeometry(22, 24); //to
|
||||||
}
|
}
|
||||||
else if (minute <= 44)
|
else if (minute <= 44)
|
||||||
{
|
{
|
||||||
strip.setSegment(5, 12, 16); // twenty to
|
strip.getSegment(5).setGeometry(12, 16); // twenty to
|
||||||
strip.setSegment(6, 22, 24); //to
|
strip.getSegment(6).setGeometry(22, 24); //to
|
||||||
}
|
}
|
||||||
else if (minute <= 49)
|
else if (minute <= 49)
|
||||||
{
|
{
|
||||||
strip.setSegment(5, 8, 12); // quarter to
|
strip.getSegment(5).setGeometry(8, 12); // quarter to
|
||||||
strip.setSegment(3, 0, 0); //minutes
|
strip.getSegment(3).setGeometry(0, 0); //minutes
|
||||||
strip.setSegment(6, 22, 24); //to
|
strip.getSegment(6).setGeometry(22, 24); //to
|
||||||
}
|
}
|
||||||
else if (minute <= 54)
|
else if (minute <= 54)
|
||||||
{
|
{
|
||||||
strip.setSegment(5, 6, 8); // ten to
|
strip.getSegment(5).setGeometry(6, 8); // ten to
|
||||||
strip.setSegment(6, 22, 24); //to
|
strip.getSegment(6).setGeometry(22, 24); //to
|
||||||
}
|
}
|
||||||
else if (minute <= 59)
|
else if (minute <= 59)
|
||||||
{
|
{
|
||||||
strip.setSegment(5, 16, 18); // five to
|
strip.getSegment(5).setGeometry(16, 18); // five to
|
||||||
strip.setSegment(6, 22, 24); //to
|
strip.getSegment(6).setGeometry(22, 24); //to
|
||||||
}
|
}
|
||||||
|
|
||||||
//hours
|
//hours
|
||||||
@ -220,45 +220,45 @@ public:
|
|||||||
switch (hour)
|
switch (hour)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
strip.setSegment(7, 27, 29);
|
strip.getSegment(7).setGeometry(27, 29);
|
||||||
break; //one
|
break; //one
|
||||||
case 2:
|
case 2:
|
||||||
strip.setSegment(7, 35, 37);
|
strip.getSegment(7).setGeometry(35, 37);
|
||||||
break; //two
|
break; //two
|
||||||
case 3:
|
case 3:
|
||||||
strip.setSegment(7, 29, 32);
|
strip.getSegment(7).setGeometry(29, 32);
|
||||||
break; //three
|
break; //three
|
||||||
case 4:
|
case 4:
|
||||||
strip.setSegment(7, 32, 35);
|
strip.getSegment(7).setGeometry(32, 35);
|
||||||
break; //four
|
break; //four
|
||||||
case 5:
|
case 5:
|
||||||
strip.setSegment(7, 37, 40);
|
strip.getSegment(7).setGeometry(37, 40);
|
||||||
break; //five
|
break; //five
|
||||||
case 6:
|
case 6:
|
||||||
strip.setSegment(7, 43, 45);
|
strip.getSegment(7).setGeometry(43, 45);
|
||||||
break; //six
|
break; //six
|
||||||
case 7:
|
case 7:
|
||||||
strip.setSegment(7, 40, 43);
|
strip.getSegment(7).setGeometry(40, 43);
|
||||||
break; //seven
|
break; //seven
|
||||||
case 8:
|
case 8:
|
||||||
strip.setSegment(7, 45, 48);
|
strip.getSegment(7).setGeometry(45, 48);
|
||||||
break; //eight
|
break; //eight
|
||||||
case 9:
|
case 9:
|
||||||
strip.setSegment(7, 48, 50);
|
strip.getSegment(7).setGeometry(48, 50);
|
||||||
break; //nine
|
break; //nine
|
||||||
case 10:
|
case 10:
|
||||||
strip.setSegment(7, 54, 56);
|
strip.getSegment(7).setGeometry(54, 56);
|
||||||
break; //ten
|
break; //ten
|
||||||
case 11:
|
case 11:
|
||||||
strip.setSegment(7, 50, 54);
|
strip.getSegment(7).setGeometry(50, 54);
|
||||||
break; //eleven
|
break; //eleven
|
||||||
case 12:
|
case 12:
|
||||||
strip.setSegment(7, 56, 60);
|
strip.getSegment(7).setGeometry(56, 60);
|
||||||
break; //twelve
|
break; //twelve
|
||||||
}
|
}
|
||||||
|
|
||||||
selectWordSegments(true);
|
selectWordSegments(true);
|
||||||
applyMacro(1);
|
applyPreset(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void timeOfDay()
|
void timeOfDay()
|
||||||
|
@ -1,305 +0,0 @@
|
|||||||
#include "wled.h"
|
|
||||||
/*
|
|
||||||
* This v1 usermod file allows you to add own functionality to WLED more easily
|
|
||||||
* See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality
|
|
||||||
* EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in const.h)
|
|
||||||
* If you just need 8 bytes, use 2551-2559 (you do not need to increase EEPSIZE)
|
|
||||||
*
|
|
||||||
* Consider the v2 usermod API if you need a more advanced feature set!
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t minuteLast = 99;
|
|
||||||
int dayBrightness = 128;
|
|
||||||
int nightBrightness = 16;
|
|
||||||
|
|
||||||
//Use userVar0 and userVar1 (API calls &U0=,&U1=, uint16_t)
|
|
||||||
|
|
||||||
//gets called once at boot. Do all initialization that doesn't depend on network here
|
|
||||||
void userSetup()
|
|
||||||
{
|
|
||||||
saveMacro(14, "A=128", false);
|
|
||||||
saveMacro(15, "A=64", false);
|
|
||||||
saveMacro(16, "A=16", false);
|
|
||||||
|
|
||||||
saveMacro(1, "&FX=0&R=255&G=255&B=255", false);
|
|
||||||
|
|
||||||
//strip.getSegment(1).setOption(SEG_OPTION_SELECTED, true);
|
|
||||||
|
|
||||||
//select first two segments (background color + FX settable)
|
|
||||||
Segment &seg = strip.getSegment(0);
|
|
||||||
seg.colors[0] = ((0 << 24) | ((0 & 0xFF) << 16) | ((0 & 0xFF) << 8) | ((0 & 0xFF)));
|
|
||||||
strip.getSegment(0).setOption(0, false);
|
|
||||||
strip.getSegment(0).setOption(2, false);
|
|
||||||
//other segments are text
|
|
||||||
for (int i = 1; i < 10; i++)
|
|
||||||
{
|
|
||||||
Segment &seg = strip.getSegment(i);
|
|
||||||
seg.colors[0] = ((0 << 24) | ((0 & 0xFF) << 16) | ((190 & 0xFF) << 8) | ((180 & 0xFF)));
|
|
||||||
strip.getSegment(i).setOption(0, true);
|
|
||||||
strip.setBrightness(128);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//gets called every time WiFi is (re-)connected. Initialize own network interfaces here
|
|
||||||
void userConnected()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void selectWordSegments(bool state)
|
|
||||||
{
|
|
||||||
for (int i = 1; i < 10; i++)
|
|
||||||
{
|
|
||||||
//Segment &seg = strip.getSegment(i);
|
|
||||||
strip.getSegment(i).setOption(0, state);
|
|
||||||
// strip.getSegment(1).setOption(SEG_OPTION_SELECTED, true);
|
|
||||||
//seg.mode = 12;
|
|
||||||
//seg.palette = 1;
|
|
||||||
//strip.setBrightness(255);
|
|
||||||
}
|
|
||||||
strip.getSegment(0).setOption(0, !state);
|
|
||||||
}
|
|
||||||
|
|
||||||
void hourChime()
|
|
||||||
{
|
|
||||||
//strip.resetSegments();
|
|
||||||
selectWordSegments(true);
|
|
||||||
colorUpdated(CALL_MODE_FX_CHANGED);
|
|
||||||
//savePreset(255);
|
|
||||||
selectWordSegments(false);
|
|
||||||
//strip.getSegment(0).setOption(0, true);
|
|
||||||
strip.getSegment(0).setOption(2, true);
|
|
||||||
applyPreset(12);
|
|
||||||
colorUpdated(CALL_MODE_FX_CHANGED);
|
|
||||||
}
|
|
||||||
|
|
||||||
void displayTime(byte hour, byte minute)
|
|
||||||
{
|
|
||||||
bool isToHour = false; //true if minute > 30
|
|
||||||
strip.setSegment(0, 0, 64); // background
|
|
||||||
strip.setSegment(1, 0, 2); //It is
|
|
||||||
|
|
||||||
strip.setSegment(2, 0, 0);
|
|
||||||
strip.setSegment(3, 0, 0); //disable minutes
|
|
||||||
strip.setSegment(4, 0, 0); //past
|
|
||||||
strip.setSegment(6, 0, 0); //to
|
|
||||||
strip.setSegment(8, 0, 0); //disable o'clock
|
|
||||||
|
|
||||||
if (hour < 24) //valid time, display
|
|
||||||
{
|
|
||||||
if (minute == 30)
|
|
||||||
{
|
|
||||||
strip.setSegment(2, 3, 6); //half
|
|
||||||
strip.setSegment(3, 0, 0); //minutes
|
|
||||||
}
|
|
||||||
else if (minute == 15 || minute == 45)
|
|
||||||
{
|
|
||||||
strip.setSegment(3, 0, 0); //minutes
|
|
||||||
}
|
|
||||||
else if (minute == 10)
|
|
||||||
{
|
|
||||||
//strip.setSegment(5, 6, 8); //ten
|
|
||||||
}
|
|
||||||
else if (minute == 5)
|
|
||||||
{
|
|
||||||
//strip.setSegment(5, 16, 18); //five
|
|
||||||
}
|
|
||||||
else if (minute == 0)
|
|
||||||
{
|
|
||||||
strip.setSegment(3, 0, 0); //minutes
|
|
||||||
//hourChime();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
strip.setSegment(3, 18, 22); //minutes
|
|
||||||
}
|
|
||||||
|
|
||||||
//past or to?
|
|
||||||
if (minute == 0)
|
|
||||||
{ //full hour
|
|
||||||
strip.setSegment(3, 0, 0); //disable minutes
|
|
||||||
strip.setSegment(4, 0, 0); //disable past
|
|
||||||
strip.setSegment(6, 0, 0); //disable to
|
|
||||||
strip.setSegment(8, 60, 64); //o'clock
|
|
||||||
}
|
|
||||||
else if (minute > 34)
|
|
||||||
{
|
|
||||||
//strip.setSegment(6, 22, 24); //to
|
|
||||||
//minute = 60 - minute;
|
|
||||||
isToHour = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//strip.setSegment(4, 24, 27); //past
|
|
||||||
//isToHour = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ //temperature display
|
|
||||||
}
|
|
||||||
|
|
||||||
//byte minuteRem = minute %10;
|
|
||||||
|
|
||||||
if (minute <= 4)
|
|
||||||
{
|
|
||||||
strip.setSegment(3, 0, 0); //nothing
|
|
||||||
strip.setSegment(5, 0, 0); //nothing
|
|
||||||
strip.setSegment(6, 0, 0); //nothing
|
|
||||||
strip.setSegment(8, 60, 64); //o'clock
|
|
||||||
}
|
|
||||||
else if (minute <= 9)
|
|
||||||
{
|
|
||||||
strip.setSegment(5, 16, 18); // five past
|
|
||||||
strip.setSegment(4, 24, 27); //past
|
|
||||||
}
|
|
||||||
else if (minute <= 14)
|
|
||||||
{
|
|
||||||
strip.setSegment(5, 6, 8); // ten past
|
|
||||||
strip.setSegment(4, 24, 27); //past
|
|
||||||
}
|
|
||||||
else if (minute <= 19)
|
|
||||||
{
|
|
||||||
strip.setSegment(5, 8, 12); // quarter past
|
|
||||||
strip.setSegment(3, 0, 0); //minutes
|
|
||||||
strip.setSegment(4, 24, 27); //past
|
|
||||||
}
|
|
||||||
else if (minute <= 24)
|
|
||||||
{
|
|
||||||
strip.setSegment(5, 12, 16); // twenty past
|
|
||||||
strip.setSegment(4, 24, 27); //past
|
|
||||||
}
|
|
||||||
else if (minute <= 29)
|
|
||||||
{
|
|
||||||
strip.setSegment(5, 12, 18); // twenty-five past
|
|
||||||
strip.setSegment(4, 24, 27); //past
|
|
||||||
}
|
|
||||||
else if (minute <= 34)
|
|
||||||
{
|
|
||||||
strip.setSegment(5, 3, 6); // half past
|
|
||||||
strip.setSegment(3, 0, 0); //minutes
|
|
||||||
strip.setSegment(4, 24, 27); //past
|
|
||||||
}
|
|
||||||
else if (minute <= 39)
|
|
||||||
{
|
|
||||||
strip.setSegment(5, 12, 18); // twenty-five to
|
|
||||||
strip.setSegment(6, 22, 24); //to
|
|
||||||
}
|
|
||||||
else if (minute <= 44)
|
|
||||||
{
|
|
||||||
strip.setSegment(5, 12, 16); // twenty to
|
|
||||||
strip.setSegment(6, 22, 24); //to
|
|
||||||
}
|
|
||||||
else if (minute <= 49)
|
|
||||||
{
|
|
||||||
strip.setSegment(5, 8, 12); // quarter to
|
|
||||||
strip.setSegment(3, 0, 0); //minutes
|
|
||||||
strip.setSegment(6, 22, 24); //to
|
|
||||||
}
|
|
||||||
else if (minute <= 54)
|
|
||||||
{
|
|
||||||
strip.setSegment(5, 6, 8); // ten to
|
|
||||||
strip.setSegment(6, 22, 24); //to
|
|
||||||
}
|
|
||||||
else if (minute <= 59)
|
|
||||||
{
|
|
||||||
strip.setSegment(5, 16, 18); // five to
|
|
||||||
strip.setSegment(6, 22, 24); //to
|
|
||||||
}
|
|
||||||
|
|
||||||
//hours
|
|
||||||
if (hour > 23)
|
|
||||||
return;
|
|
||||||
if (isToHour)
|
|
||||||
hour++;
|
|
||||||
if (hour > 12)
|
|
||||||
hour -= 12;
|
|
||||||
if (hour == 0)
|
|
||||||
hour = 12;
|
|
||||||
|
|
||||||
switch (hour)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
strip.setSegment(7, 27, 29);
|
|
||||||
break; //one
|
|
||||||
case 2:
|
|
||||||
strip.setSegment(7, 35, 37);
|
|
||||||
break; //two
|
|
||||||
case 3:
|
|
||||||
strip.setSegment(7, 29, 32);
|
|
||||||
break; //three
|
|
||||||
case 4:
|
|
||||||
strip.setSegment(7, 32, 35);
|
|
||||||
break; //four
|
|
||||||
case 5:
|
|
||||||
strip.setSegment(7, 37, 40);
|
|
||||||
break; //five
|
|
||||||
case 6:
|
|
||||||
strip.setSegment(7, 43, 45);
|
|
||||||
break; //six
|
|
||||||
case 7:
|
|
||||||
strip.setSegment(7, 40, 43);
|
|
||||||
break; //seven
|
|
||||||
case 8:
|
|
||||||
strip.setSegment(7, 45, 48);
|
|
||||||
break; //eight
|
|
||||||
case 9:
|
|
||||||
strip.setSegment(7, 48, 50);
|
|
||||||
break; //nine
|
|
||||||
case 10:
|
|
||||||
strip.setSegment(7, 54, 56);
|
|
||||||
break; //ten
|
|
||||||
case 11:
|
|
||||||
strip.setSegment(7, 50, 54);
|
|
||||||
break; //eleven
|
|
||||||
case 12:
|
|
||||||
strip.setSegment(7, 56, 60);
|
|
||||||
break; //twelve
|
|
||||||
}
|
|
||||||
|
|
||||||
selectWordSegments(true);
|
|
||||||
applyMacro(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void timeOfDay() {
|
|
||||||
// NOT USED: use timed macros instead
|
|
||||||
//Used to set brightness dependant of time of day - lights dimmed at night
|
|
||||||
|
|
||||||
//monday to thursday and sunday
|
|
||||||
|
|
||||||
if ((weekday(localTime) == 6) | (weekday(localTime) == 7)) {
|
|
||||||
if (hour(localTime) > 0 | hour(localTime) < 8) {
|
|
||||||
strip.setBrightness(nightBrightness);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
strip.setBrightness(dayBrightness);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (hour(localTime) < 6 | hour(localTime) >= 22) {
|
|
||||||
strip.setBrightness(nightBrightness);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
strip.setBrightness(dayBrightness);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//loop. You can use "if (WLED_CONNECTED)" to check for successful connection
|
|
||||||
void userLoop()
|
|
||||||
{
|
|
||||||
if (minute(localTime) != minuteLast)
|
|
||||||
{
|
|
||||||
updateLocalTime();
|
|
||||||
//timeOfDay();
|
|
||||||
minuteLast = minute(localTime);
|
|
||||||
displayTime(hour(localTime), minute(localTime));
|
|
||||||
if (minute(localTime) == 0){
|
|
||||||
hourChime();
|
|
||||||
}
|
|
||||||
if (minute(localTime) == 1){
|
|
||||||
//turn off background segment;
|
|
||||||
strip.getSegment(0).setOption(2, false);
|
|
||||||
//applyPreset(255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -539,6 +539,7 @@ typedef struct Segment {
|
|||||||
inline uint16_t length() const { return width() * height(); } // segment length (count) in physical pixels
|
inline uint16_t length() const { return width() * height(); } // segment length (count) in physical pixels
|
||||||
inline uint16_t groupLength() const { return grouping + spacing; }
|
inline uint16_t groupLength() const { return grouping + spacing; }
|
||||||
inline uint8_t getLightCapabilities() const { return _capabilities; }
|
inline uint8_t getLightCapabilities() const { return _capabilities; }
|
||||||
|
inline void deactivate() { setGeometry(0,0); }
|
||||||
|
|
||||||
inline static unsigned getUsedSegmentData() { return Segment::_usedSegmentData; }
|
inline static unsigned getUsedSegmentData() { return Segment::_usedSegmentData; }
|
||||||
inline static void addUsedSegmentData(int len) { Segment::_usedSegmentData += len; }
|
inline static void addUsedSegmentData(int len) { Segment::_usedSegmentData += len; }
|
||||||
@ -554,14 +555,14 @@ typedef struct Segment {
|
|||||||
static void handleRandomPalette();
|
static void handleRandomPalette();
|
||||||
|
|
||||||
void beginDraw(); // set up parameters for current effect
|
void beginDraw(); // set up parameters for current effect
|
||||||
void setUp(uint16_t i1, uint16_t i2, uint8_t grp=1, uint8_t spc=0, uint16_t ofs=UINT16_MAX, uint16_t i1Y=0, uint16_t i2Y=1);
|
void setGeometry(uint16_t i1, uint16_t i2, uint8_t grp=1, uint8_t spc=0, uint16_t ofs=UINT16_MAX, uint16_t i1Y=0, uint16_t i2Y=1, uint8_t m12=0);
|
||||||
bool setColor(uint8_t slot, uint32_t c); //returns true if changed
|
bool setColor(uint8_t slot, uint32_t c); //returns true if changed
|
||||||
void setCCT(uint16_t k);
|
void setCCT(uint16_t k);
|
||||||
void setOpacity(uint8_t o);
|
void setOpacity(uint8_t o);
|
||||||
void setOption(uint8_t n, bool val);
|
void setOption(uint8_t n, bool val);
|
||||||
void setMode(uint8_t fx, bool loadDefaults = false);
|
void setMode(uint8_t fx, bool loadDefaults = false);
|
||||||
void setPalette(uint8_t pal);
|
void setPalette(uint8_t pal);
|
||||||
uint8_t differs(Segment& b) const;
|
uint8_t differs(const Segment& b) const;
|
||||||
void refreshLightCapabilities();
|
void refreshLightCapabilities();
|
||||||
|
|
||||||
// runtime data functions
|
// runtime data functions
|
||||||
@ -783,7 +784,6 @@ class WS2812FX { // 96 bytes
|
|||||||
setBrightness(uint8_t b, bool direct = false), // sets strip brightness
|
setBrightness(uint8_t b, bool direct = false), // sets strip brightness
|
||||||
setRange(uint16_t i, uint16_t i2, uint32_t col), // used for clock overlay
|
setRange(uint16_t i, uint16_t i2, uint32_t col), // used for clock overlay
|
||||||
purgeSegments(), // removes inactive segments from RAM (may incure penalty and memory fragmentation but reduces vector footprint)
|
purgeSegments(), // removes inactive segments from RAM (may incure penalty and memory fragmentation but reduces vector footprint)
|
||||||
setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t grouping = 1, uint8_t spacing = 0, uint16_t offset = UINT16_MAX, uint16_t startY=0, uint16_t stopY=1),
|
|
||||||
setMainSegmentId(unsigned n = 0),
|
setMainSegmentId(unsigned n = 0),
|
||||||
resetSegments(), // marks all segments for reset
|
resetSegments(), // marks all segments for reset
|
||||||
makeAutoSegments(bool forceReset = false), // will create segments based on configured outputs
|
makeAutoSegments(bool forceReset = false), // will create segments based on configured outputs
|
||||||
|
@ -489,8 +489,10 @@ void Segment::handleRandomPalette() {
|
|||||||
nblendPaletteTowardPalette(_randomPalette, _newRandomPalette, 48);
|
nblendPaletteTowardPalette(_randomPalette, _newRandomPalette, 48);
|
||||||
}
|
}
|
||||||
|
|
||||||
// segId is given when called from network callback, changes are queued if that segment is currently in its effect function
|
// sets Segment geometry (length or width/height and grouping, spacing and offset as well as 2D mapping)
|
||||||
void Segment::setUp(uint16_t i1, uint16_t i2, uint8_t grp, uint8_t spc, uint16_t ofs, uint16_t i1Y, uint16_t i2Y) {
|
// strip must be suspended (strip.suspend()) before calling this function
|
||||||
|
// this function may call fill() to clear pixels if spacing or mapping changed (which requires setting _vWidth, _vHeight, _vLength or beginDraw())
|
||||||
|
void Segment::setGeometry(uint16_t i1, uint16_t i2, uint8_t grp, uint8_t spc, uint16_t ofs, uint16_t i1Y, uint16_t i2Y, uint8_t m12) {
|
||||||
// return if neither bounds nor grouping have changed
|
// return if neither bounds nor grouping have changed
|
||||||
bool boundsUnchanged = (start == i1 && stop == i2);
|
bool boundsUnchanged = (start == i1 && stop == i2);
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
@ -498,11 +500,19 @@ void Segment::setUp(uint16_t i1, uint16_t i2, uint8_t grp, uint8_t spc, uint16_t
|
|||||||
#endif
|
#endif
|
||||||
if (boundsUnchanged
|
if (boundsUnchanged
|
||||||
&& (!grp || (grouping == grp && spacing == spc))
|
&& (!grp || (grouping == grp && spacing == spc))
|
||||||
&& (ofs == UINT16_MAX || ofs == offset)) return;
|
&& (ofs == UINT16_MAX || ofs == offset)
|
||||||
|
&& (m12 == map1D2D)
|
||||||
|
) return;
|
||||||
|
|
||||||
stateChanged = true; // send UDP/WS broadcast
|
stateChanged = true; // send UDP/WS broadcast
|
||||||
|
|
||||||
if (stop) fill(BLACK); // turn old segment range off (clears pixels if changing spacing)
|
if (stop || spc != spacing || m12 != map1D2D) {
|
||||||
|
_vWidth = virtualWidth();
|
||||||
|
_vHeight = virtualHeight();
|
||||||
|
_vLength = virtualLength();
|
||||||
|
_segBri = currentBri();
|
||||||
|
fill(BLACK); // turn old segment range off or clears pixels if changing spacing (requires _vWidth/_vHeight/_vLength/_segBri)
|
||||||
|
}
|
||||||
if (grp) { // prevent assignment of 0
|
if (grp) { // prevent assignment of 0
|
||||||
grouping = grp;
|
grouping = grp;
|
||||||
spacing = spc;
|
spacing = spc;
|
||||||
@ -511,6 +521,7 @@ void Segment::setUp(uint16_t i1, uint16_t i2, uint8_t grp, uint8_t spc, uint16_t
|
|||||||
spacing = 0;
|
spacing = 0;
|
||||||
}
|
}
|
||||||
if (ofs < UINT16_MAX) offset = ofs;
|
if (ofs < UINT16_MAX) offset = ofs;
|
||||||
|
map1D2D = constrain(m12, 0, 7);
|
||||||
|
|
||||||
DEBUG_PRINT(F("setUp segment: ")); DEBUG_PRINT(i1);
|
DEBUG_PRINT(F("setUp segment: ")); DEBUG_PRINT(i1);
|
||||||
DEBUG_PRINT(','); DEBUG_PRINT(i2);
|
DEBUG_PRINT(','); DEBUG_PRINT(i2);
|
||||||
@ -993,7 +1004,7 @@ uint32_t IRAM_ATTR_YN Segment::getPixelColor(int i) const
|
|||||||
return strip.getPixelColor(i);
|
return strip.getPixelColor(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Segment::differs(Segment& b) const {
|
uint8_t Segment::differs(const Segment& b) const {
|
||||||
uint8_t d = 0;
|
uint8_t d = 0;
|
||||||
if (start != b.start) d |= SEG_DIFFERS_BOUNDS;
|
if (start != b.start) d |= SEG_DIFFERS_BOUNDS;
|
||||||
if (stop != b.stop) d |= SEG_DIFFERS_BOUNDS;
|
if (stop != b.stop) d |= SEG_DIFFERS_BOUNDS;
|
||||||
@ -1595,19 +1606,6 @@ Segment& WS2812FX::getSegment(unsigned id) {
|
|||||||
return _segments[id >= _segments.size() ? getMainSegmentId() : id]; // vectors
|
return _segments[id >= _segments.size() ? getMainSegmentId() : id]; // vectors
|
||||||
}
|
}
|
||||||
|
|
||||||
// sets new segment bounds, queues if that segment is currently running
|
|
||||||
void WS2812FX::setSegment(uint8_t segId, uint16_t i1, uint16_t i2, uint8_t grouping, uint8_t spacing, uint16_t offset, uint16_t startY, uint16_t stopY) {
|
|
||||||
if (segId >= getSegmentsNum()) {
|
|
||||||
if (i2 <= i1) return; // do not append empty/inactive segments
|
|
||||||
appendSegment(Segment(0, strip.getLengthTotal()));
|
|
||||||
segId = getSegmentsNum()-1; // segments are added at the end of list
|
|
||||||
}
|
|
||||||
suspend();
|
|
||||||
_segments[segId].setUp(i1, i2, grouping, spacing, offset, startY, stopY);
|
|
||||||
resume();
|
|
||||||
if (segId > 0 && segId == getSegmentsNum()-1 && i2 <= i1) _segments.pop_back(); // if last segment was deleted remove it from vector
|
|
||||||
}
|
|
||||||
|
|
||||||
void WS2812FX::resetSegments() {
|
void WS2812FX::resetSegments() {
|
||||||
_segments.clear(); // destructs all Segment as part of clearing
|
_segments.clear(); // destructs all Segment as part of clearing
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
|
@ -34,7 +34,7 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
|
|||||||
//DEBUG_PRINTLN(F("-- JSON deserialize segment."));
|
//DEBUG_PRINTLN(F("-- JSON deserialize segment."));
|
||||||
Segment& seg = strip.getSegment(id);
|
Segment& seg = strip.getSegment(id);
|
||||||
//DEBUG_PRINTF_P(PSTR("-- Original segment: %p (%p)\n"), &seg, seg.data);
|
//DEBUG_PRINTF_P(PSTR("-- Original segment: %p (%p)\n"), &seg, seg.data);
|
||||||
Segment prev = seg; //make a backup so we can tell if something changed (calling copy constructor)
|
const Segment prev = seg; //make a backup so we can tell if something changed (calling copy constructor)
|
||||||
//DEBUG_PRINTF_P(PSTR("-- Duplicate segment: %p (%p)\n"), &prev, prev.data);
|
//DEBUG_PRINTF_P(PSTR("-- Duplicate segment: %p (%p)\n"), &prev, prev.data);
|
||||||
|
|
||||||
int start = elem["start"] | seg.start;
|
int start = elem["start"] | seg.start;
|
||||||
@ -96,17 +96,11 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
|
|||||||
uint16_t of = seg.offset;
|
uint16_t of = seg.offset;
|
||||||
uint8_t soundSim = elem["si"] | seg.soundSim;
|
uint8_t soundSim = elem["si"] | seg.soundSim;
|
||||||
uint8_t map1D2D = elem["m12"] | seg.map1D2D;
|
uint8_t map1D2D = elem["m12"] | seg.map1D2D;
|
||||||
|
uint8_t set = elem[F("set")] | seg.set;
|
||||||
if ((spc>0 && spc!=seg.spacing) || seg.map1D2D!=map1D2D) seg.fill(BLACK); // clear spacing gaps
|
seg.set = constrain(set, 0, 3);
|
||||||
|
|
||||||
seg.map1D2D = constrain(map1D2D, 0, 7);
|
|
||||||
seg.soundSim = constrain(soundSim, 0, 3);
|
seg.soundSim = constrain(soundSim, 0, 3);
|
||||||
|
|
||||||
uint8_t set = elem[F("set")] | seg.set;
|
int len = (stop > start) ? stop - start : 1;
|
||||||
seg.set = constrain(set, 0, 3);
|
|
||||||
|
|
||||||
int len = 1;
|
|
||||||
if (stop > start) len = stop - start;
|
|
||||||
int offset = elem[F("of")] | INT32_MAX;
|
int offset = elem[F("of")] | INT32_MAX;
|
||||||
if (offset != INT32_MAX) {
|
if (offset != INT32_MAX) {
|
||||||
int offsetAbs = abs(offset);
|
int offsetAbs = abs(offset);
|
||||||
@ -117,7 +111,7 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
|
|||||||
if (stop > start && of > len -1) of = len -1;
|
if (stop > start && of > len -1) of = len -1;
|
||||||
|
|
||||||
// update segment (delete if necessary)
|
// update segment (delete if necessary)
|
||||||
seg.setUp(start, stop, grp, spc, of, startY, stopY); // strip needs to be suspended for this to work without issues
|
seg.setGeometry(start, stop, grp, spc, of, startY, stopY, map1D2D); // strip needs to be suspended for this to work without issues
|
||||||
|
|
||||||
if (newSeg) seg.refreshLightCapabilities(); // fix for #3403
|
if (newSeg) seg.refreshLightCapabilities(); // fix for #3403
|
||||||
|
|
||||||
|
@ -874,7 +874,9 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
spcI = std::max(0,getNumVal(&req, pos));
|
spcI = std::max(0,getNumVal(&req, pos));
|
||||||
}
|
}
|
||||||
strip.setSegment(selectedSeg, startI, stopI, grpI, spcI, UINT16_MAX, startY, stopY);
|
strip.suspend(); // must suspend strip operations before changing geometry
|
||||||
|
selseg.setGeometry(startI, stopI, grpI, spcI, UINT16_MAX, startY, stopY, selseg.map1D2D);
|
||||||
|
strip.resume();
|
||||||
|
|
||||||
pos = req.indexOf(F("RV=")); //Segment reverse
|
pos = req.indexOf(F("RV=")); //Segment reverse
|
||||||
if (pos > 0) selseg.reverse = req.charAt(pos+3) != '0';
|
if (pos > 0) selseg.reverse = req.charAt(pos+3) != '0';
|
||||||
|
@ -260,11 +260,12 @@ void parseNotifyPacket(uint8_t *udpIn) {
|
|||||||
// are we syncing bounds and slave has more active segments than master?
|
// are we syncing bounds and slave has more active segments than master?
|
||||||
if (receiveSegmentBounds && numSrcSegs < strip.getActiveSegmentsNum()) {
|
if (receiveSegmentBounds && numSrcSegs < strip.getActiveSegmentsNum()) {
|
||||||
DEBUG_PRINTLN(F("Removing excessive segments."));
|
DEBUG_PRINTLN(F("Removing excessive segments."));
|
||||||
for (size_t i=strip.getSegmentsNum(); i>numSrcSegs; i--) {
|
strip.suspend(); //should not be needed as UDP handling is not done in ISR callbacks but still added "just in case"
|
||||||
if (strip.getSegment(i).isActive()) {
|
for (size_t i=strip.getSegmentsNum(); i>numSrcSegs && i>0; i--) {
|
||||||
strip.setSegment(i-1,0,0); // delete segment
|
Segment &seg = strip.getSegment(i-1);
|
||||||
}
|
if (seg.isActive()) seg.deactivate(); // delete segment
|
||||||
}
|
}
|
||||||
|
strip.resume();
|
||||||
}
|
}
|
||||||
size_t inactiveSegs = 0;
|
size_t inactiveSegs = 0;
|
||||||
for (size_t i = 0; i < numSrcSegs && i < strip.getMaxSegments(); i++) {
|
for (size_t i = 0; i < numSrcSegs && i < strip.getMaxSegments(); i++) {
|
||||||
@ -300,7 +301,7 @@ void parseNotifyPacket(uint8_t *udpIn) {
|
|||||||
if (!receiveSegmentOptions) {
|
if (!receiveSegmentOptions) {
|
||||||
DEBUG_PRINTF_P(PSTR("Set segment w/o options: %d [%d,%d;%d,%d]\n"), id, (int)start, (int)stop, (int)startY, (int)stopY);
|
DEBUG_PRINTF_P(PSTR("Set segment w/o options: %d [%d,%d;%d,%d]\n"), id, (int)start, (int)stop, (int)startY, (int)stopY);
|
||||||
strip.suspend(); //should not be needed as UDP handling is not done in ISR callbacks but still added "just in case"
|
strip.suspend(); //should not be needed as UDP handling is not done in ISR callbacks but still added "just in case"
|
||||||
selseg.setUp(start, stop, selseg.grouping, selseg.spacing, offset, startY, stopY);
|
selseg.setGeometry(start, stop, selseg.grouping, selseg.spacing, offset, startY, stopY, selseg.map1D2D);
|
||||||
strip.resume();
|
strip.resume();
|
||||||
continue; // we do receive bounds, but not options
|
continue; // we do receive bounds, but not options
|
||||||
}
|
}
|
||||||
@ -342,12 +343,12 @@ void parseNotifyPacket(uint8_t *udpIn) {
|
|||||||
if (receiveSegmentBounds) {
|
if (receiveSegmentBounds) {
|
||||||
DEBUG_PRINTF_P(PSTR("Set segment w/ options: %d [%d,%d;%d,%d]\n"), id, (int)start, (int)stop, (int)startY, (int)stopY);
|
DEBUG_PRINTF_P(PSTR("Set segment w/ options: %d [%d,%d;%d,%d]\n"), id, (int)start, (int)stop, (int)startY, (int)stopY);
|
||||||
strip.suspend(); //should not be needed as UDP handling is not done in ISR callbacks but still added "just in case"
|
strip.suspend(); //should not be needed as UDP handling is not done in ISR callbacks but still added "just in case"
|
||||||
selseg.setUp(start, stop, udpIn[5+ofs], udpIn[6+ofs], offset, startY, stopY);
|
selseg.setGeometry(start, stop, udpIn[5+ofs], udpIn[6+ofs], offset, startY, stopY, selseg.map1D2D);
|
||||||
strip.resume();
|
strip.resume();
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTF_P(PSTR("Set segment grouping: %d [%d,%d]\n"), id, (int)udpIn[5+ofs], (int)udpIn[6+ofs]);
|
DEBUG_PRINTF_P(PSTR("Set segment grouping: %d [%d,%d]\n"), id, (int)udpIn[5+ofs], (int)udpIn[6+ofs]);
|
||||||
strip.suspend(); //should not be needed as UDP handling is not done in ISR callbacks but still added "just in case"
|
strip.suspend(); //should not be needed as UDP handling is not done in ISR callbacks but still added "just in case"
|
||||||
selseg.setUp(selseg.start, selseg.stop, udpIn[5+ofs], udpIn[6+ofs], selseg.offset, selseg.startY, selseg.stopY);
|
selseg.setGeometry(selseg.start, selseg.stop, udpIn[5+ofs], udpIn[6+ofs], selseg.offset, selseg.startY, selseg.stopY, selseg.map1D2D);
|
||||||
strip.resume();
|
strip.resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user