From 9c4278f983c009f59195e0419718d5b75c70965e Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 24 Apr 2020 20:03:18 +0200 Subject: [PATCH] Removed switching of ports, revived switching of outputs Ports can be handled by PulseAudio with module-switch-on-port-available. --- ursaryd.c | 97 ++++++++++--------------------------------------------- 1 file changed, 17 insertions(+), 80 deletions(-) diff --git a/ursaryd.c b/ursaryd.c index 1666307..c128e50 100644 --- a/ursaryd.c +++ b/ursaryd.c @@ -29,8 +29,8 @@ * * rotary red button green button * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * 0 sink PCH mute use headphones - * 1 - - - + * 0 sink PCH mute switch to PCH + * 1 sink BT mute switch to BT * 2 - - - * 3 desk brightness - desk lights on * 4 MPD mute MPD play/pause @@ -43,6 +43,7 @@ */ #define PCH_SINK "alsa_output.pci-0000_00_1f.3.analog-stereo" +#define BT_SINK "bluez_sink.CC_98_8B_D0_8C_06.a2dp_sink" /*** Sink controls ***/ @@ -78,18 +79,6 @@ static void update_ring_from_sink(int ring, const char *sink_name) noct_set_button(ring, 0); } -static void update_button_from_port(int button, const char *sink_name, const char *port_name) -{ - struct pulse_sink *s = pulse_sink_by_name(sink_name); - if (!s) - { - noct_set_button(button, 0); - return; - } - - noct_set_button(button, !strcmp(s->active_port, port_name)); -} - static void update_sink_from_rotary(int delta, const char *sink_name) { struct pulse_sink *s = pulse_sink_by_name(sink_name); @@ -120,23 +109,6 @@ static void update_sink_mute_from_button(int on, const char *sink_name) pulse_sink_set_mute(s->idx, !s->mute); } -static void update_port_from_button(int on, const char *sink_name, const char *port1, const char *port2) -{ - if (!on) - return; - - struct pulse_sink *s = pulse_sink_by_name(sink_name); - if (!s) - return; - - const char *port = port1; - if (!strcmp(s->active_port, port1)) - port = port2; - - DBG("## Setting port of sink %s to %s", s->name, port); - pulse_sink_set_port(s->idx, port); -} - /*** Client controls ***/ struct client_map { @@ -293,8 +265,6 @@ static void update_group_from_button(int i, int on) } } -#if 0 // Not used at the moment - static int find_touched_client(void) { int touched = -1; @@ -309,12 +279,8 @@ static int find_touched_client(void) return touched; } -#endif - /*** Default sink controls ***/ -#if 0 // Not mapped to any button at the moment - static const char *get_client_sink(int i) { const char *sink = NULL; @@ -341,29 +307,20 @@ static void update_default_sink(void) else sink = pulse_default_sink_name ? : "?"; - if (!strcmp(sink, "ursarium")) + if (!strcmp(sink, PCH_SINK)) { noct_set_button(8, 1); noct_set_button(9, 0); - noct_set_button(10, 0); } - else if (!strcmp(sink, "catarium")) + else if (!strcmp(sink, BT_SINK)) { noct_set_button(8, 0); noct_set_button(9, 1); - noct_set_button(10, 0); - } - else if (!strcmp(sink, "compress")) - { - noct_set_button(8, 0); - noct_set_button(9, 0); - noct_set_button(10, 1); } else { noct_set_button(8, 0); noct_set_button(9, 0); - noct_set_button(10, 0); } } @@ -373,34 +330,19 @@ static void update_default_sink_from_button(int button, int on) return; int i = find_touched_client(); +#if 0 const char *sink; if (i >= 0) sink = get_client_sink(i); else sink = pulse_default_sink_name ? : "?"; +#endif const char *switch_to = NULL; if (button == 8) - { - if (!strcmp(sink, "ursarium")) - switch_to = "burrow"; - else - switch_to = "ursarium"; - } + switch_to = PCH_SINK; else if (button == 9) - { - if (!strcmp(sink, "catarium")) - switch_to = "burrow"; - else - switch_to = "catarium"; - } - else if (button == 10) - { - if (!strcmp(sink, "compress")) - switch_to = "burrow"; - else - switch_to = "compress"; - } + switch_to = BT_SINK; if (!switch_to) return; @@ -425,8 +367,6 @@ static void update_default_sink_from_button(int button, int on) } } -#endif - /*** MPD controls ***/ static bool mpd_flash_state; @@ -665,7 +605,7 @@ static void do_update(struct main_timer *t) if (!want_sleep) last_touch_time = main_get_now(); timestamp_t since_touch = last_touch_time ? main_get_now() - last_touch_time : 0; - timestamp_t sleep_in = 5000; + timestamp_t sleep_in = 30000; if (since_touch >= sleep_in) { DBG("UPDATE: Sleeping"); @@ -695,11 +635,9 @@ static void do_update(struct main_timer *t) // Everything normal update_ring_from_sink(0, PCH_SINK); - update_button_from_port(8, PCH_SINK, "analog-output-headphones"); + update_ring_from_sink(1, BT_SINK); update_groups(); -#if 0 update_default_sink(); -#endif update_mpd(); update_lights(); } @@ -737,6 +675,9 @@ void notify_rotary(int rotary, int delta) case 0: update_sink_from_rotary(delta, PCH_SINK); break; + case 1: + update_sink_from_rotary(delta, BT_SINK); + break; case 3: update_lights_from_rotary(0, delta); break; @@ -758,15 +699,13 @@ void notify_button(int button, int on) case 0: update_sink_mute_from_button(on, PCH_SINK); break; - case 8: - update_port_from_button(on, PCH_SINK, "analog-output-lineout", "analog-output-headphones"); + case 1: + update_sink_mute_from_button(on, BT_SINK); break; -#if 0 + case 8: case 9: - case 10: update_default_sink_from_button(button, on); break; -#endif case 11: update_lights_from_button(0, on); break; @@ -795,11 +734,9 @@ void notify_touch(int rotary UNUSED, int on UNUSED) if (!prepare_notify()) return; -#if 0 // Rotary touches switch meaning of LEDs, this is handled inside display updates if (rotary >= 4 && rotary < 8) schedule_update(); -#endif } /*** Main entry point ***/ -- 2.39.2