• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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               GesturePreventsButtonDownTest);
27   FRIEND_TEST(HapticButtonGeneratorFilterInterpreterTest, DynamicThresholdTest);
28   FRIEND_TEST(HapticButtonGeneratorFilterInterpreterTest, PalmTest);
29  public:
30   // Takes ownership of |next|:
31   explicit HapticButtonGeneratorFilterInterpreter(PropRegistry* prop_reg,
32                                                   Interpreter* next,
33                                                   Tracer* tracer);
~HapticButtonGeneratorFilterInterpreter()34   virtual ~HapticButtonGeneratorFilterInterpreter() {}
35 
36   virtual void Initialize(const HardwareProperties* hwprops,
37                           Metrics* metrics, MetricsProperties* mprops,
38                           GestureConsumer* consumer) override;
39  protected:
40   virtual void SyncInterpretImpl(HardwareState* hwstate,
41                                  stime_t* timeout) override;
42 
43  private:
44   void ConsumeGesture(const Gesture& gesture) override;
45   void HandleHardwareState(HardwareState* hwstate);
46   virtual void HandleTimerImpl(stime_t now, stime_t *timeout) override;
47   void UpdatePalmState(HardwareState* hwstate);
48 
49   static const size_t kMaxSensitivitySettings = 5;
50 
51   // All threshold values are in grams.
52   const double down_thresholds_[kMaxSensitivitySettings] =
53       {90.0, 110.0, 130.0, 145.0, 160.0};
54   const double up_thresholds_[kMaxSensitivitySettings] =
55       {80.0, 95.0, 105.0, 120.0, 135.0};
56 
57   std::set<short> palms_;
58 
59   // Scaling factor for release force [0.0-1.0]
60   double release_suppress_factor_;
61 
62   // We prevent button down events during an active non-click multi-finger
63   // gesture
64   bool active_gesture_;
65   double active_gesture_timeout_;
66   double active_gesture_deadline_;
67 
68   // Is the button currently down?
69   bool button_down_;
70 
71   bool is_haptic_pad_;
72 
73   // When the user presses very hard, we dynamically adjust force thresholds to
74   // allow easier double-clicking
75   double dynamic_down_threshold_;
76   double dynamic_up_threshold_;
77 
78   IntProperty sensitivity_;  // [1..5]
79 
80   BoolProperty use_custom_thresholds_;
81   DoubleProperty custom_down_threshold_;
82   DoubleProperty custom_up_threshold_;
83 
84   BoolProperty enabled_;
85 
86   DoubleProperty force_scale_;
87   DoubleProperty force_translate_;
88 
89   DoubleProperty complete_release_suppress_speed_;
90 
91   BoolProperty use_dynamic_thresholds_;
92   DoubleProperty dynamic_down_ratio_;
93   DoubleProperty dynamic_up_ratio_;
94   DoubleProperty max_dynamic_up_force_;
95 };
96 
97 }  // namespace gestures
98 
99 
100 #endif  // GESTURES_INCLUDE_HAPTIC_BUTTON_GENERATOR_FILTER_INTERPRETER_H_
101