Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 250520
b: refs/heads/master
c: f1e430e
h: refs/heads/master
v: v3
  • Loading branch information
Michael Hennerich authored and Dmitry Torokhov committed May 17, 2011
1 parent 369d34b commit 3b8388b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 91 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 3532cb0ca2774b05e3c660f536ba3d1b38061fc9
refs/heads/master: f1e430e6369f5edac552d99bff15369ef8c6bbd2
109 changes: 19 additions & 90 deletions trunk/drivers/input/misc/ad714x.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,7 @@ struct ad714x_slider_drv {
struct ad714x_wheel_drv {
int abs_pos;
int flt_pos;
int pre_mean_value;
int pre_highest_stage;
int pre_mean_value_no_offset;
int mean_value;
int mean_value_no_offset;
int pos_offset;
int pos_ratio;
int highest_stage;
enum ad714x_device_state state;
struct input_dev *input;
Expand Down Expand Up @@ -404,7 +398,6 @@ static void ad714x_slider_state_machine(struct ad714x_chip *ad714x, int idx)
ad714x_slider_cal_highest_stage(ad714x, idx);
ad714x_slider_cal_abs_pos(ad714x, idx);
ad714x_slider_cal_flt_pos(ad714x, idx);

input_report_abs(sw->input, ABS_X, sw->flt_pos);
input_report_key(sw->input, BTN_TOUCH, 1);
} else {
Expand Down Expand Up @@ -468,104 +461,41 @@ static void ad714x_wheel_cal_sensor_val(struct ad714x_chip *ad714x, int idx)
/*
* When the scroll wheel is activated, we compute the absolute position based
* on the sensor values. To calculate the position, we first determine the
* sensor that has the greatest response among the 8 sensors that constitutes
* the scrollwheel. Then we determined the 2 sensors on either sides of the
* sensor that has the greatest response among the sensors that constitutes
* the scrollwheel. Then we determined the sensors on either sides of the
* sensor with the highest response and we apply weights to these sensors. The
* result of this computation gives us the mean value which defined by the
* following formula:
* For i= second_before_highest_stage to i= second_after_highest_stage
* v += Sensor response(i)*WEIGHT*(i+3)
* w += Sensor response(i)
* Mean_Value=v/w
* pos_on_scrollwheel = (Mean_Value - position_offset) / position_ratio
* result of this computation gives us the mean value.
*/

#define WEIGHT_FACTOR 30
/* This constant prevents the "PositionOffset" from reaching a big value */
#define OFFSET_POSITION_CLAMP 120
static void ad714x_wheel_cal_abs_pos(struct ad714x_chip *ad714x, int idx)
{
struct ad714x_wheel_plat *hw = &ad714x->hw->wheel[idx];
struct ad714x_wheel_drv *sw = &ad714x->sw->wheel[idx];
int stage_num = hw->end_stage - hw->start_stage + 1;
int second_before, first_before, highest, first_after, second_after;
int first_before, highest, first_after;
int a_param, b_param;

/* Calculate Mean value */

second_before = (sw->highest_stage + stage_num - 2) % stage_num;
first_before = (sw->highest_stage + stage_num - 1) % stage_num;
highest = sw->highest_stage;
first_after = (sw->highest_stage + stage_num + 1) % stage_num;
second_after = (sw->highest_stage + stage_num + 2) % stage_num;

if (((sw->highest_stage - hw->start_stage) > 1) &&
((hw->end_stage - sw->highest_stage) > 1)) {
a_param = ad714x->sensor_val[second_before] *
(second_before - hw->start_stage + 3) +
ad714x->sensor_val[first_before] *
(second_before - hw->start_stage + 3) +
ad714x->sensor_val[highest] *
(second_before - hw->start_stage + 3) +
ad714x->sensor_val[first_after] *
(first_after - hw->start_stage + 3) +
ad714x->sensor_val[second_after] *
(second_after - hw->start_stage + 3);
} else {
a_param = ad714x->sensor_val[second_before] *
(second_before - hw->start_stage + 1) +
ad714x->sensor_val[first_before] *
(second_before - hw->start_stage + 2) +
ad714x->sensor_val[highest] *
(second_before - hw->start_stage + 3) +
ad714x->sensor_val[first_after] *
(first_after - hw->start_stage + 4) +
ad714x->sensor_val[second_after] *
(second_after - hw->start_stage + 5);
}
a_param *= WEIGHT_FACTOR;

b_param = ad714x->sensor_val[second_before] +
a_param = ad714x->sensor_val[highest] *
(highest - hw->start_stage) +
ad714x->sensor_val[first_before] *
(highest - hw->start_stage - 1) +
ad714x->sensor_val[first_after] *
(highest - hw->start_stage + 1);
b_param = ad714x->sensor_val[highest] +
ad714x->sensor_val[first_before] +
ad714x->sensor_val[highest] +
ad714x->sensor_val[first_after] +
ad714x->sensor_val[second_after];

sw->pre_mean_value = sw->mean_value;
sw->mean_value = a_param / b_param;

/* Calculate the offset */

if ((sw->pre_highest_stage == hw->end_stage) &&
(sw->highest_stage == hw->start_stage))
sw->pos_offset = sw->mean_value;
else if ((sw->pre_highest_stage == hw->start_stage) &&
(sw->highest_stage == hw->end_stage))
sw->pos_offset = sw->pre_mean_value;

if (sw->pos_offset > OFFSET_POSITION_CLAMP)
sw->pos_offset = OFFSET_POSITION_CLAMP;

/* Calculate the mean value without the offset */

sw->pre_mean_value_no_offset = sw->mean_value_no_offset;
sw->mean_value_no_offset = sw->mean_value - sw->pos_offset;
if (sw->mean_value_no_offset < 0)
sw->mean_value_no_offset = 0;

/* Calculate ratio to scale down to NUMBER_OF_WANTED_POSITIONS */

if ((sw->pre_highest_stage == hw->end_stage) &&
(sw->highest_stage == hw->start_stage))
sw->pos_ratio = (sw->pre_mean_value_no_offset * 100) /
hw->max_coord;
else if ((sw->pre_highest_stage == hw->start_stage) &&
(sw->highest_stage == hw->end_stage))
sw->pos_ratio = (sw->mean_value_no_offset * 100) /
hw->max_coord;
sw->abs_pos = (sw->mean_value_no_offset * 100) / sw->pos_ratio;
ad714x->sensor_val[first_after];

sw->abs_pos = ((hw->max_coord / (hw->end_stage - hw->start_stage)) *
a_param) / b_param;

if (sw->abs_pos > hw->max_coord)
sw->abs_pos = hw->max_coord;
else if (sw->abs_pos < 0)
sw->abs_pos = 0;
}

static void ad714x_wheel_cal_flt_pos(struct ad714x_chip *ad714x, int idx)
Expand Down Expand Up @@ -639,9 +569,8 @@ static void ad714x_wheel_state_machine(struct ad714x_chip *ad714x, int idx)
ad714x_wheel_cal_highest_stage(ad714x, idx);
ad714x_wheel_cal_abs_pos(ad714x, idx);
ad714x_wheel_cal_flt_pos(ad714x, idx);

input_report_abs(sw->input, ABS_WHEEL,
sw->abs_pos);
sw->flt_pos);
input_report_key(sw->input, BTN_TOUCH, 1);
} else {
/* When the user lifts off the sensor, configure
Expand Down

0 comments on commit 3b8388b

Please sign in to comment.