input/buttons: Fix the event lose between the invocation of poll
Signed-off-by: xueyanhong <xueyanhong@xiaomi.com>
This commit is contained in:
parent
2c8437151f
commit
b953296de7
@ -95,6 +95,7 @@ struct btn_open_s
|
|||||||
* driver events.
|
* driver events.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
bool bo_pending;
|
||||||
FAR struct pollfd *bo_fds[CONFIG_INPUT_BUTTONS_NPOLLWAITERS];
|
FAR struct pollfd *bo_fds[CONFIG_INPUT_BUTTONS_NPOLLWAITERS];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -281,6 +282,10 @@ static void btn_sample(FAR struct btn_upperhalf_s *priv)
|
|||||||
|
|
||||||
for (opriv = priv->bu_open; opriv; opriv = opriv->bo_flink)
|
for (opriv = priv->bu_open; opriv; opriv = opriv->bo_flink)
|
||||||
{
|
{
|
||||||
|
/* Always set bo_pending true, only clear it after button read */
|
||||||
|
|
||||||
|
opriv->bo_pending = true;
|
||||||
|
|
||||||
/* Have any poll events occurred? */
|
/* Have any poll events occurred? */
|
||||||
|
|
||||||
if ((press & opriv->bo_pollevents.bp_press) != 0 ||
|
if ((press & opriv->bo_pollevents.bp_press) != 0 ||
|
||||||
@ -488,11 +493,13 @@ static ssize_t btn_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
FAR struct inode *inode;
|
FAR struct inode *inode;
|
||||||
|
FAR struct btn_open_s *opriv;
|
||||||
FAR struct btn_upperhalf_s *priv;
|
FAR struct btn_upperhalf_s *priv;
|
||||||
FAR const struct btn_lowerhalf_s *lower;
|
FAR const struct btn_lowerhalf_s *lower;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(filep && filep->f_inode);
|
DEBUGASSERT(filep && filep->f_inode);
|
||||||
|
opriv = filep->f_priv;
|
||||||
inode = filep->f_inode;
|
inode = filep->f_inode;
|
||||||
DEBUGASSERT(inode->i_private);
|
DEBUGASSERT(inode->i_private);
|
||||||
priv = (FAR struct btn_upperhalf_s *)inode->i_private;
|
priv = (FAR struct btn_upperhalf_s *)inode->i_private;
|
||||||
@ -523,6 +530,7 @@ static ssize_t btn_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
lower = priv->bu_lower;
|
lower = priv->bu_lower;
|
||||||
DEBUGASSERT(lower && lower->bl_buttons);
|
DEBUGASSERT(lower && lower->bl_buttons);
|
||||||
*(FAR btn_buttonset_t *)buffer = lower->bl_buttons(lower);
|
*(FAR btn_buttonset_t *)buffer = lower->bl_buttons(lower);
|
||||||
|
opriv->bo_pending = false;
|
||||||
|
|
||||||
btn_givesem(&priv->bu_exclsem);
|
btn_givesem(&priv->bu_exclsem);
|
||||||
return (ssize_t)sizeof(btn_buttonset_t);
|
return (ssize_t)sizeof(btn_buttonset_t);
|
||||||
@ -759,6 +767,19 @@ static int btn_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|||||||
|
|
||||||
opriv->bo_fds[i] = fds;
|
opriv->bo_fds[i] = fds;
|
||||||
fds->priv = &opriv->bo_fds[i];
|
fds->priv = &opriv->bo_fds[i];
|
||||||
|
|
||||||
|
/* Report if the event is pending */
|
||||||
|
|
||||||
|
if (opriv->bo_pending)
|
||||||
|
{
|
||||||
|
fds->revents |= (fds->events & POLLIN);
|
||||||
|
if (fds->revents != 0)
|
||||||
|
{
|
||||||
|
iinfo("Report events: %02x\n", fds->revents);
|
||||||
|
nxsem_post(fds->sem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user