diff options
| -rw-r--r-- | src/common.h | 16 | ||||
| -rw-r--r-- | src/gestures.c | 2 | ||||
| -rw-r--r-- | src/hwdata.h | 7 | ||||
| -rw-r--r-- | src/hwstate.c | 18 |
4 files changed, 24 insertions, 19 deletions
diff --git a/src/common.h b/src/common.h index 1b4d007..32be48d 100644 --- a/src/common.h +++ b/src/common.h | |||
| @@ -61,6 +61,22 @@ | |||
| 61 | #define SETBIT(m, x) (m |= BITMASK(x)) | 61 | #define SETBIT(m, x) (m |= BITMASK(x)) |
| 62 | #define CLEARBIT(m, x) (m &= ~BITMASK(x)) | 62 | #define CLEARBIT(m, x) (m &= ~BITMASK(x)) |
| 63 | 63 | ||
| 64 | static inline int maxval(int x, int y) { return x > y ? x : y; } | ||
| 65 | static inline int minval(int x, int y) { return x < y ? x : y; } | ||
| 66 | |||
| 67 | static inline int clamp15(int x) | ||
| 68 | { | ||
| 69 | return x < -32767 ? -32767 : x > 32767 ? 32767 : x; | ||
| 70 | } | ||
| 71 | |||
| 72 | /* absolute scale is assumed to fit in 15 bits */ | ||
| 73 | static inline int dist2(int dx, int dy) | ||
| 74 | { | ||
| 75 | dx = clamp15(dx); | ||
| 76 | dy = clamp15(dy); | ||
| 77 | return dx * dx + dy * dy; | ||
| 78 | } | ||
| 79 | |||
| 64 | /* Count number of bits (Sean Eron Andersson's Bit Hacks) */ | 80 | /* Count number of bits (Sean Eron Andersson's Bit Hacks) */ |
| 65 | static inline int bitcount(unsigned v) | 81 | static inline int bitcount(unsigned v) |
| 66 | { | 82 | { |
diff --git a/src/gestures.c b/src/gestures.c index f44e6ab..a0ef5d4 100644 --- a/src/gestures.c +++ b/src/gestures.c | |||
| @@ -31,8 +31,6 @@ | |||
| 31 | static const int FINGER_ATTACK_MS = 70; | 31 | static const int FINGER_ATTACK_MS = 70; |
| 32 | static const int FINGER_DECAY_MS = 120; | 32 | static const int FINGER_DECAY_MS = 120; |
| 33 | 33 | ||
| 34 | static inline int maxval(int x, int y) { return x > y ? x : y; } | ||
| 35 | |||
| 36 | inline int dxval(const struct FingerState *a, const struct FingerState *b) | 34 | inline int dxval(const struct FingerState *a, const struct FingerState *b) |
| 37 | { | 35 | { |
| 38 | return a->hw.position_x - b->hw.position_x; | 36 | return a->hw.position_x - b->hw.position_x; |
diff --git a/src/hwdata.h b/src/hwdata.h index 15a9fcb..5dd99cf 100644 --- a/src/hwdata.h +++ b/src/hwdata.h | |||
| @@ -81,4 +81,11 @@ void init_hwdata(struct HWData *hw); | |||
| 81 | int read_hwdata(struct HWData *hw, const struct input_event* ev); | 81 | int read_hwdata(struct HWData *hw, const struct input_event* ev); |
| 82 | void output_hwdata(const struct HWData *hw); | 82 | void output_hwdata(const struct HWData *hw); |
| 83 | 83 | ||
| 84 | static inline int finger_dist2(const struct FingerData *a, | ||
| 85 | const struct FingerData *b) | ||
| 86 | { | ||
| 87 | return dist2(a->position_x - b->position_x, | ||
| 88 | a->position_y - b->position_y); | ||
| 89 | } | ||
| 90 | |||
| 84 | #endif | 91 | #endif |
diff --git a/src/hwstate.c b/src/hwstate.c index 07bab31..a68b81a 100644 --- a/src/hwstate.c +++ b/src/hwstate.c | |||
| @@ -25,27 +25,11 @@ | |||
| 25 | 25 | ||
| 26 | #define NOTOUCH(hw, c) ((hw)->touch_major == 0 && (c)->has_touch_major) | 26 | #define NOTOUCH(hw, c) ((hw)->touch_major == 0 && (c)->has_touch_major) |
| 27 | 27 | ||
| 28 | const int XMAX = 32767; | ||
| 29 | |||
| 30 | void init_hwstate(struct HWState *s) | 28 | void init_hwstate(struct HWState *s) |
| 31 | { | 29 | { |
| 32 | memset(s, 0, sizeof(struct HWState)); | 30 | memset(s, 0, sizeof(struct HWState)); |
| 33 | } | 31 | } |
| 34 | 32 | ||
| 35 | static inline int clamp15(int x) | ||
| 36 | { | ||
| 37 | return x < -XMAX ? -XMAX : x > XMAX ? XMAX : x; | ||
| 38 | } | ||
| 39 | |||
| 40 | /* abslute scale is assumed to fit in 15 bits */ | ||
| 41 | inline int dist2(const struct FingerData *a, const struct FingerData *b) | ||
| 42 | { | ||
| 43 | int dx = clamp15(a->position_x - b->position_x); | ||
| 44 | int dy = clamp15(a->position_y - b->position_y); | ||
| 45 | |||
| 46 | return dx * dx + dy * dy; | ||
| 47 | } | ||
| 48 | |||
| 49 | /* Dmitry Torokhov's code from kernel/driver/input/input.c */ | 33 | /* Dmitry Torokhov's code from kernel/driver/input/input.c */ |
| 50 | static int defuzz(int value, int old_val, int fuzz) | 34 | static int defuzz(int value, int old_val, int fuzz) |
| 51 | { | 35 | { |
| @@ -104,7 +88,7 @@ void modify_hwstate(struct HWState *s, | |||
| 104 | sid[j] = 0; | 88 | sid[j] = 0; |
| 105 | row = A + hw->nfinger * j; | 89 | row = A + hw->nfinger * j; |
| 106 | for (i = 0; i < hw->nfinger; i++) | 90 | for (i = 0; i < hw->nfinger; i++) |
| 107 | row[i] = dist2(&hw->finger[i], &s->finger[j].hw); | 91 | row[i] = finger_dist2(&hw->finger[i], &s->finger[j].hw); |
| 108 | } | 92 | } |
| 109 | 93 | ||
| 110 | match_fingers(hw2s, A, hw->nfinger, s->nfinger); | 94 | match_fingers(hw2s, A, hw->nfinger, s->nfinger); |
