View Single Post
Old 03-10-2010, 02:26 PM   #29
A4-
Connoisseur
A4- can extract oil from cheeseA4- can extract oil from cheeseA4- can extract oil from cheeseA4- can extract oil from cheeseA4- can extract oil from cheeseA4- can extract oil from cheeseA4- can extract oil from cheeseA4- can extract oil from cheeseA4- can extract oil from cheese
 
A4-'s Avatar
 
Posts: 84
Karma: 1110
Join Date: Aug 2009
Location: Netherlands
Device: iRex iLiad v2
Instant buttons

I've been playing with the sources a few months ago and the way I changed it was as follows (code below):
For buttons that don't have a (useful) long press it instantly sends the key (instead of waiting for key_up)
So now I can hold the flipbar for ages and the nextpage changes as fast as the screen & software are able too.

The only thing I notice is that sometimes the flipbar wont register at all. I suspect that that's when it used to jump 5 pages instead of 1. Since this is probably related with the kb-driver I'm not gonna try to fix that since it doesn't bother me.

The function of button.c (contentlister) which I changed:
Code:
static void *buttonStateMachine(void *arg)
{
    int button;
    struct timespec times;
    struct timeval timev;

    enum
    {
        buttonReleased,
        buttonPressed
    } state = buttonReleased;

    button = -1;
    while (1)
    {
        CL_LOGPRINTF("smthread: start of loop, state %d", state);
        switch (state)
        {
            case buttonReleased:
                pthread_mutex_lock(&buttonCondMutex);
                CL_LOGPRINTF("smthread: waiting for press");
                pthread_cond_wait(&buttonCond, &buttonCondMutex);
                if (protectedButton == 0xFF)
                {
                    CL_LOGPRINTF("smthread: release in released");
                    pthread_mutex_unlock(&buttonCondMutex);
                }
                else
                {
                    CL_LOGPRINTF("smthread: press in released");
                    button = protectedButton;
                    state = buttonPressed;
                    pthread_mutex_unlock(&buttonCondMutex);
                }
                break;

            case buttonPressed:
                pthread_mutex_lock(&buttonCondMutex);
                // get current time, and add BUTTON_LONG_PRESS_TIMEOUT ms
                // a timeval -> timespec conversion is needed (nanosec to microsec)
// -------------  Instant Buttons ----------------
            if ( (button != MODE) && (button != OVERVIEW) && (button != CONNECT) && (button != POWER) )
		      {
				  pthread_mutex_unlock(&buttonCondMutex);
			         CL_LOGPRINTF("smthread: short flipbar button handler");
				  button_handler(button, arg);        // short flipbar
				  button = -1;  
				  state = buttonReleased;
			}
			else
			{
// -------------  Regular buttons -----------------
                gettimeofday(&timev, NULL);
                times.tv_sec = timev.tv_sec + g_timoutValue.tv_sec;
                times.tv_nsec = (timev.tv_usec * 1000) + g_timoutValue.tv_nsec;
                if (times.tv_nsec >= 1000000000)
                {
                    times.tv_nsec -= 1000000000;
                    times.tv_sec += 1;
                }
                CL_LOGPRINTF("smthread: timed waiting for release");
                if (pthread_cond_timedwait(&buttonCond, &buttonCondMutex, &times) == ETIMEDOUT)
                {
                    CL_LOGPRINTF("smthread: timeout in pressed");
                    pthread_mutex_unlock(&buttonCondMutex);
                    if (button >= 0 && button < NUM_BUTTONS)
                    {
                        CL_LOGPRINTF("smthread: long button handler");
                        button_handler(button | BUTTON_LONG_PRESS, arg);        // long
                    }
                    button = -1;
                    state = buttonReleased;
                }
                else
                {
                    if (protectedButton == 0xFF)
                    {
                        CL_LOGPRINTF("smthread: release in pressed");
                        state = buttonReleased;
                        pthread_mutex_unlock(&buttonCondMutex);
                        if (button >= 0 && button < NUM_BUTTONS)
                        {
                            CL_LOGPRINTF("smthread: short button handler");
                            button_handler(button, arg);        // short
                        }
                        button = -1;
                    }
                    else
                    {
                        CL_LOGPRINTF("smthread: press in pressed");
                        button = protectedButton;
                        pthread_mutex_unlock(&buttonCondMutex);
                    }
                }
             } 			// from instant flipbar
               break;
        }
    }
    pthread_exit(NULL);
}
I've also reversed the "settings button" so that a short press will get me to the recent documents and a long one to the settings.
A4- is offline   Reply With Quote