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