/*** Interface to PulseAudio ***/
static pa_context *pulse_ctx;
+static struct main_timer pulse_connect_timer;
static void pulse_dump(void);
#define HASH_NODE struct pulse_sink_input
#define HASH_PREFIX(x) pulse_sink_input_##x
#define HASH_KEY_ATOMIC idx
-// #define HASH_WANT_CLEANUP
+#define HASH_WANT_CLEANUP
#define HASH_WANT_LOOKUP
#define HASH_WANT_REMOVE
#define HASH_ZERO_FILL
#define HASH_NODE struct pulse_sink
#define HASH_PREFIX(x) pulse_sink_##x
#define HASH_KEY_ATOMIC idx
-// #define HASH_WANT_CLEANUP
+#define HASH_WANT_CLEANUP
#define HASH_WANT_LOOKUP
#define HASH_WANT_REMOVE
#define HASH_ZERO_FILL
#define HASH_NODE struct pulse_client
#define HASH_PREFIX(x) pulse_client_##x
#define HASH_KEY_ATOMIC idx
-// #define HASH_WANT_CLEANUP
+#define HASH_WANT_CLEANUP
#define HASH_WANT_LOOKUP
#define HASH_WANT_REMOVE
#define HASH_ZERO_FILL
schedule_update();
}
+static void pulse_shutdown(void)
+{
+ DBG("Pulse: Shutting down");
+ pulse_client_cleanup();
+ pulse_sink_cleanup();
+ pulse_sink_input_cleanup();
+}
+
static void pulse_subscribe_done_cb(pa_context *ctx, int success, void *userdata)
{
pulse_op_done(userdata);
{
PULSE_STATE(PS_OFFLINE);
pulse_op_cancel_all();
- // FIXME: Reset all data structures
+ pulse_shutdown();
+ schedule_update();
}
+ if (state == PA_CONTEXT_FAILED && !timer_is_active(&pulse_connect_timer))
+ timer_add_rel(&pulse_connect_timer, 2000);
}
}
HASH_END_FOR;
}
-static void pulse_init(void)
+static void pulse_connect(struct main_timer *t)
{
- pmain_init();
+ DBG("Pulse: Connecting");
+ timer_del(t);
+
clist_init(&pulse_op_list);
pulse_client_init();
pulse_sink_init();
pulse_sink_input_init();
+ if (pulse_ctx)
+ pa_context_unref(pulse_ctx);
pulse_ctx = pa_context_new(&pmain_api, "ursaryd");
+
pa_context_set_state_callback(pulse_ctx, pulse_state_cb, NULL);
pa_context_connect(pulse_ctx, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL);
}
+static void pulse_init(void)
+{
+ pmain_init();
+
+ pulse_connect_timer.handler = pulse_connect;
+ timer_add_rel(&pulse_connect_timer, 0);
+}
+
/*** High-level logic ***/
static struct main_timer update_timer;
static void do_update(struct main_timer *t)
{
timer_del(t);
+ if (!noct_is_ready())
+ {
+ DBG("## UPDATE: Nocturn is not ready");
+ return;
+ }
+
+ static bool dead;
if (pulse_state != PS_ONLINE)
{
DBG("## UPDATE: Pulse is not online");
+ for (int i=0; i<=8; i++)
+ noct_set_ring(i, RING_MODE_LEFT, 0);
+ for (int i=0; i<8; i++)
+ {
+ noct_set_button(i, 1);
+ noct_set_button(i+8, 0);
+ }
+ dead = 1;
return;
}
- if (!noct_is_ready())
+ if (dead)
{
- DBG("## UPDATE: Nocturn is not ready");
- return;
+ DBG("## UPDATE: Waking up from the dead");
+ for (int i=0; i<=8; i++)
+ noct_set_ring(i, RING_MODE_LEFT, 0);
+ for (int i=0; i<16; i++)
+ noct_set_button(i, 0);
+ dead = 0;
}
DBG("## UPDATE");
{
if (pulse_state != PS_ONLINE)
{
- DBG("## NOTIFY: Pulse is not inline");
+ DBG("## NOTIFY: Pulse is not online");
return;
}
{
if (pulse_state != PS_ONLINE)
{
- DBG("## NOTIFY: Pulse is not inline");
+ DBG("## NOTIFY: Pulse is not online");
return;
}