fix(kscan): Avoid sending duplicate kscan events.

This commit is contained in:
Pete Johanson 2020-09-01 09:55:25 -04:00
parent af6ddfb7e2
commit 01db53b46a
1 changed files with 2 additions and 2 deletions

View File

@ -156,7 +156,6 @@ static int kscan_gpio_read(struct device *dev)
struct kscan_gpio_data *data = dev->driver_data;
const struct kscan_gpio_config *cfg = dev->config_info;
u32_t read_state = data->pin_state;
LOG_DBG("Scanning the pins for updated state");
for (int i = 0; i < cfg->num_of_inputs; i++)
{
struct device *in_dev = kscan_gpio_input_devices(dev)[i];
@ -165,8 +164,9 @@ static int kscan_gpio_read(struct device *dev)
}
for (int i = 0; i < cfg->num_of_inputs; i++)
{
bool prev_pressed = BIT(i) & data->pin_state;
bool pressed = BIT(i) & read_state;
if (pressed != (BIT(i) & data->pin_state))
if (pressed != prev_pressed)
{
LOG_DBG("Sending event at %d,%d state %s",
0, i, (pressed ? "on" : "off"));