• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "SingleTouchMotionAccumulator.h"
18 
19 #include "EventHub.h"
20 #include "InputDevice.h"
21 
22 namespace android {
23 
SingleTouchMotionAccumulator()24 SingleTouchMotionAccumulator::SingleTouchMotionAccumulator() {
25     clearAbsoluteAxes();
26 }
27 
reset(InputDeviceContext & deviceContext)28 void SingleTouchMotionAccumulator::reset(InputDeviceContext& deviceContext) {
29     mAbsX = deviceContext.getAbsoluteAxisValue(ABS_X);
30     mAbsY = deviceContext.getAbsoluteAxisValue(ABS_Y);
31     mAbsPressure = deviceContext.getAbsoluteAxisValue(ABS_PRESSURE);
32     mAbsToolWidth = deviceContext.getAbsoluteAxisValue(ABS_TOOL_WIDTH);
33     mAbsDistance = deviceContext.getAbsoluteAxisValue(ABS_DISTANCE);
34     mAbsTiltX = deviceContext.getAbsoluteAxisValue(ABS_TILT_X);
35     mAbsTiltY = deviceContext.getAbsoluteAxisValue(ABS_TILT_Y);
36 }
37 
clearAbsoluteAxes()38 void SingleTouchMotionAccumulator::clearAbsoluteAxes() {
39     mAbsX = 0;
40     mAbsY = 0;
41     mAbsPressure = 0;
42     mAbsToolWidth = 0;
43     mAbsDistance = 0;
44     mAbsTiltX = 0;
45     mAbsTiltY = 0;
46 }
47 
process(const RawEvent * rawEvent)48 void SingleTouchMotionAccumulator::process(const RawEvent* rawEvent) {
49     if (rawEvent->type == EV_ABS) {
50         switch (rawEvent->code) {
51             case ABS_X:
52                 mAbsX = rawEvent->value;
53                 break;
54             case ABS_Y:
55                 mAbsY = rawEvent->value;
56                 break;
57             case ABS_PRESSURE:
58                 mAbsPressure = rawEvent->value;
59                 break;
60             case ABS_TOOL_WIDTH:
61                 mAbsToolWidth = rawEvent->value;
62                 break;
63             case ABS_DISTANCE:
64                 mAbsDistance = rawEvent->value;
65                 break;
66             case ABS_TILT_X:
67                 mAbsTiltX = rawEvent->value;
68                 break;
69             case ABS_TILT_Y:
70                 mAbsTiltY = rawEvent->value;
71                 break;
72         }
73     }
74 }
75 
76 } // namespace android
77