Fix for segment on/off transitions.

Fix for missing return.
Slightly smoother Chunchun, added Speed parameter for Hiphotic.
This commit is contained in:
Blaz Kristan 2022-08-23 16:00:50 +02:00
parent 89f334e67b
commit a7dbfc4954
7 changed files with 28 additions and 23 deletions

View File

@ -2826,7 +2826,7 @@ uint16_t mode_bouncing_balls(void) {
// number of balls based on intensity setting to max of 7 (cycles colors)
// non-chosen color is a random color
uint8_t numBalls = int(((SEGMENT.intensity * (maxNumBalls - 0.8f)) / 255) + 1);
uint16_t numBalls = int(((SEGMENT.intensity * (maxNumBalls - 0.8f)) / 255) + 1);
float gravity = -9.81; // standard value of gravity
float impactVelocityStart = sqrt( -2 * gravity);
@ -2848,7 +2848,7 @@ uint16_t mode_bouncing_balls(void) {
if (balls[i].height < 0) { //start bounce
balls[i].height = 0;
//damping for better effect using multiple balls
float dampening = 0.90 - float(i)/(float(numBalls) * float(numBalls)); // avoid use pow(x, 2) - its extremely slow !
float dampening = 0.90 - float(i)/float(numBalls * numBalls); // avoid use pow(x, 2) - its extremely slow !
balls[i].impactVelocity = dampening * balls[i].impactVelocity;
balls[i].lastBounceTime = time;
@ -3574,7 +3574,8 @@ static const char _data_FX_MODE_PLASMA[] PROGMEM = "Plasma@Phase,;1,2,3;!;1d";
*/
uint16_t mode_percent(void) {
uint8_t percent = MAX(0, MIN(200, SEGMENT.intensity));
uint8_t percent = SEGMENT.intensity;
percent = constrain(percent, 0, 200);
uint16_t active_leds = (percent < 100) ? SEGLEN * percent / 100.0
: SEGLEN * (200 - percent) / 100.0;
@ -4003,7 +4004,8 @@ static const char _data_FX_MODE_FLOW[] PROGMEM = "Flow@!,!;!,!,!;!;mp12=1,1d"; /
*/
uint16_t mode_chunchun(void)
{
SEGMENT.fill(SEGCOLOR(1));
//SEGMENT.fill(SEGCOLOR(1));
SEGMENT.fade_out(254); // add a bit of trail
uint16_t counter = strip.now * (6 + (SEGMENT.speed >> 4));
uint16_t numBirds = 2 + (SEGLEN >> 3); // 2 + 1/8 of a segment
uint16_t span = (SEGMENT.intensity << 8) / numBirds;
@ -4014,6 +4016,7 @@ uint16_t mode_chunchun(void)
uint16_t megumin = sin16(counter) + 0x8000;
uint16_t bird = uint32_t(megumin * SEGLEN) >> 16;
uint32_t c = SEGMENT.color_from_palette((i * 255)/ numBirds, false, false, 0); // no palette wrapping
bird = constrain(bird, 0, SEGLEN-1);
SEGMENT.setPixelColor(bird, c);
}
return FRAMETIME;
@ -4941,7 +4944,7 @@ uint16_t mode_2DHiphotic() { // By: ldirko https://edit
const uint16_t cols = SEGMENT.virtualWidth();
const uint16_t rows = SEGMENT.virtualHeight();
const uint32_t a = strip.now / 8;
const uint32_t a = strip.now / ((SEGMENT.custom3>>1)+1);
for (int x = 0; x < cols; x++) {
for (int y = 0; y < rows; y++) {
@ -4951,7 +4954,7 @@ uint16_t mode_2DHiphotic() { // By: ldirko https://edit
return FRAMETIME;
} // mode_2DHiphotic()
static const char _data_FX_MODE_2DHIPHOTIC[] PROGMEM = "Hiphotic@X scale,Y scale;;!;2d";
static const char _data_FX_MODE_2DHIPHOTIC[] PROGMEM = "Hiphotic@X scale,Y scale,,,Speed;;!;2d";
/////////////////////////

View File

@ -427,6 +427,8 @@ uint16_t Segment::virtualLength() const {
void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col)
{
if (i >= virtualLength() || i<0) return; // if pixel would fall out of segment just exit
#ifndef WLED_DISABLE_2D
if (is2D()) { // if this does not work use strip.isMatrix
uint16_t vH = virtualHeight(); // segment height in logical pixels
@ -460,16 +462,16 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col)
break;
}
return;
} else if (width()==1 && height()>1) {
// we have a vertical 1D segment
setPixelColorXY(0, i, col); // transpose
} else if (width()>1 && height()==1) {
// we have a horizontal 1D segment
setPixelColorXY(i, 0, col);
} else if (width()==1 || height()==1) {
// we have a vertical or horizontal 1D segment (WARNING: virtual...() may be transposed)
int x = 0, y = 0;
if (virtualHeight()>1) y = i;
if (virtualWidth() >1) x = i;
setPixelColorXY(x, y, col);
return;
}
#endif
if (i >= virtualLength() || i<0) return; // if pixel would fall out of segment just exit
if (leds) leds[i] = col;
uint16_t len = length();

View File

@ -197,10 +197,10 @@ void handleAnalog(uint8_t b)
// otherwise use "double press" for segment selection
Segment& seg = strip.getSegment(macroDoublePress[b]);
if (aRead == 0) {
seg.on = false; // off
seg.setOption(SEG_OPTION_ON, false); // off (use transition)
} else {
seg.setOpacity(aRead);
seg.on = true;
seg.setOption(SEG_OPTION_ON, true); // on (use transition)
}
// this will notify clients of update (websockets,mqtt,etc)
updateInterfaces(CALL_MODE_BUTTON);

View File

@ -102,12 +102,12 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
byte segbri = seg.opacity;
if (getVal(elem["bri"], &segbri)) {
if (segbri > 0) seg.setOpacity(segbri);
seg.on = segbri;
seg.setOption(SEG_OPTION_ON, segbri); // use transition
}
bool on = elem["on"] | seg.on;
if (elem["on"].is<const char*>() && elem["on"].as<const char*>()[0] == 't') on = !on;
seg.on = on;
seg.setOption(SEG_OPTION_ON, on); // use transition
bool frz = elem["frz"] | seg.freeze;
if (elem["frz"].is<const char*>() && elem["frz"].as<const char*>()[0] == 't') frz = !seg.freeze;
seg.freeze = frz;

View File

@ -713,7 +713,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
pos = req.indexOf(F("SB=")); //Segment brightness/opacity
if (pos > 0) {
byte segbri = getNumVal(&req, pos);
selseg.on = segbri;
selseg.setOption(SEG_OPTION_ON, segbri); // use transition
if (segbri) {
selseg.setOpacity(segbri);
}
@ -722,9 +722,9 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
pos = req.indexOf(F("SW=")); //segment power
if (pos > 0) {
switch (getNumVal(&req, pos)) {
case 0: selseg.on = false; break;
case 1: selseg.on = true; break;
default: selseg.on = !selseg.on; break;
case 0: selseg.setOption(SEG_OPTION_ON, false); break; // use transition
case 1: selseg.setOption(SEG_OPTION_ON, true); break; // use transition
default: selseg.setOption(SEG_OPTION_ON, !selseg.on); break; // use transition
}
}

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2208220
#define VERSION 2208231
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG

View File

@ -425,7 +425,7 @@ void deEEP() {
for (byte j = 0; j < strip.getMaxSegments(); j++)
{
strip.getSegment(j).opacity = 255;
strip.getSegment(j).on = true;
strip.getSegment(j).setOption(SEG_OPTION_ON, true); // use transistion
}
}
serializeState(pObj, true, false, true);