/*
* The Ursary Control Panel
*
- * (c) 2014--2022 Martin Mares <mj@ucw.cz>
+ * (c) 2014-2023 Martin Mares <mj@ucw.cz>
*/
#undef LOCAL_DEBUG
* 6 Albireo Zoom mute MPD prev
* 7 eveyrhing else mute MPD next
*
- * center -
+ * center rainbow brightness
* slider light color temperature
*/
-#define PCH_SINK "alsa_output.pci-0000_00_1f.3.analog-stereo"
+#define PCH_SINK "alsa_output.pci-0000_07_00.6.analog-stereo"
#define BT_SINK "bluez_sink.CC_98_8B_D0_8C_06.a2dp_sink"
#define LOGI_SOURCE "alsa_input.usb-046d_Logitech_Webcam_C925e_EF163C5F-02.analog-stereo"
}
}
+static void update_lights_from_ir(int ch, int dir)
+{
+ if (lights_on[ch])
+ lights_brightness[ch] = CLAMP(lights_brightness[ch] + 0.07*dir, 0., 1.);
+ else if (dir > 0)
+ {
+ lights_on[ch] = 1;
+ lights_brightness[ch] = 1;
+ }
+ else
+ {
+ 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_temp_ir(void)
+{
+ 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);
+}
+
+/*** Rainbow ***/
+
+static double rainbow_brightness;
+static timestamp_t rainbow_last_update;
+
+static void update_rainbow(void)
+{
+ noct_set_ring(8, RING_MODE_LEFT, rainbow_brightness * 127);
+}
+
+static void send_rainbow(void)
+{
+ char val[100];
+ snprintf(val, sizeof(val), "%.3f", rainbow_brightness);
+ mqtt_publish("burrow/lights/rainbow/brightness", val);
+ rainbow_last_update = main_get_now();
+ update_rainbow();
+}
+
+static void update_rainbow_from_rotary(int delta)
+{
+ rainbow_brightness = CLAMP(rainbow_brightness + 0.015*delta*abs(delta), 0., 1.);
+ send_rainbow();
+}
+
/*** Main update routines ***/
static struct main_timer update_timer;
update_source_buttons();
update_mpd();
update_lights();
+ update_rainbow();
}
void schedule_update(void)
case 3:
update_lights_from_rotary(0, delta);
break;
+ case 8:
+ update_rainbow_from_rotary(delta);
+ break;
case 9:
update_lights_from_slider(delta);
break;
schedule_update();
}
+static void notify_ir(const char *key)
+{
+ DBG("Received IR key %s", key);
+
+ // Lights
+ if (!strcmp(key, "preset+"))
+ update_lights_from_ir(1, 1);
+ else if (!strcmp(key, "preset-"))
+ 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, -1);
+ else if (!strcmp(key, "band"))
+ update_lights_on_off_ir(1);
+ else if (!strcmp(key, "fm-mode"))
+ update_lights_on_off_ir(0);
+ else if (!strcmp(key, "dimmer"))
+ update_lights_temp_ir();
+
+ // Player
+ else if (!strcmp(key, "play"))
+ mpd_play();
+ else if (!strcmp(key, "stop"))
+ mpd_stop();
+ else if (!strcmp(key, "pause"))
+ mpd_pause(1);
+ else if (!strcmp(key, "prev-song"))
+ mpd_prev();
+ else if (!strcmp(key, "next-song"))
+ mpd_next();
+ else if (!strcmp(key, "rewind"))
+ update_sink_from_rotary(-2, PCH_SINK);
+ else if (!strcmp(key, "ffwd"))
+ update_sink_from_rotary(2, PCH_SINK);
+}
+
void notify_mqtt(const char *topic, const char *val)
{
const char blc[] = "burrow/lights/catarium/";
update_lights();
}
}
+
+ if (!strcmp(topic, "burrow/lights/rainbow/brightness"))
+ {
+ double b;
+ if (sscanf(val, "%lf", &b) == 1 && b >= 0 && b <= 1)
+ {
+ timestamp_t now = main_get_now();
+ if (!rainbow_last_update || rainbow_last_update + 1000 < now)
+ {
+ DBG("Received foreign rainbow settings");
+ rainbow_brightness = b;
+ update_rainbow();
+ }
+ }
+ }
+
+ if (!strcmp(topic, "burrow/control/catarium-ir"))
+ notify_ir(val);
}
/*** Main entry point ***/