]> mj.ucw.cz Git - ursary.git/commitdiff
React to IR remote control
authorMartin Mares <mj@ucw.cz>
Sun, 14 May 2023 13:50:58 +0000 (15:50 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 14 May 2023 13:50:58 +0000 (15:50 +0200)
mqtt.c
ursaryd.c

diff --git a/mqtt.c b/mqtt.c
index a84ea2b43d22817388cd15b7a4fd01a8988db78a..93cb0b355e882328448bced8ee36c8bad77b9291 100644 (file)
--- a/mqtt.c
+++ b/mqtt.c
@@ -1,7 +1,7 @@
 /*
  *     Interaction with MQTT
  *
- *     (c) 2022 Martin Mares <mj@ucw.cz>
+ *     (c) 2022-2023 Martin Mares <mj@ucw.cz>
  */
 
 #undef LOCAL_DEBUG
@@ -44,7 +44,8 @@ static void mqtt_conn_callback(struct mosquitto *mosq UNUSED, void *obj UNUSED,
   if (!status)
     {
       msg(L_DEBUG, "MQTT: Connection established, subscribing");
-      if (mosquitto_subscribe(mosq, NULL, "burrow/lights/catarium/#", 1) != MOSQ_ERR_SUCCESS)
+      if (mosquitto_subscribe(mosq, NULL, "burrow/lights/catarium/#", 1) != MOSQ_ERR_SUCCESS ||
+          mosquitto_subscribe(mosq, NULL, "burrow/control/catarium-ir", 1) != MOSQ_ERR_SUCCESS)
        die("Mosquitto: subscribe failed");
 
       mqtt_publish("status/ursary", "ok");
index 85cde2bfdd8e06ef013076f1eab0cad89d4520ed..2a67a78a780fe7f309b4a489384f8c65ca983e21 100644 (file)
--- a/ursaryd.c
+++ b/ursaryd.c
@@ -1,7 +1,7 @@
 /*
  *     The Ursary Control Panel
  *
- *     (c) 2014--2022 Martin Mares <mj@ucw.cz>
+ *     (c) 2014-2023 Martin Mares <mj@ucw.cz>
  */
 
 #undef LOCAL_DEBUG
@@ -491,6 +491,7 @@ 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)
 {
@@ -567,6 +568,36 @@ static void update_lights_from_button(int ch, int on)
     }
 }
 
+static void update_lights_from_ir(int ch, int state)
+{
+  lights_on[ch] = state;
+  send_lights(ch);
+  lights_ir_channel = ch;
+}
+
+static void update_lights_ir_num(int num)
+{
+  if (lights_ir_channel < 2)
+    {
+      lights_brightness[lights_ir_channel] = num / 9.;
+      send_lights(lights_ir_channel);
+    }
+  else
+    {
+      lights_temperature[0] = num / 9.;
+      lights_temperature[1] = num / 9.;
+      send_lights(0);
+      send_lights(1);
+    }
+}
+
+static void update_lights_ir_full(void)
+{
+  lights_brightness[0] = lights_brightness[1] = 1;
+  send_lights(0);
+  send_lights(1);
+}
+
 /*** Rainbow ***/
 
 static double rainbow_brightness;
@@ -809,6 +840,45 @@ void notify_touch(int rotary UNUSED, int on UNUSED)
     schedule_update();
 }
 
+static void notify_ir(const char *key)
+{
+  msg(L_INFO, "Received IR key %s", key);
+
+  // Lights
+  if (!strcmp(key, "preset+"))
+    update_lights_from_ir(0, 1);
+  else if (!strcmp(key, "preset-"))
+    update_lights_from_ir(0, 0);
+  else if (!strcmp(key, "tuning-up"))
+    update_lights_from_ir(1, 1);
+  else if (!strcmp(key, "tuning-down"))
+    update_lights_from_ir(1, 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);
+  else if (!strcmp(key, "band"))
+    lights_ir_channel = 2;
+  else if (!strcmp(key, "fm-mode"))
+    update_lights_ir_full();
+
+  // 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(-5, PCH_SINK);
+  else if (!strcmp(key, "ffwd"))
+    update_sink_from_rotary(5, PCH_SINK);
+}
+
 void notify_mqtt(const char *topic, const char *val)
 {
   const char blc[] = "burrow/lights/catarium/";
@@ -857,6 +927,9 @@ void notify_mqtt(const char *topic, const char *val)
            }
        }
     }
+
+  if (!strcmp(topic, "burrow/control/catarium-ir"))
+    notify_ir(val);
 }
 
 /*** Main entry point ***/