Rockbox Technical Forums

Support and General Use => User Interface and Voice => Topic started by: adw on March 15, 2012, 11:25:46 AM

Title: Sansa Clip +: hold (key lock) function for recording screen
Post by: adw on March 15, 2012, 11:25:46 AM
I'm trying to add a "key lock" function for my Sansa Clip +. So far I have added:

apps/keymaps/keymap-clip.c

/** Recording Screen **/
static const struct button_mapping button_context_recscreen[]  = {
...
#ifndef HAS_BUTTON_HOLD /* Clip+ */
    { ACTION_STD_KEYLOCK,        BUTTON_HOME|BUTTON_SELECT,     BUTTON_NONE },
#endif /* HAS_BUTTON_HOLD */
...

apps/recorder/recording.c

...
static bool keys_locked = false;
...
        if (button == ACTION_STD_KEYLOCK)
        {
            if (keys_locked)
            {
                keys_locked = false;
                splash(HZ/2, str(LANG_KEYLOCK_OFF));
            }
            else
            {
                keys_locked = true;
                splash(HZ/2, str(LANG_KEYLOCK_ON));
            }
        }

        if (keys_locked)
        {
            splash(HZ/2, str(LANG_KEYLOCK_ON));
        }
        else
        {
            switch(button)
            ...
            } /*switch(button)*/
        } /*if(keys_locked)*/

This is doing the job for most keys, but the UP and DOWN keys that change the item during recording (Voulme / Gain / Filename) are not locked, and I can't figure out where these keys are handled. Can anyone give me a hint please?

Title: Re: Sansa Clip +: hold (key lock) function for recording screen
Post by: JdGordon on March 15, 2012, 07:35:05 PM
above the code you're fiddling with will be a call to something like gui_synclist_do_button(), check the lock before entering that.
Title: Re: Sansa Clip +: hold (key lock) function for recording screen
Post by: adw on March 16, 2012, 08:11:24 AM
Thank you, JdGordon, that was too obvious for me to see it...

I have also udated splash messages and screen blanking.

My complete changes are shown below. If anyone cares to make a patch out of it (with proper HAS_BUTTON_HOLD everywhere and support for all players), feel free to use my code as a starting point.


apps/keymaps/keymap-clip.c

/** Recording Screen **/
static const struct button_mapping button_context_recscreen[]  = {
...
Code: [Select]
#ifndef HAS_BUTTON_HOLD /* Clip+ */
    { ACTION_STD_KEYLOCK,        BUTTON_HOME|BUTTON_SELECT,     BUTTON_NONE },
#endif /* HAS_BUTTON_HOLD */
...

apps/recorder/recording.c

...
Code: [Select]
static bool keys_locked = false;...
Code: [Select]
        if (button == ACTION_STD_KEYLOCK)
        {
            if (keys_locked)
            {
                keys_locked = false;
                splash(HZ/2, str(LANG_KEYLOCK_OFF));
                screen_update = NB_SCREENS;
                update_list = true;
                send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); /* force a redraw */
            }
            else
            {
                keys_locked = true;
                screen_update = 0;
                update_list = false;
                FOR_NB_SCREENS(i)
                {
                    screens[i].clear_display();
                }
                splash(HZ/2, str(LANG_KEYLOCK_ON));
                FOR_NB_SCREENS(i)
                {
                    screens[i].clear_display();
                }
                button_clear_queue();
            }
        }

        if (keys_locked)
        {
            if (button != BUTTON_NONE)
            {
                splash(HZ/2, str(LANG_KEYLOCK_ON));
                FOR_NB_SCREENS(i)
                {
                    screens[i].clear_display();
                }
            }
        }
        else
        {
           /* let list handle the button */
            gui_synclist_do_button(&lists, &button, LIST_WRAP_UNLESS_HELD);

            switch(button)
            ...
            } /*switch(button)*/
Code: [Select]
       } /*if(keys_locked)*/