if( rq->bRequest )
{
type = 1;
H = rq->wValue.bytes[0];
S = rq->wValue.bytes[1];
V = rq->wValue.bytes[2];
}
else
{
type = 0;
lamp.r = rq->wValue.bytes[0];
lamp.g = rq->wValue.bytes[1];
lamp.b = rq->wValue.bytes[2];
}
//computeOutputStatus();
return 0;
}
//-------------------------------------------------------------------------------
// Main
//-------------------------------------------------------------------------------
if ( type )
{
type = 0;
hsv_to_rgb(H,S,V,&lamp);
}
}
return 0;
}
//-------------------------------------------------------------------------------
// Converts HSV to RGB
//-------------------------------------------------------------------------------
void hsv_to_rgb (unsigned char h, unsigned char s, unsigned char v, RGB * out)
{
unsigned char r=0,g=0,b=0, i, f;
unsigned int p, q, t;
if( s == 0 ) {
r = g = b = v;
}
else
{ i=h/43;
f=h%43;
p = (v * (255 - s))/256;
q = (v * ((10710 - (s * f))/42))/256;
t = (v * ((10710 - (s * (42 - f)))/42))/256;
switch( i )
{ case 0:
r = v; g = t; b = p; break;
case 1:
r = q; g = v; b = p; break;
case 2:
r = p; g = v; b = t; break;
case 3:
r = p; g = q; b = v; break;
case 4:
r = t; g = p; b = v; break;
case 5:
r = v; g = p; b = q; break;
}
}
out->r=r; out->g=g; out->b=b;
}