Browse Source

Working encoder detection.

xmkb
Pete Johanson 4 years ago
parent
commit
7da9a1039f
  1. 15
      app/drivers/zephyr/ec11.c
  2. 2
      app/src/main.c

15
app/drivers/zephyr/ec11.c

@ -18,6 +18,13 @@ @@ -18,6 +18,13 @@
LOG_MODULE_REGISTER(EC11, CONFIG_SENSOR_LOG_LEVEL);
static int ec11_get_ab_state(struct device *dev)
{
struct ec11_data *drv_data = dev->driver_data;
const struct ec11_config *drv_cfg = dev->config_info;
return (gpio_pin_get(drv_data->a, drv_cfg->a_pin) << 1) | gpio_pin_get(drv_data->b, drv_cfg->b_pin);
}
static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan)
{
@ -28,15 +35,15 @@ static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan) @@ -28,15 +35,15 @@ static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan)
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_ROTATION);
val = (gpio_pin_get(drv_data->a, drv_cfg->a_pin) << 1) | gpio_pin_get(drv_data->b, drv_cfg->b_pin);
val = ec11_get_ab_state(dev);
LOG_DBG("prev: %d, new: %d", drv_data->ab_state, val);
switch(val | (drv_data->ab_state << 2)) {
case 0b0001: case 0b0111: case 0b1110: case 0b1000:
case 0b0010: case 0b0100: case 0b1101: case 0b1011:
delta = 1;
break;
case 0b0010: case 0b0100: case 0b1101: case 0b1011:
case 0b0001: case 0b0111: case 0b1110: case 0b1000:
delta = -1;
break;
default:
@ -106,6 +113,8 @@ int ec11_init(struct device *dev) @@ -106,6 +113,8 @@ int ec11_init(struct device *dev)
}
#endif
drv_data->ab_state = ec11_get_ab_state(dev);
return 0;
}

2
app/src/main.c

@ -39,6 +39,8 @@ void encoder_change(struct device *dev, struct sensor_trigger *trigger) @@ -39,6 +39,8 @@ void encoder_change(struct device *dev, struct sensor_trigger *trigger)
LOG_DBG("Failed to get the sample for EC11 %d", err);
return;
}
LOG_DBG("val1 %d val2 %d", value.val1, value.val2);
}
void init_sensor()

Loading…
Cancel
Save