/*
* Interaction with MQTT
*
- * (c) 2022 Martin Mares <mj@ucw.cz>
+ * (c) 2022-2023 Martin Mares <mj@ucw.cz>
*/
#undef LOCAL_DEBUG
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");
/*
* The Ursary Control Panel
*
- * (c) 2014--2022 Martin Mares <mj@ucw.cz>
+ * (c) 2014-2023 Martin Mares <mj@ucw.cz>
*/
#undef LOCAL_DEBUG
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)
+{
+ 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;
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/";
}
}
}
+
+ if (!strcmp(topic, "burrow/control/catarium-ir"))
+ notify_ir(val);
}
/*** Main entry point ***/