summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2005-04-06 11:12:22 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2005-04-06 11:12:22 +0000
commit3d2178148bbabac312ea01ad4d9cc6d86bcff75c (patch)
treebd222448c25549d124d81ecb468f7ad3ef89bb70 /apps
parent3b853c692e65b603c71655537288fc811b25214f (diff)
downloadrockbox-3d2178148bbabac312ea01ad4d9cc6d86bcff75c.tar.gz
rockbox-3d2178148bbabac312ea01ad4d9cc6d86bcff75c.tar.bz2
rockbox-3d2178148bbabac312ea01ad4d9cc6d86bcff75c.zip
Moved the car adapter mode handling to apps/, now every thread gets SYS_CHARGER_CONNECTED and SYS_CHARGER_DISCONNECTED events
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6255 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/main.c5
-rw-r--r--apps/misc.c66
-rw-r--r--apps/misc.h1
-rw-r--r--apps/settings.c2
-rw-r--r--apps/settings_menu.c2
-rw-r--r--apps/tree.c3
6 files changed, 73 insertions, 6 deletions
diff --git a/apps/main.c b/apps/main.c
index b5c6364080..af84a46984 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -58,7 +58,7 @@
#include "power.h"
#include "talk.h"
#include "plugin.h"
-
+#include "misc.h"
#if (CONFIG_HWCODEC == MASNONE)
#include "pcm_playback.h"
@@ -271,6 +271,9 @@ void init(void)
#if (CONFIG_HWCODEC == MASNONE)
pcm_init();
#endif
+#ifdef HAVE_CHARGING
+ car_adapter_mode_init();
+#endif
}
int main(void)
diff --git a/apps/misc.c b/apps/misc.c
index af1c417fd6..e7438d673e 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -31,6 +31,7 @@
#include "screens.h"
#include "talk.h"
#include "mpeg.h"
+#include "audio.h"
#include "mp3_playback.h"
#include "settings.h"
#include "ata.h"
@@ -289,6 +290,61 @@ bool clean_shutdown(void)
return false;
}
+#ifdef HAVE_CHARGING
+static bool waiting_to_resume_play = false;
+static long play_resume_tick;
+
+static void car_adapter_mode_processing(bool inserted)
+{
+ if (global_settings.car_adapter_mode)
+ {
+ if(inserted)
+ {
+ /*
+ * Just got plugged in, delay & resume if we were playing
+ */
+ if (audio_status() & AUDIO_STATUS_PAUSE)
+ {
+ /* delay resume a bit while the engine is cranking */
+ play_resume_tick = current_tick + HZ*5;
+ waiting_to_resume_play = true;
+ }
+ }
+ else
+ {
+ /*
+ * Just got unplugged, pause if playing
+ */
+ if ((audio_status() & AUDIO_STATUS_PLAY) &&
+ !(audio_status() & AUDIO_STATUS_PAUSE))
+ {
+ audio_pause();
+ }
+ }
+ }
+}
+
+static void car_adapter_tick(void)
+{
+ if (waiting_to_resume_play)
+ {
+ if (TIME_AFTER(current_tick, play_resume_tick))
+ {
+ if (audio_status() & AUDIO_STATUS_PAUSE)
+ {
+ audio_resume();
+ }
+ waiting_to_resume_play = false;
+ }
+ }
+}
+
+void car_adapter_mode_init(void)
+{
+ tick_add_task(car_adapter_tick);
+}
+#endif
+
long default_event_handler_ex(long event, void (*callback)(void *), void *parameter)
{
switch(event)
@@ -307,6 +363,15 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame
if (!clean_shutdown())
return SYS_POWEROFF;
break;
+#ifdef HAVE_CHARGING
+ case SYS_CHARGER_CONNECTED:
+ car_adapter_mode_processing(true);
+ return SYS_CHARGER_CONNECTED;
+
+ case SYS_CHARGER_DISCONNECTED:
+ car_adapter_mode_processing(false);
+ return SYS_CHARGER_DISCONNECTED;
+#endif
}
return 0;
}
@@ -315,4 +380,3 @@ long default_event_handler(long event)
{
return default_event_handler_ex(event, NULL, NULL);
}
-
diff --git a/apps/misc.h b/apps/misc.h
index 956a8fcd5e..105f65732a 100644
--- a/apps/misc.h
+++ b/apps/misc.h
@@ -44,5 +44,6 @@ bool settings_parseline(char* line, char** name, char** value);
bool clean_shutdown(void);
long default_event_handler_ex(long event, void (*callback)(void *), void *parameter);
long default_event_handler(long event);
+void car_adapter_mode_init(void);
#endif
diff --git a/apps/settings.c b/apps/settings.c
index 56dcd0af09..bbfdd54d93 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -825,8 +825,6 @@ void settings_apply(void)
lang_load(buf);
talk_init(); /* use voice of same language */
}
-
- set_car_adapter_mode(global_settings.car_adapter_mode);
}
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index 9590e15476..5af7470c7d 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -63,7 +63,7 @@ static bool car_adapter_mode(void)
&global_settings.car_adapter_mode,
STR(LANG_SET_BOOL_YES),
STR(LANG_SET_BOOL_NO),
- set_car_adapter_mode);
+ NULL);
}
#endif
diff --git a/apps/tree.c b/apps/tree.c
index 139043ab04..c9f5847ab8 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -484,7 +484,8 @@ static bool ask_resume(bool ask_once)
#endif
/* Handle sys events, ignore button releases */
default:
- if(default_event_handler(button) || !(button & BUTTON_REL))
+ if(default_event_handler(button) == SYS_USB_CONNECTED ||
+ (!(button & SYS_EVENT) && !(button & BUTTON_REL)))
stop = true;
break;
}