Browse Source

Fetch/get implementation work.

xmkb
Pete Johanson 4 years ago
parent
commit
c058757252
  1. 37
      app/drivers/zephyr/ec11.c
  2. 5
      app/drivers/zephyr/ec11.h

37
app/drivers/zephyr/ec11.c

@ -24,7 +24,7 @@ static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan)
struct ec11_data *drv_data = dev->driver_data; struct ec11_data *drv_data = dev->driver_data;
const struct ec11_config *drv_cfg = dev->config_info; const struct ec11_config *drv_cfg = dev->config_info;
u8_t val; u8_t val;
u8_t delta; s8_t delta;
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_ROTATION); __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_ROTATION);
@ -33,27 +33,25 @@ static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan)
LOG_DBG("prev: %d, new: %d", drv_data->ab_state, val); LOG_DBG("prev: %d, new: %d", drv_data->ab_state, val);
switch(val | (drv_data->ab_state << 2)) { switch(val | (drv_data->ab_state << 2)) {
case 0b0001: case 0b0111: case 0b1110: case 0b0001: case 0b0111: case 0b1110: case 0b1000:
LOG_DBG("+1");
delta = 1; delta = 1;
break; break;
case 0b0010: case 0b0100: case 0b1101: case 0b1011:
delta = -1;
break;
default: default:
LOG_DBG("FIGURE IT OUT!"); delta = 0;
break; break;
} }
LOG_DBG("Delta: %d", delta); LOG_DBG("Delta: %d", delta);
drv_data->pulses += delta;
drv_data->ab_state = val;
// if (ec11_reg_read(drv_data, EC11_REG_TOBJ, &val) < 0) { drv_data->ticks = drv_data->pulses / drv_cfg->resolution;
// return -EIO; drv_data->delta = delta;
// } drv_data->pulses %= drv_cfg->resolution;
// if (val & EC11_DATA_INVALID_BIT) {
// return -EIO;
// }
// drv_data->sample = arithmetic_shift_right((s16_t)val, 2);
return 0; return 0;
} }
@ -64,15 +62,12 @@ static int ec11_channel_get(struct device *dev,
{ {
struct ec11_data *drv_data = dev->driver_data; struct ec11_data *drv_data = dev->driver_data;
// s32_t uval; if (chan != SENSOR_CHAN_ROTATION) {
return -ENOTSUP;
// if (chan != SENSOR_CHAN_AMBIENT_TEMP) { }
// return -ENOTSUP;
// }
// uval = (s32_t)drv_data->sample * EC11_TEMP_SCALE; val->val1 = drv_data->ticks;
// val->val1 = uval / 1000000; val->val2 = drv_data->delta;
// val->val2 = uval % 1000000;
return 0; return 0;
} }

5
app/drivers/zephyr/ec11.h

@ -31,8 +31,9 @@ struct ec11_data {
struct device *a; struct device *a;
struct device *b; struct device *b;
u8_t ab_state; u8_t ab_state;
s16_t pulse_state; s8_t pulses;
s16_t tick_state; s8_t ticks;
s8_t delta;
#ifdef CONFIG_EC11_TRIGGER #ifdef CONFIG_EC11_TRIGGER
struct device *gpio; struct device *gpio;

Loading…
Cancel
Save