more G-Labs products

Author Topic: Philips Hue and Ambilight  (Read 5865 times)

August 18, 2015, 06:54:58 PM
Reply #15

saue0

  • **
  • Information
  • Jr. Member
  • Posts: 40
Here my code for RGB to HSV
case "Control.Color":
     
        double r = int.Parse(values[0]) / 255;
        double g = int.Parse(values[1]) / 255;
        double b = int.Parse(values[2]) / 255;
       
        double min = Math.Min( r, Math.Min( g, b ));
        double max = Math.Max( r, Math.Max( g, b ));
        double v = max;            // v
        double s = 0;            // s
        double h = 0;            // h
        double delta = max - min;
        if( max != 0 )
        {
            s = delta / max;      // s

            if( r == max )
                h = ( g - b ) / delta;      // between yellow & magenta
            else if( g == max )
                h = 2 + ( b - r ) / delta;   // between cyan & yellow
            else
                h = 4 + ( r - g ) / delta;   // between magenta & cyan
           
            h *= 60;            // degrees
            if( h < 0 )
                h += 360;       
        }
     
        if (values.Length > 3)
            transition = ((int)(double.Parse(values[3]) * 10));

        bridgeapicall(grp, lightnumber, "{ \"on\" : true" +
                      ", \"hue\" : " + ((int)Math.Round(h * 182.044)).ToString() +
                      ", \"sat\" : " + ((int)Math.Round(s * 255)).ToString() +
                      ", \"bri\" : " + ((int)Math.Round(v * 255)).ToString() +
                      ", \"transitiontime\" : " + transition.ToString() +  "}");
        break;

August 22, 2015, 09:36:33 AM
Reply #16

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Thanks for that saue0, unfortunately I've given up on this project though. My wife *hates* the Hues as extra Ambilights so I've never really put more effort into it.

I can't seem to find my test code either, although it wasn't too hard to get the RGB info from the TV. If anyone is interested you can find some examples for reading the data in my previous posts.