1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

X86/64 Question about color smoothing

Discussion in 'Software Support' started by kokoko3k, 27 March 2019.

  1. kokoko3k

    kokoko3k New Member

    Messages:
    6
    Hardware:
    +Arduino
    Hi, i'd like to understand better how color smoothing works.
    I know, given a start color and an end color, it interpolates between them over a specified amount of time at a specified refresh rate, fine.
    What i've not understood is the timing, an example with just one led should be clear:

    Imagine i've set a slooow smoothing over 1000ms.

    a) time 0ms : tell hyperiond to display 0,0,0
    b) time 500ms: tell hyperiond to display 255,255,255
    c) time 1000ms: tell hyperiond to display 0,255,0

    What will happen?
    a) To simplify things, suppose that at time 0 there is no smoothing triggered.
    b) At time 500ms, hyperion will start to fade from black to white; and given the high smoothing time of 1000ms, the fade is expected to stop at time 1500ms.
    c) "BUT" at time 1000ms, i tell hyperiond i want green instead, and by that time, the previous fade (b2w) is still going on, it is in the middle, and probably the led is a perfect gray (128,128,128).

    So i'd like to know what would the happen at time 1000ms.
    Does the fading stop and another fade starts just from 128,128,128 to 0,255,0 or will hyperiond wait for the first fade (b2w) to finish, before starting the new one from 255,255,255 to 0,255,0?​


    I hope i've been clear enough, thanks.
     
  2. kokoko3k

    kokoko3k New Member

    Messages:
    6
    Hardware:
    +Arduino
    Ok, after several testing, i understood that unfortunately the smooth routine "queues" fades.
    I modified my sketch to fade itself and disabled the smoothing in hyperion, here it is, works well for me.

    Code:
    //put the following in Hyperion smoothing config :
    /*  // SMOOTHING CONFIG
      "smoothing" :
      {
      "type"  : "linear",
      "time_ms"  : 0,
      "updateFrequency" : 60.0000,
      "updateDelay"  : 0
      }
    */
    
    #include "FastLED.h"
    // How many leds in your strip?
    #define NUM_LEDS 33
    // For led chips like Neopixels, which have a data line, ground, and power, you just
    // need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
    // ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
    #define DATA_PIN 3
    #define CLOCK_PIN 13
    #define COLOR_ORDER RGB
    // Adalight sends a "Magic Word" (defined in /etc/boblight.conf) before sending the pixel data
    uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i;
    // Baudrate, higher rate allows faster refresh rate and more LEDs (defined in /etc/boblight.conf)
    #define serialRate 500000
    
    
    
    // Define the array of leds
    CRGB leds[NUM_LEDS];
    CRGB oldleds[NUM_LEDS];
    
    
    float speed = 0.1; //0.0 -> 1.0
    
    
    int ismooth_value_step(int iStart, int iEnd, int iStep ){
      int diff ;
      diff = iStart - iEnd ;
      if ( abs(diff) > iStep ) {
      
      if (iStart > iEnd) {
      return ( iStart - iStep );
      } else {
      return ( iStart + iStep );  
      }
    
      } else {
      return iEnd ;
      }
    }
    
    int ismooth_value_k(int iStart, int iEnd, float fSpeed){
      int diff, abs_diff ;
      diff = iStart - iEnd ;
      abs_diff = abs(diff);
      if ( abs_diff > 1 ) {
      
      if (iStart > iEnd) {
      return round ( iStart - (fSpeed * abs_diff) );
      } else {
      fSpeed = fSpeed / 2 ;
      return round ( iStart + (fSpeed * abs_diff ) );  
      }
    
      } else {
      return iEnd ;
      }
    }
    
    void setup() {
      FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, 100);  //reset a zero di tutti i led
      delay(500);
      LEDS.showColor(CRGB(0, 0, 0));
      delay(250);
      FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
      
      // initial RGB flash
      LEDS.showColor(CRGB(32, 0, 0));
      delay(100);
      LEDS.showColor(CRGB(0, 32, 0));
      delay(100);
      LEDS.showColor(CRGB(0, 0, 32));
      delay(100);
      LEDS.showColor(CRGB(0, 0, 0));
     
      Serial.begin(serialRate);
      Serial.print("Ada\n"); // Send "Magic Word" string to host
    }
    void loop() {
      // wait for first byte of Magic Word
      for(i = 0; i < sizeof prefix; ++i) {
      waitLoop: while (!Serial.available()) ;;
      // Check next byte in Magic Word
      if(prefix[i] == Serial.read()) continue;
      // otherwise, start over
      i = 0;
      goto waitLoop;
      }
      // Hi, Lo, Checksum
      while (!Serial.available()) ;;
      hi=Serial.read();
      while (!Serial.available()) ;;
      lo=Serial.read();
      while (!Serial.available()) ;;
      chk=Serial.read();
      // if checksum does not match go back to wait
      if (chk != (hi ^ lo ^ 0x55))
      {
      i=0;
      goto waitLoop;
      }
      memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
      // read the transmission data and set LED values
      for (uint8_t i = 0; i < NUM_LEDS; i++) {
      byte r, g, b;  
      while(!Serial.available());
      r = Serial.read();
      while(!Serial.available());
      g = Serial.read();
      while(!Serial.available());
      b = Serial.read();
    
      leds[i].r = ismooth_value_k(oldleds[i].r,r,speed);
      leds[i].g = ismooth_value_k(oldleds[i].g,g,speed);
      leds[i].b = ismooth_value_k(oldleds[i].b,b,speed);
    
      oldleds[i].r = leds[i].r ;
      oldleds[i].g = leds[i].g ;
      oldleds[i].b = leds[i].b ;
    
      }
      // shows new values
    FastLED.show();
    }
    
    It provides smooth and slow (play with the speed value) color fades; it differs by the hyperion implementation because it reacts immediately to the requested changes instead of waiting for the previous fade to complete.
    Think at it as a sort of real time temporal smoothing.
     
  3. TPmodding

    TPmodding Administrator Staff Member Administrator

    Messages:
    1,372
    Hardware:
    RPi1/Zero, RPi2, RPi3, +Arduino, +nodeMCU/ESP8266