1 // Copyright 2012 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <map> 6 7 #include <gtest/gtest.h> // For FRIEND_TEST 8 9 #include "include/filter_interpreter.h" 10 #include "include/finger_metrics.h" 11 #include "include/gestures.h" 12 #include "include/prop_registry.h" 13 #include "include/tracer.h" 14 15 #ifndef GESTURES_SENSOR_JUMP_FILTER_INTERPRETER_H_ 16 #define GESTURES_SENSOR_JUMP_FILTER_INTERPRETER_H_ 17 18 namespace gestures { 19 20 // This filter interpreter looks for fingers that suspiciously jump position, 21 // something that can occur on some touchpads when a finger is large and 22 // spanning multiple sensors. 23 24 // When a suspicious jump is detected, the finger is flagged with a warp 25 // flag for the axis in which the jump occurred. 26 27 class SensorJumpFilterInterpreter : public FilterInterpreter, 28 public PropertyDelegate { 29 FRIEND_TEST(SensorJumpFilterInterpreterTest, SimpleTest); 30 FRIEND_TEST(SensorJumpFilterInterpreterTest, ActualLogTest); 31 public: 32 // Takes ownership of |next|: 33 SensorJumpFilterInterpreter(PropRegistry* prop_reg, Interpreter* next, 34 Tracer* tracer); ~SensorJumpFilterInterpreter()35 virtual ~SensorJumpFilterInterpreter() {} 36 37 protected: 38 virtual void SyncInterpretImpl(HardwareState& hwstate, stime_t* timeout); 39 40 private: 41 // Fingers from the previous two SyncInterpret calls. previous_input_[0] 42 // is the more recent. 43 std::map<short, FingerState> previous_input_[2]; 44 45 // When a finger is flagged with a warp flag for the first time, we note it 46 // here. 47 // first_flag_[0] for WARP_X_NON_MOVE; 48 // first_flag_[1] for WARP_Y_NON_MOVE; 49 // first_flag_[2] for WARP_X_MOVE; 50 // first_flag_[3] for WARP_Y_MOVE. 51 std::set<short> first_flag_[4]; 52 53 // Whether or not this filter is enabled. If disabled, it behaves as a 54 // simple passthrough. 55 BoolProperty enabled_; 56 // The smallest distance that may be considered for warp for non-cursor 57 // movement. 58 DoubleProperty min_warp_dist_non_move_; 59 // The largest distance that may be considered for warp for non-cursor 60 // movement. 61 DoubleProperty max_warp_dist_non_move_; 62 // A suspiciously sized jump may be tolerated if it's length falls within 63 // similar_multiplier_ * the previous frame's movement, for non-cursor 64 // movement. 65 DoubleProperty similar_multiplier_non_move_; 66 67 // Similar set of parameters to the above ones but for cursor movement. 68 DoubleProperty min_warp_dist_move_; 69 DoubleProperty max_warp_dist_move_; 70 DoubleProperty similar_multiplier_move_; 71 72 // Considering the following X position sequence: 73 // 8, 9, 10, 9, 10, 11, 12 (1F move) 74 // In case of 1F move, we don't want to marke the second 10 as WARP due 75 // to the direction change in 10->9->10 since in Box Filter the second 76 // 10 will be re-set to box center and the following 11, 12 won't cause 77 // movement since they are within the new box. So we use 78 // no_warp_min_dist_move_ to filter out really small direction change to 79 // not be marked as WARP. 80 DoubleProperty no_warp_min_dist_move_; 81 }; 82 83 } // namespace gestures 84 85 #endif // GESTURES_SENSOR_JUMP_FILTER_INTERPRETER_H_ 86