From d24edc605b9b52d3610efbb9cf691c437ea00746 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Thu, 3 Jan 2019 20:46:54 -0500 Subject: Add HAVE_LINEOUT_DETECTION and associated logic This allows targets to automatically switch audio settings when the line out is plugged/unplugged. Only hooked up on the xDuoo X3, but there are other potential users. Change-Id: Ic46a329bc955cca2e2ad0335ca16295eab24ad59 --- apps/misc.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'apps/misc.c') diff --git a/apps/misc.c b/apps/misc.c index 90865859cf..2106d11164 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -157,11 +157,11 @@ char *output_dyn_value(char *buf, value_abs /= scale; unit_no++; } - + value = (value < 0) ? -value_abs : value_abs; /* preserve sign */ fraction = (fraction * 1000 / scale) / 10; - if (value_abs >= 100 || fraction >= 100 || !unit_no) + if (value_abs >= 100 || fraction >= 100 || !unit_no) tbuf[0] = '\0'; else if (value_abs >= 10) snprintf(tbuf, sizeof(tbuf), "%01u", fraction / 10); @@ -521,7 +521,7 @@ void car_adapter_mode_init(void) #endif #ifdef HAVE_HEADPHONE_DETECTION -static void unplug_change(bool inserted) +static void hp_unplug_change(bool inserted) { static bool headphone_caused_pause = false; @@ -553,6 +553,18 @@ static void unplug_change(bool inserted) } #endif +#ifdef HAVE_LINEOUT_DETECTION +static void lo_unplug_change(bool inserted) +{ +#ifdef HAVE_LINEOUT_POWEROFF + lineout_set(inserted); +#else + (void)inserted; + audiohw_set_lineout_volume(0,0); +#endif +} +#endif + long default_event_handler_ex(long event, void (*callback)(void *), void *parameter) { #if CONFIG_PLATFORM & (PLATFORM_ANDROID|PLATFORM_MAEMO) @@ -632,13 +644,22 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame #endif #ifdef HAVE_HEADPHONE_DETECTION case SYS_PHONE_PLUGGED: - unplug_change(true); + hp_unplug_change(true); return SYS_PHONE_PLUGGED; case SYS_PHONE_UNPLUGGED: - unplug_change(false); + hp_unplug_change(false); return SYS_PHONE_UNPLUGGED; #endif +#ifdef HAVE_LINEOUT_DETECTION + case SYS_LINEOUT_PLUGGED: + lo_unplug_change(true); + return SYS_LINEOUT_PLUGGED; + + case SYS_LINEOUT_UNPLUGGED: + lo_unplug_change(false); + return SYS_LINEOUT_UNPLUGGED; +#endif #if CONFIG_PLATFORM & (PLATFORM_ANDROID|PLATFORM_MAEMO) /* stop playback if we receive a call */ case SYS_CALL_INCOMING: -- cgit v1.2.3