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