1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Linus Nielsen Feltzing 2005-04-06 11:12:22 +00:00
parent 3b853c692e
commit 3d2178148b
8 changed files with 77 additions and 60 deletions

View file

@ -58,7 +58,7 @@
#include "power.h" #include "power.h"
#include "talk.h" #include "talk.h"
#include "plugin.h" #include "plugin.h"
#include "misc.h"
#if (CONFIG_HWCODEC == MASNONE) #if (CONFIG_HWCODEC == MASNONE)
#include "pcm_playback.h" #include "pcm_playback.h"
@ -271,6 +271,9 @@ void init(void)
#if (CONFIG_HWCODEC == MASNONE) #if (CONFIG_HWCODEC == MASNONE)
pcm_init(); pcm_init();
#endif #endif
#ifdef HAVE_CHARGING
car_adapter_mode_init();
#endif
} }
int main(void) int main(void)

View file

@ -31,6 +31,7 @@
#include "screens.h" #include "screens.h"
#include "talk.h" #include "talk.h"
#include "mpeg.h" #include "mpeg.h"
#include "audio.h"
#include "mp3_playback.h" #include "mp3_playback.h"
#include "settings.h" #include "settings.h"
#include "ata.h" #include "ata.h"
@ -289,6 +290,61 @@ bool clean_shutdown(void)
return false; 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) long default_event_handler_ex(long event, void (*callback)(void *), void *parameter)
{ {
switch(event) switch(event)
@ -307,6 +363,15 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame
if (!clean_shutdown()) if (!clean_shutdown())
return SYS_POWEROFF; return SYS_POWEROFF;
break; 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; return 0;
} }
@ -315,4 +380,3 @@ long default_event_handler(long event)
{ {
return default_event_handler_ex(event, NULL, NULL); return default_event_handler_ex(event, NULL, NULL);
} }

View file

@ -44,5 +44,6 @@ bool settings_parseline(char* line, char** name, char** value);
bool clean_shutdown(void); bool clean_shutdown(void);
long default_event_handler_ex(long event, void (*callback)(void *), void *parameter); long default_event_handler_ex(long event, void (*callback)(void *), void *parameter);
long default_event_handler(long event); long default_event_handler(long event);
void car_adapter_mode_init(void);
#endif #endif

View file

@ -825,8 +825,6 @@ void settings_apply(void)
lang_load(buf); lang_load(buf);
talk_init(); /* use voice of same language */ talk_init(); /* use voice of same language */
} }
set_car_adapter_mode(global_settings.car_adapter_mode);
} }

View file

@ -63,7 +63,7 @@ static bool car_adapter_mode(void)
&global_settings.car_adapter_mode, &global_settings.car_adapter_mode,
STR(LANG_SET_BOOL_YES), STR(LANG_SET_BOOL_YES),
STR(LANG_SET_BOOL_NO), STR(LANG_SET_BOOL_NO),
set_car_adapter_mode); NULL);
} }
#endif #endif

View file

@ -484,7 +484,8 @@ static bool ask_resume(bool ask_once)
#endif #endif
/* Handle sys events, ignore button releases */ /* Handle sys events, ignore button releases */
default: 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; stop = true;
break; break;
} }

View file

@ -43,6 +43,8 @@
#define SYS_MMC_EXTRACTED ((SYS_EVENT | ((long)7 << 27))) #define SYS_MMC_EXTRACTED ((SYS_EVENT | ((long)7 << 27)))
#define SYS_POWEROFF ((SYS_EVENT | ((long)8 << 27))) #define SYS_POWEROFF ((SYS_EVENT | ((long)8 << 27)))
#define SYS_FS_CHANGED ((SYS_EVENT | ((long)9 << 27))) #define SYS_FS_CHANGED ((SYS_EVENT | ((long)9 << 27)))
#define SYS_CHARGER_CONNECTED ((SYS_EVENT | ((long)10 << 27)))
#define SYS_CHARGER_DISCONNECTED ((SYS_EVENT | ((long)11 << 27)))
struct event struct event
{ {

View file

@ -89,11 +89,6 @@ void set_battery_capacity(int capacity)
(void)capacity; (void)capacity;
} }
void set_car_adapter_mode(bool setting)
{
(void)setting;
}
void reset_poweroff_timer(void) void reset_poweroff_timer(void)
{ {
} }
@ -150,9 +145,6 @@ static enum {
CHARGER_PLUGGED, /* transient state */ CHARGER_PLUGGED, /* transient state */
CHARGER CHARGER
} charger_input_state; } charger_input_state;
static bool waiting_to_resume_play = false;
static long play_resume_time;
#endif #endif
#ifdef HAVE_CHARGE_CTRL #ifdef HAVE_CHARGE_CTRL
@ -192,8 +184,6 @@ static int battery_type = 0;
/* Power history: power_history[0] is the newest sample */ /* Power history: power_history[0] is the newest sample */
unsigned short power_history[POWER_HISTORY_LEN]; unsigned short power_history[POWER_HISTORY_LEN];
static bool car_adapter_mode_enabled = false;
static char power_stack[DEFAULT_STACK_SIZE + DEBUG_STACK]; static char power_stack[DEFAULT_STACK_SIZE + DEBUG_STACK];
static const char power_thread_name[] = "power"; static const char power_thread_name[] = "power";
@ -401,47 +391,6 @@ static void handle_auto_poweroff(void)
} }
} }
void set_car_adapter_mode(bool setting)
{
car_adapter_mode_enabled = setting;
}
#ifdef HAVE_CHARGING
static void car_adapter_mode_processing(void)
{
if (car_adapter_mode_enabled) {
if (waiting_to_resume_play) {
if (TIME_AFTER(current_tick, play_resume_time)) {
if (audio_status() & AUDIO_STATUS_PAUSE) {
audio_resume();
}
waiting_to_resume_play = false;
}
} else {
if (charger_input_state == CHARGER_UNPLUGGED) {
/*
* Just got unplugged, pause if playing
*/
if ((audio_status() & AUDIO_STATUS_PLAY) &&
!(audio_status() & AUDIO_STATUS_PAUSE)) {
audio_pause();
}
} else if(charger_input_state == CHARGER_PLUGGED) {
/*
* 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_time = current_tick + HZ*5;
waiting_to_resume_play = true;
}
}
}
}
}
#endif
/* /*
* Estimate how much current we are drawing just to run. * Estimate how much current we are drawing just to run.
*/ */
@ -507,6 +456,7 @@ static void power_thread_sleep(int ticks)
charger_input_state = CHARGER_PLUGGED; charger_input_state = CHARGER_PLUGGED;
return; return;
case CHARGER_PLUGGED: case CHARGER_PLUGGED:
queue_broadcast(SYS_CHARGER_CONNECTED, NULL);
charger_input_state = CHARGER; charger_input_state = CHARGER;
break; break;
case CHARGER: case CHARGER:
@ -517,6 +467,7 @@ static void power_thread_sleep(int ticks)
case NO_CHARGER: case NO_CHARGER:
break; break;
case CHARGER_UNPLUGGED: case CHARGER_UNPLUGGED:
queue_broadcast(SYS_CHARGER_DISCONNECTED, NULL);
charger_input_state = NO_CHARGER; charger_input_state = NO_CHARGER;
break; break;
case CHARGER_PLUGGED: case CHARGER_PLUGGED:
@ -531,9 +482,6 @@ static void power_thread_sleep(int ticks)
sleep(small_ticks); sleep(small_ticks);
ticks -= small_ticks; ticks -= small_ticks;
#ifdef HAVE_CHARGING
car_adapter_mode_processing();
#endif
#ifdef HAVE_ALARM_MOD #ifdef HAVE_ALARM_MOD
power_thread_rtc_process(); power_thread_rtc_process();
#endif #endif