Commit 98a4c546 authored by phdeswer's avatar phdeswer

add disconnect debounce

Signed-off-by: phdeswer's avatarPhilippe De Swert <philippedeswert@gmail.com>
parent 6e1d2043
...@@ -172,12 +172,16 @@ static void udev_parse(struct udev_device *dev) ...@@ -172,12 +172,16 @@ static void udev_parse(struct udev_device *dev)
if(get_trigger_value()) if(get_trigger_value())
{ {
if(!strcmp(tmp, get_trigger_value())) if(!strcmp(tmp, get_trigger_value()))
{
set_usb_mode(get_trigger_mode()); set_usb_mode(get_trigger_mode());
}
else else
return; return;
} }
else else
{
set_usb_mode(get_trigger_mode()); set_usb_mode(get_trigger_mode());
}
return; return;
} }
} }
...@@ -54,6 +54,7 @@ extern int log_type; ...@@ -54,6 +54,7 @@ extern int log_type;
gboolean run_as_daemon = FALSE; gboolean run_as_daemon = FALSE;
gboolean runlevel_ignore = FALSE; gboolean runlevel_ignore = FALSE;
struct usb_mode current_mode; struct usb_mode current_mode;
guint debounce = 0;
#ifdef NOKIA #ifdef NOKIA
gboolean special_mode = FALSE; gboolean special_mode = FALSE;
guint timeout_source = 0; guint timeout_source = 0;
...@@ -63,6 +64,7 @@ static GList *modelist; ...@@ -63,6 +64,7 @@ static GList *modelist;
#endif /* APP_SYNC */ #endif /* APP_SYNC */
/* static helper functions */ /* static helper functions */
static gboolean set_disconnected(gpointer data);
static void usb_moded_init(void); static void usb_moded_init(void);
static gboolean charging_fallback(gpointer data); static gboolean charging_fallback(gpointer data);
static void usage(void); static void usage(void);
...@@ -98,6 +100,12 @@ void set_usb_connected(gboolean connected) ...@@ -98,6 +100,12 @@ void set_usb_connected(gboolean connected)
*/ */
if(current_mode.connected) if(current_mode.connected)
return; return;
if(debounce)
{
g_source_remove(debounce);
debounce = 0;
}
#ifdef NOKIA #ifdef NOKIA
if(timeout_source) if(timeout_source)
{ {
...@@ -109,7 +117,14 @@ void set_usb_connected(gboolean connected) ...@@ -109,7 +117,14 @@ void set_usb_connected(gboolean connected)
set_usb_connected_state(); set_usb_connected_state();
} }
else else
{ if(!debounce)
debounce = g_timeout_add_seconds(2, set_disconnected, NULL);
}
static gboolean set_disconnected(gpointer data)
{
current_mode.connected = FALSE; current_mode.connected = FALSE;
/* signal usb disconnected */ /* signal usb disconnected */
log_debug("usb disconnected\n"); log_debug("usb disconnected\n");
...@@ -124,7 +139,7 @@ void set_usb_connected(gboolean connected) ...@@ -124,7 +139,7 @@ void set_usb_connected(gboolean connected)
#endif /* NOKIA */ #endif /* NOKIA */
set_usb_mode(MODE_UNDEFINED); set_usb_mode(MODE_UNDEFINED);
} return FALSE;
} }
/** set the chosen usb state /** set the chosen usb state
...@@ -238,8 +253,6 @@ void set_usb_mode(const char *mode) ...@@ -238,8 +253,6 @@ void set_usb_mode(const char *mode)
struct mode_list_elem *data = iter->data; struct mode_list_elem *data = iter->data;
if(!strcmp(mode, data->mode_name)) if(!strcmp(mode, data->mode_name))
{ {
/* set state to connected as we might get a disconnect in between */
current_mode.connected = TRUE;
check_module_state(data->mode_module); check_module_state(data->mode_module);
set_usb_module(data->mode_module); set_usb_module(data->mode_module);
ret = usb_moded_load_module(data->mode_module); ret = usb_moded_load_module(data->mode_module);
...@@ -333,6 +346,15 @@ gboolean get_usb_connection_state(void) ...@@ -333,6 +346,15 @@ gboolean get_usb_connection_state(void)
return current_mode.connected; return current_mode.connected;
} }
/** set connection status for some corner cases
*
* @param: connection status that needs to be set. Connected (TRUE)
*
*/
void set_usb_connection_state(gboolean state)
{
current_mode.connected = state;
}
/*================ Static functions ===================================== */ /*================ Static functions ===================================== */
......
...@@ -59,5 +59,6 @@ const char * get_usb_mode(void); ...@@ -59,5 +59,6 @@ const char * get_usb_mode(void);
void set_usb_module(const char *module); void set_usb_module(const char *module);
const char * get_usb_module(void); const char * get_usb_module(void);
gboolean get_usb_connection_state(void); gboolean get_usb_connection_state(void);
void set_usb_connection_state(gboolean state);
#endif /* USB_MODED_H */ #endif /* USB_MODED_H */
...@@ -12,4 +12,3 @@ mount = /home/user/MyDocs ...@@ -12,4 +12,3 @@ mount = /home/user/MyDocs
[cdrom] [cdrom]
path = path =
timeout = timeout =
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment