Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add disconnect debounce
Signed-off-by: Philippe De Swert <philippedeswert@gmail.com>
  • Loading branch information
philippedeswert committed May 17, 2011
1 parent 6e1d204 commit 98a4c54
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/usb_moded-trigger.c
Expand Up @@ -172,12 +172,16 @@ static void udev_parse(struct udev_device *dev)
if(get_trigger_value())
{
if(!strcmp(tmp, get_trigger_value()))
{
set_usb_mode(get_trigger_mode());
}
else
return;
}
else
{
set_usb_mode(get_trigger_mode());
}
return;
}
}
30 changes: 26 additions & 4 deletions src/usb_moded.c
Expand Up @@ -54,6 +54,7 @@ extern int log_type;
gboolean run_as_daemon = FALSE;
gboolean runlevel_ignore = FALSE;
struct usb_mode current_mode;
guint debounce = 0;
#ifdef NOKIA
gboolean special_mode = FALSE;
guint timeout_source = 0;
Expand All @@ -63,6 +64,7 @@ static GList *modelist;
#endif /* APP_SYNC */

/* static helper functions */
static gboolean set_disconnected(gpointer data);
static void usb_moded_init(void);
static gboolean charging_fallback(gpointer data);
static void usage(void);
Expand Down Expand Up @@ -98,6 +100,12 @@ void set_usb_connected(gboolean connected)
*/
if(current_mode.connected)
return;

if(debounce)
{
g_source_remove(debounce);
debounce = 0;
}
#ifdef NOKIA
if(timeout_source)
{
Expand All @@ -109,7 +117,14 @@ void set_usb_connected(gboolean connected)
set_usb_connected_state();
}
else
{
if(!debounce)
debounce = g_timeout_add_seconds(2, set_disconnected, NULL);


}

static gboolean set_disconnected(gpointer data)
{
current_mode.connected = FALSE;
/* signal usb disconnected */
log_debug("usb disconnected\n");
Expand All @@ -124,7 +139,7 @@ void set_usb_connected(gboolean connected)
#endif /* NOKIA */

set_usb_mode(MODE_UNDEFINED);
}
return FALSE;
}

/** set the chosen usb state
Expand Down Expand Up @@ -238,8 +253,6 @@ void set_usb_mode(const char *mode)
struct mode_list_elem *data = iter->data;
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);
set_usb_module(data->mode_module);
ret = usb_moded_load_module(data->mode_module);
Expand Down Expand Up @@ -333,6 +346,15 @@ gboolean get_usb_connection_state(void)
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 ===================================== */

Expand Down
1 change: 1 addition & 0 deletions src/usb_moded.h
Expand Up @@ -59,5 +59,6 @@ const char * get_usb_mode(void);
void set_usb_module(const char *module);
const char * get_usb_module(void);
gboolean get_usb_connection_state(void);
void set_usb_connection_state(gboolean state);

#endif /* USB_MODED_H */
1 change: 0 additions & 1 deletion usb-moded.ini
Expand Up @@ -12,4 +12,3 @@ mount = /home/user/MyDocs
[cdrom]
path =
timeout =

0 comments on commit 98a4c54

Please sign in to comment.