static double lights_brightness[2];
static double lights_temperature[2];
static timestamp_t lights_last_update[2];
-static int lights_ir_channel; // 2 if temperature
static void update_lights(void)
{
}
}
-static void update_lights_from_ir(int ch, int state)
+static void update_lights_from_ir(int ch, int dir)
{
- lights_on[ch] = state;
- send_lights(ch);
- lights_ir_channel = ch;
-}
-
-static void update_lights_ir_num(int num)
-{
- if (lights_ir_channel < 2)
+ if (lights_on[ch])
+ lights_brightness[ch] = CLAMP(lights_brightness[ch] + 0.07*dir, 0., 1.);
+ else if (dir > 0)
{
- lights_brightness[lights_ir_channel] = num / 9.;
- send_lights(lights_ir_channel);
+ lights_on[ch] = 1;
+ lights_brightness[ch] = 1;
}
else
{
- lights_temperature[0] = num / 9.;
- lights_temperature[1] = num / 9.;
- send_lights(0);
- send_lights(1);
+ lights_on[ch] = 1;
+ lights_brightness[ch] = 0.05;
}
+ send_lights(ch);
+}
+
+static void update_lights_on_off_ir(int ch)
+{
+ lights_on[ch] ^= 1;
+ send_lights(ch);
}
-static void update_lights_ir_full(void)
+static void update_lights_temp_ir(void)
{
- lights_brightness[0] = lights_brightness[1] = 1;
+ if (!lights_on[0] && !lights_on[1])
+ return;
+
+ double t = (lights_temperature[0] + lights_temperature[1]) / 2;
+ if (t >= 0.66)
+ t = 0;
+ else if (t < 0.33)
+ t = 0.5;
+ else
+ t = 1;
+ lights_temperature[0] = lights_temperature[1] = t;
+
send_lights(0);
send_lights(1);
}
if (!strcmp(key, "preset+"))
update_lights_from_ir(1, 1);
else if (!strcmp(key, "preset-"))
- update_lights_from_ir(1, 0);
+ update_lights_from_ir(1, -1);
else if (!strcmp(key, "tuning-up"))
update_lights_from_ir(0, 1);
else if (!strcmp(key, "tuning-down"))
- update_lights_from_ir(0, 0);
- else if (strlen(key) == 1 && key[0] >= '0' && key[0] <= '9')
- update_lights_ir_num(key[0] - '0');
- else if (!strcmp(key, "10/0"))
- update_lights_ir_num(0);
+ update_lights_from_ir(0, -1);
else if (!strcmp(key, "band"))
- lights_ir_channel = 2;
+ update_lights_on_off_ir(1);
else if (!strcmp(key, "fm-mode"))
- update_lights_ir_full();
+ update_lights_on_off_ir(0);
+ else if (!strcmp(key, "dimmer"))
+ update_lights_temp_ir();
// Player
else if (!strcmp(key, "play"))