Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问一下按键事件回调函数和用户注册时的ID是相反的是什么原因,我有4个按键,注册时是按0、1、2、3分配的ID,但是在事件回调中是相反的顺序,比如说我注册的时候ID是0,但是在事件回调函数里面打印的按键ID是3 #26

Open
14779771343 opened this issue Jun 17, 2022 · 2 comments

Comments

@14779771343
Copy link

No description provided.

@14779771343
Copy link
Author

已经发现按键ID是相反的原因是在按键事件处理函数中,头结点应该是在寄存器g_btn_status_reg的高位,在程序中是最低位。把“ i = 0”改成“ i = button_cnt - 1”,以及“ i ++”改成“i--”
`static void flex_button_process(void)
{
uint8_t i;
flex_button_t* target;

for (target = btn_head, i = button_cnt - 1; target != NULL; target = target->next, i --)
{
    if (target->status > FLEX_BTN_STAGE_DEFAULT)
    {
        target->scan_cnt ++;
        if (target->scan_cnt >= ((1 << (sizeof(target->scan_cnt) * 8)) - 1))
        {
            target->scan_cnt = target->long_hold_start_tick;
        }
    }

    switch (target->status)
    {
    case FLEX_BTN_STAGE_DEFAULT: /* stage: default(button up) */
        if (BTN_IS_PRESSED(i)) /* is pressed */
        {
            target->scan_cnt = 0;
            target->click_cnt = 0;

            EVENT_SET_AND_EXEC_CB(target, FLEX_BTN_PRESS_DOWN);

            /* swtich to button down stage */
            target->status = FLEX_BTN_STAGE_DOWN;
        }
        else
        {
            target->event = FLEX_BTN_PRESS_NONE;
        }
        break;

    case FLEX_BTN_STAGE_DOWN: /* stage: button down */
        if (BTN_IS_PRESSED(i)) /* is pressed */
        {
            if (target->click_cnt > 0) /* multiple click */
            {
                if (target->scan_cnt > target->max_multiple_clicks_interval)
                {
                    EVENT_SET_AND_EXEC_CB(target, 
                        target->click_cnt < FLEX_BTN_PRESS_REPEAT_CLICK ? 
                            target->click_cnt :
                            FLEX_BTN_PRESS_REPEAT_CLICK);

                    /* swtich to button down stage */
                    target->status = FLEX_BTN_STAGE_DOWN;
                    target->scan_cnt = 0;
                    target->click_cnt = 0;
                }
            }
            else if (target->scan_cnt >= target->long_hold_start_tick)
            {
                if (target->event != FLEX_BTN_PRESS_LONG_HOLD)
                {
                    EVENT_SET_AND_EXEC_CB(target, FLEX_BTN_PRESS_LONG_HOLD);
                }
            }
            else if (target->scan_cnt >= target->long_press_start_tick)
            {
                if (target->event != FLEX_BTN_PRESS_LONG_START)
                {
                    EVENT_SET_AND_EXEC_CB(target, FLEX_BTN_PRESS_LONG_START);
                }
            }
            else if (target->scan_cnt >= target->short_press_start_tick)
            {
                if (target->event != FLEX_BTN_PRESS_SHORT_START)
                {
                    EVENT_SET_AND_EXEC_CB(target, FLEX_BTN_PRESS_SHORT_START);
                }
            }
        }
        else /* button up */
        {
            if (target->scan_cnt >= target->long_hold_start_tick)
            {
                EVENT_SET_AND_EXEC_CB(target, FLEX_BTN_PRESS_LONG_HOLD_UP);
                target->status = FLEX_BTN_STAGE_DEFAULT;
            }
            else if (target->scan_cnt >= target->long_press_start_tick)
            {
                EVENT_SET_AND_EXEC_CB(target, FLEX_BTN_PRESS_LONG_UP);
                target->status = FLEX_BTN_STAGE_DEFAULT;
            }
            else if (target->scan_cnt >= target->short_press_start_tick)
            {
                EVENT_SET_AND_EXEC_CB(target, FLEX_BTN_PRESS_SHORT_UP);
                target->status = FLEX_BTN_STAGE_DEFAULT;
            }
            else
            {
                /* swtich to multiple click stage */
                target->status = FLEX_BTN_STAGE_MULTIPLE_CLICK;
                target->click_cnt ++;
            }
        }
        break;

    case FLEX_BTN_STAGE_MULTIPLE_CLICK: /* stage: multiple click */
        if (BTN_IS_PRESSED(i)) /* is pressed */
        {
            /* swtich to button down stage */
            target->status = FLEX_BTN_STAGE_DOWN;
            target->scan_cnt = 0;
        }
        else
        {
            if (target->scan_cnt > target->max_multiple_clicks_interval)
            {
                EVENT_SET_AND_EXEC_CB(target, 
                    target->click_cnt < FLEX_BTN_PRESS_REPEAT_CLICK ? 
                        target->click_cnt :
                        FLEX_BTN_PRESS_REPEAT_CLICK);

                /* swtich to default stage */
                target->status = FLEX_BTN_STAGE_DEFAULT;
            }
        }
        break;
    }
}

}`

@xluohome
Copy link

xluohome commented Mar 18, 2023

FlexibleButton v2.0.1 released Latest 是存在 这个问题, @murphyzhao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants