1 /*
2 * Copyright (c) 2021-2022 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 namespace OHOS {
19 namespace MMI {
20 namespace {
21 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "ProcessingFingerDevice" };
22 constexpr int64_t FINGER_BLOCK_TIME = 6;
23 } // namespace
24
TransformJsonDataToInputData(const DeviceItem & fingerEventArrays,InputEventArray & inputEventArray)25 int32_t ProcessingFingerDevice::TransformJsonDataToInputData(const DeviceItem &fingerEventArrays,
26 InputEventArray &inputEventArray)
27 {
28 CALL_DEBUG_ENTER;
29 std::vector<DeviceEvent> inputData = fingerEventArrays.events;
30 if (inputData.empty()) {
31 MMI_HILOGE("Manage finger array failed, inputData is empty.");
32 return RET_ERR;
33 }
34 TouchPadInputEvents touchPadInputEvents = {};
35 AnalysisTouchPadFingerDate(inputData, touchPadInputEvents);
36 TouchPadInputEvent pressEvents = touchPadInputEvents.eventArray[0];
37 AnalysisTouchPadFingerPressData(inputEventArray, pressEvents);
38 for (uint64_t i = 1; i < touchPadInputEvents.eventNumber; i++) {
39 AnalysisTouchPadFingerMoveData(inputEventArray, touchPadInputEvents.eventArray[i]);
40 }
41 uint64_t releaseEventIndex = touchPadInputEvents.eventNumber - 1;
42 TouchPadInputEvent releaseEvents = touchPadInputEvents.eventArray[releaseEventIndex];
43 AnalysisTouchPadFingerReleaseData(inputEventArray, releaseEvents);
44 return RET_OK;
45 }
46
AnalysisTouchPadFingerDate(const std::vector<DeviceEvent> & inputData,TouchPadInputEvents & touchPadInputEvents)47 void ProcessingFingerDevice::AnalysisTouchPadFingerDate(const std::vector<DeviceEvent> &inputData,
48 TouchPadInputEvents &touchPadInputEvents)
49 {
50 TouchPadCoordinates touchPadCoordinates = {};
51 TouchPadInputEvent touchPadInputEvent = {};
52 for (const auto &item : inputData) {
53 touchPadInputEvent.groupNumber = 0;
54 for (const auto &posXYItem : item.posXY) {
55 touchPadCoordinates.xPos = posXYItem.xPos;
56 touchPadCoordinates.yPos = posXYItem.yPos;
57 touchPadInputEvent.events.push_back(touchPadCoordinates);
58 ++touchPadInputEvent.groupNumber;
59 }
60 touchPadInputEvents.eventNumber = inputData.size();
61 touchPadInputEvents.eventArray.push_back(touchPadInputEvent);
62 touchPadInputEvent.events.clear();
63 }
64 }
65
AnalysisTouchPadFingerPressData(InputEventArray & inputEventArray,const TouchPadInputEvent & touchPadInputEvent)66 void ProcessingFingerDevice::AnalysisTouchPadFingerPressData(InputEventArray &inputEventArray,
67 const TouchPadInputEvent &touchPadInputEvent)
68 {
69 int32_t yPos = 0;
70 int32_t xPos = 0;
71 for (uint64_t i = 0; i < static_cast<uint64_t>(touchPadInputEvent.groupNumber); i++) {
72 yPos = touchPadInputEvent.events[i].yPos;
73 xPos = touchPadInputEvent.events[i].xPos;
74 if (touchPadInputEvent.groupNumber > 1) {
75 SetMtSlot(inputEventArray, FINGER_BLOCK_TIME, static_cast<int32_t>(i));
76 }
77 SetTrackingId(inputEventArray, FINGER_BLOCK_TIME);
78 SetPositionX(inputEventArray, FINGER_BLOCK_TIME, xPos);
79 SetPositionY(inputEventArray, FINGER_BLOCK_TIME, yPos);
80 SetMtTouchMajor(inputEventArray, FINGER_BLOCK_TIME, 1);
81 SetMtTouchMinor(inputEventArray, FINGER_BLOCK_TIME, 1);
82 SetBtnTouch(inputEventArray, FINGER_BLOCK_TIME, 1);
83 SetMtTouchFingerType(inputEventArray, FINGER_BLOCK_TIME,
84 static_cast<int32_t>(touchPadInputEvent.groupNumber), 1);
85 SetEvAbsX(inputEventArray, FINGER_BLOCK_TIME, xPos);
86 SetEvAbsY(inputEventArray, FINGER_BLOCK_TIME, yPos);
87 }
88 SetSynReport(inputEventArray);
89 }
90
AnalysisTouchPadFingerMoveData(InputEventArray & inputEventArray,const TouchPadInputEvent & touchPadInputEvent)91 void ProcessingFingerDevice::AnalysisTouchPadFingerMoveData(InputEventArray &inputEventArray,
92 const TouchPadInputEvent &touchPadInputEvent)
93 {
94 int32_t xPos = 0;
95 int32_t yPos = 0;
96 for (uint64_t i = 0; i < static_cast<uint64_t>(touchPadInputEvent.groupNumber); i++) {
97 xPos = touchPadInputEvent.events[i].xPos;
98 yPos = touchPadInputEvent.events[i].yPos;
99 if (touchPadInputEvent.groupNumber > 1) {
100 SetMtSlot(inputEventArray, FINGER_BLOCK_TIME, static_cast<int32_t>(i));
101 }
102 SetPositionX(inputEventArray, FINGER_BLOCK_TIME, xPos);
103 SetPositionY(inputEventArray, FINGER_BLOCK_TIME, yPos);
104 SetMtTouchMajor(inputEventArray, FINGER_BLOCK_TIME, 1);
105 SetMtTouchMinor(inputEventArray, FINGER_BLOCK_TIME, 1);
106 SetEvAbsX(inputEventArray, FINGER_BLOCK_TIME, xPos);
107 SetEvAbsY(inputEventArray, FINGER_BLOCK_TIME, yPos);
108 }
109 SetSynReport(inputEventArray);
110 }
111
AnalysisTouchPadFingerReleaseData(InputEventArray & inputEventArray,const TouchPadInputEvent & touchPadInputEvent)112 void ProcessingFingerDevice::AnalysisTouchPadFingerReleaseData(InputEventArray &inputEventArray,
113 const TouchPadInputEvent &touchPadInputEvent)
114 {
115 for (uint64_t i = 0; i < static_cast<uint64_t>(touchPadInputEvent.groupNumber); i++) {
116 if (touchPadInputEvent.groupNumber > 1) {
117 SetMtSlot(inputEventArray, FINGER_BLOCK_TIME, static_cast<int32_t>(i));
118 }
119 SetTrackingId(inputEventArray, FINGER_BLOCK_TIME, -1);
120 SetBtnTouch(inputEventArray, FINGER_BLOCK_TIME, 0);
121 SetMtTouchFingerType(inputEventArray, FINGER_BLOCK_TIME,
122 static_cast<int32_t>(touchPadInputEvent.groupNumber), 0);
123 }
124 SetSynReport(inputEventArray);
125 }
126 } // namespace MMI
127 } // namespace OHOS
128