From: Martin Mares Date: Wed, 24 May 2023 20:50:02 +0000 (+0200) Subject: Better IR control of lights X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=ursary.git Better IR control of lights --- diff --git a/ursaryd.c b/ursaryd.c index 237e0af..1d0e5ff 100644 --- a/ursaryd.c +++ b/ursaryd.c @@ -491,7 +491,6 @@ static bool lights_on[2]; 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) { @@ -568,32 +567,43 @@ static void update_lights_from_button(int ch, int on) } } -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); } @@ -848,19 +858,17 @@ static void notify_ir(const char *key) 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"))