1 // Copyright 2021 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 <gtest/gtest.h> // for FRIEND_TEST 6 #include <set> 7 8 #include "include/filter_interpreter.h" 9 #include "include/gestures.h" 10 #include "include/prop_registry.h" 11 #include "include/tracer.h" 12 13 #ifndef GESTURES_INCLUDE_HAPTIC_BUTTON_GENERATOR_FILTER_INTERPRETER_H_ 14 #define GESTURES_INCLUDE_HAPTIC_BUTTON_GENERATOR_FILTER_INTERPRETER_H_ 15 16 // For haptic touchpads, the gesture library is responsible for determining the 17 // state of the "physical" button. This class sets the button state based on the 18 // user's force threshold preferences. 19 20 namespace gestures { 21 22 class HapticButtonGeneratorFilterInterpreter : public FilterInterpreter { 23 FRIEND_TEST(HapticButtonGeneratorFilterInterpreterTest, SimpleTest); 24 FRIEND_TEST(HapticButtonGeneratorFilterInterpreterTest, NotHapticTest); 25 FRIEND_TEST(HapticButtonGeneratorFilterInterpreterTest, 26 NotHapticConsumeGestureTest); 27 FRIEND_TEST(HapticButtonGeneratorFilterInterpreterTest, 28 GesturePreventsButtonDownTest); 29 FRIEND_TEST(HapticButtonGeneratorFilterInterpreterTest, DynamicThresholdTest); 30 FRIEND_TEST(HapticButtonGeneratorFilterInterpreterTest, PalmTest); 31 public: 32 // Takes ownership of |next|: 33 explicit HapticButtonGeneratorFilterInterpreter(PropRegistry* prop_reg, 34 Interpreter* next, 35 Tracer* tracer); ~HapticButtonGeneratorFilterInterpreter()36 virtual ~HapticButtonGeneratorFilterInterpreter() {} 37 38 virtual void Initialize(const HardwareProperties* hwprops, 39 Metrics* metrics, MetricsProperties* mprops, 40 GestureConsumer* consumer) override; 41 protected: 42 virtual void SyncInterpretImpl(HardwareState& hwstate, 43 stime_t* timeout) override; 44 45 private: 46 void ConsumeGesture(const Gesture& gesture) override; 47 void HandleHardwareState(HardwareState& hwstate); 48 virtual void HandleTimerImpl(stime_t now, stime_t *timeout) override; 49 void UpdatePalmState(const HardwareState& hwstate); 50 51 static const size_t kMaxSensitivitySettings = 5; 52 53 // All threshold values are in grams. 54 const double down_thresholds_[kMaxSensitivitySettings] = 55 {90.0, 110.0, 130.0, 145.0, 160.0}; 56 const double up_thresholds_[kMaxSensitivitySettings] = 57 {80.0, 95.0, 105.0, 120.0, 135.0}; 58 59 std::set<short> palms_; 60 61 // Scaling factor for release force [0.0-1.0] 62 double release_suppress_factor_; 63 64 // We prevent button down events during an active non-click multi-finger 65 // gesture 66 bool active_gesture_; 67 double active_gesture_timeout_; 68 double active_gesture_deadline_; 69 70 // Is the button currently down? 71 bool button_down_; 72 73 bool is_haptic_pad_; 74 75 // When the user presses very hard, we dynamically adjust force thresholds to 76 // allow easier double-clicking 77 double dynamic_down_threshold_; 78 double dynamic_up_threshold_; 79 80 IntProperty sensitivity_; // [1..5] 81 82 BoolProperty use_custom_thresholds_; 83 DoubleProperty custom_down_threshold_; 84 DoubleProperty custom_up_threshold_; 85 86 BoolProperty enabled_; 87 88 DoubleProperty force_scale_; 89 DoubleProperty force_translate_; 90 91 DoubleProperty complete_release_suppress_speed_; 92 93 BoolProperty use_dynamic_thresholds_; 94 DoubleProperty dynamic_down_ratio_; 95 DoubleProperty dynamic_up_ratio_; 96 DoubleProperty max_dynamic_up_force_; 97 }; 98 99 } // namespace gestures 100 101 102 #endif // GESTURES_INCLUDE_HAPTIC_BUTTON_GENERATOR_FILTER_INTERPRETER_H_ 103