From: Martin Mares Date: Sun, 14 May 2023 13:50:58 +0000 (+0200) Subject: React to IR remote control X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=9b398afc18f6240f61eda6d3e640ca90e5601fe9;p=ursary.git React to IR remote control --- diff --git a/mqtt.c b/mqtt.c index a84ea2b..93cb0b3 100644 --- a/mqtt.c +++ b/mqtt.c @@ -1,7 +1,7 @@ /* * Interaction with MQTT * - * (c) 2022 Martin Mares + * (c) 2022-2023 Martin Mares */ #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"); diff --git a/ursaryd.c b/ursaryd.c index 85cde2b..2a67a78 100644 --- a/ursaryd.c +++ b/ursaryd.c @@ -1,7 +1,7 @@ /* * The Ursary Control Panel * - * (c) 2014--2022 Martin Mares + * (c) 2014-2023 Martin Mares */ #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 ***/