1 /*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "processing_finger_device.h"
17
18 #undef MMI_LOG_TAG
19 #define MMI_LOG_TAG "ProcessingFingerDevice"
20
21 namespace OHOS {
22 namespace MMI {
23 namespace {
24 constexpr int64_t FINGER_BLOCK_TIME { 6 };
25 } // namespace
26
TransformJsonDataToInputData(const DeviceItem & fingerEventArrays,InputEventArray & inputEventArray)27 int32_t ProcessingFingerDevice::TransformJsonDataToInputData(const DeviceItem &fingerEventArrays,
28 InputEventArray &inputEventArray)
29 {
30 CALL_DEBUG_ENTER;
31 std::vector<DeviceEvent> inputData = fingerEventArrays.events;
32 if (inputData.empty()) {
33 MMI_HILOGE("Manage finger array failed, inputData is empty");
34 return RET_ERR;
35 }
36 TouchPadInputEvents touchPadInputEvents = {};
37 AnalysisTouchPadFingerDate(inputData, touchPadInputEvents);
38 if (touchPadInputEvents.eventArray.empty()) {
39 MMI_HILOGE("The eventArray is empty");
40 return RET_ERR;
41 }
42 TouchPadInputEvent pressEvents = touchPadInputEvents.eventArray[0];
43 AnalysisTouchPadFingerPressData(inputEventArray, pressEvents);
44 for (uint64_t i = 1; i < touchPadInputEvents.eventNumber; i++) {
45 AnalysisTouchPadFingerMoveData(inputEventArray, touchPadInputEvents.eventArray[i]);
46 }
47 uint64_t releaseEventIndex = touchPadInputEvents.eventNumber - 1;
48 TouchPadInputEvent releaseEvents = touchPadInputEvents.eventArray[releaseEventIndex];
49 AnalysisTouchPadFingerReleaseData(inputEventArray, releaseEvents);
50 return RET_OK;
51 }
52
AnalysisTouchPadFingerDate(const std::vector<DeviceEvent> & inputData,TouchPadInputEvents & touchPadInputEvents)53 void ProcessingFingerDevice::AnalysisTouchPadFingerDate(const std::vector<DeviceEvent> &inputData,
54 TouchPadInputEvents &touchPadInputEvents)
55 {
56 TouchPadCoordinates touchPadCoordinates = {};
57 TouchPadInputEvent touchPadInputEvent = {};
58 for (const auto &item : inputData) {
59 touchPadInputEvent.groupNumber = 0;
60 for (const auto &posXYItem : item.posXY) {
61 touchPadCoordinates.xPos = posXYItem.xPos;
62 touchPadCoordinates.yPos = posXYItem.yPos;
63 touchPadInputEvent.events.push_back(touchPadCoordinates);
64 ++touchPadInputEvent.groupNumber;
65 }
66 touchPadInputEvents.eventNumber = inputData.size();
67 touchPadInputEvents.eventArray.push_back(touchPadInputEvent);
68 touchPadInputEvent.events.clear();
69 }
70 }
71
AnalysisTouchPadFingerPressData(InputEventArray & inputEventArray,const TouchPadInputEvent & touchPadInputEvent)72 void ProcessingFingerDevice::AnalysisTouchPadFingerPressData(InputEventArray &inputEventArray,
73 const TouchPadInputEvent &touchPadInputEvent)
74 {
75 int32_t yPos = 0;
76 int32_t xPos = 0;
77 for (uint64_t i = 0; i < static_cast<uint64_t>(touchPadInputEvent.groupNumber); i++) {
78 yPos = touchPadInputEvent.events[i].yPos;
79 xPos = touchPadInputEvent.events[i].xPos;
80 if (touchPadInputEvent.groupNumber > 1) {
81 SetMtSlot(inputEventArray, FINGER_BLOCK_TIME, static_cast<int32_t>(i));
82 }
83 SetTrackingId(inputEventArray, FINGER_BLOCK_TIME);
84 SetPositionX(inputEventArray, FINGER_BLOCK_TIME, xPos);
85 SetPositionY(inputEventArray, FINGER_BLOCK_TIME, yPos);
86 SetMtTouchMajor(inputEventArray, FINGER_BLOCK_TIME, 1);
87 SetMtTouchMinor(inputEventArray, FINGER_BLOCK_TIME, 1);
88 SetBtnTouch(inputEventArray, FINGER_BLOCK_TIME, 1);
89 SetMtTouchFingerType(inputEventArray, FINGER_BLOCK_TIME,
90 static_cast<int32_t>(touchPadInputEvent.groupNumber), 1);
91 SetEvAbsX(inputEventArray, FINGER_BLOCK_TIME, xPos);
92 SetEvAbsY(inputEventArray, FINGER_BLOCK_TIME, yPos);
93 }
94 SetSynReport(inputEventArray);
95 }
96
AnalysisTouchPadFingerMoveData(InputEventArray & inputEventArray,const TouchPadInputEvent & touchPadInputEvent)97 void ProcessingFingerDevice::AnalysisTouchPadFingerMoveData(InputEventArray &inputEventArray,
98 const TouchPadInputEvent &touchPadInputEvent)
99 {
100 int32_t xPos = 0;
101 int32_t yPos = 0;
102 for (uint64_t i = 0; i < static_cast<uint64_t>(touchPadInputEvent.groupNumber); i++) {
103 xPos = touchPadInputEvent.events[i].xPos;
104 yPos = touchPadInputEvent.events[i].yPos;
105 if (touchPadInputEvent.groupNumber > 1) {
106 SetMtSlot(inputEventArray, FINGER_BLOCK_TIME, static_cast<int32_t>(i));
107 }
108 SetPositionX(inputEventArray, FINGER_BLOCK_TIME, xPos);
109 SetPositionY(inputEventArray, FINGER_BLOCK_TIME, yPos);
110 SetMtTouchMajor(inputEventArray, FINGER_BLOCK_TIME, 1);
111 SetMtTouchMinor(inputEventArray, FINGER_BLOCK_TIME, 1);
112 SetEvAbsX(inputEventArray, FINGER_BLOCK_TIME, xPos);
113 SetEvAbsY(inputEventArray, FINGER_BLOCK_TIME, yPos);
114 }
115 SetSynReport(inputEventArray);
116 }
117
AnalysisTouchPadFingerReleaseData(InputEventArray & inputEventArray,const TouchPadInputEvent & touchPadInputEvent)118 void ProcessingFingerDevice::AnalysisTouchPadFingerReleaseData(InputEventArray &inputEventArray,
119 const TouchPadInputEvent &touchPadInputEvent)
120 {
121 for (uint64_t i = 0; i < static_cast<uint64_t>(touchPadInputEvent.groupNumber); i++) {
122 if (touchPadInputEvent.groupNumber > 1) {
123 SetMtSlot(inputEventArray, FINGER_BLOCK_TIME, static_cast<int32_t>(i));
124 }
125 SetTrackingId(inputEventArray, FINGER_BLOCK_TIME, -1);
126 SetBtnTouch(inputEventArray, FINGER_BLOCK_TIME, 0);
127 SetMtTouchFingerType(inputEventArray, FINGER_BLOCK_TIME,
128 static_cast<int32_t>(touchPadInputEvent.groupNumber), 0);
129 }
130 SetSynReport(inputEventArray);
131 }
132 } // namespace MMI
133 } // namespace OHOS
134