Fetch/get implementation work.
This commit is contained in:
parent
109c69cbab
commit
c058757252
2 changed files with 22 additions and 26 deletions
|
@ -24,7 +24,7 @@ static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan)
|
|||
struct ec11_data *drv_data = dev->driver_data;
|
||||
const struct ec11_config *drv_cfg = dev->config_info;
|
||||
u8_t val;
|
||||
u8_t delta;
|
||||
s8_t delta;
|
||||
|
||||
__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);
|
||||
|
||||
switch(val | (drv_data->ab_state << 2)) {
|
||||
case 0b0001: case 0b0111: case 0b1110:
|
||||
LOG_DBG("+1");
|
||||
case 0b0001: case 0b0111: case 0b1110: case 0b1000:
|
||||
delta = 1;
|
||||
break;
|
||||
case 0b0010: case 0b0100: case 0b1101: case 0b1011:
|
||||
delta = -1;
|
||||
break;
|
||||
default:
|
||||
LOG_DBG("FIGURE IT OUT!");
|
||||
delta = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
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) {
|
||||
// return -EIO;
|
||||
// }
|
||||
|
||||
// if (val & EC11_DATA_INVALID_BIT) {
|
||||
// return -EIO;
|
||||
// }
|
||||
|
||||
// drv_data->sample = arithmetic_shift_right((s16_t)val, 2);
|
||||
drv_data->ticks = drv_data->pulses / drv_cfg->resolution;
|
||||
drv_data->delta = delta;
|
||||
drv_data->pulses %= drv_cfg->resolution;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -64,15 +62,12 @@ static int ec11_channel_get(struct device *dev,
|
|||
{
|
||||
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 = uval / 1000000;
|
||||
// val->val2 = uval % 1000000;
|
||||
val->val1 = drv_data->ticks;
|
||||
val->val2 = drv_data->delta;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -31,8 +31,9 @@ struct ec11_data {
|
|||
struct device *a;
|
||||
struct device *b;
|
||||
u8_t ab_state;
|
||||
s16_t pulse_state;
|
||||
s16_t tick_state;
|
||||
s8_t pulses;
|
||||
s8_t ticks;
|
||||
s8_t delta;
|
||||
|
||||
#ifdef CONFIG_EC11_TRIGGER
|
||||
struct device *gpio;
|
||||
|
|
Loading…
Reference in a new issue