Siarhei Vishniakou | a0e7f73 | 2018-01-17 11:49:04 -0800 | [diff] [blame^] | 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 | #define LOG_TAG "InputClassifierHAL" |
| 18 | |
| 19 | #include "InputClassifier.h" |
| 20 | #include <inttypes.h> |
| 21 | #include <log/log.h> |
| 22 | #include <utils/Timers.h> |
| 23 | |
| 24 | using namespace android::hardware::input::classifier::V1_0; |
| 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace input { |
| 29 | namespace classifier { |
| 30 | namespace V1_0 { |
| 31 | namespace implementation { |
| 32 | |
| 33 | // Methods from ::android::hardware::input::classifier::V1_0::IInputClassifier follow. |
| 34 | Return<Classification> InputClassifier::classify(const MotionEvent& event) { |
| 35 | /** |
| 36 | * In this example implementation, we will see how many "pixels" inside the video frame |
| 37 | * exceed the value of 250. If more than 6 such pixels are present, then treat the event |
| 38 | * as a "DEEP_PRESS". |
| 39 | */ |
| 40 | if (event.frames.size() == 0) { |
| 41 | return Classification::NONE; |
| 42 | } |
| 43 | ALOGI("Frame(O) timestamp = %" PRIu64 ", received %zu frame(s)", event.frames[0].timestamp, |
| 44 | event.frames.size()); |
| 45 | for (const VideoFrame& frame : event.frames) { |
| 46 | size_t count = 0; |
| 47 | for (size_t i = 0; i < frame.data.size(); i++) { |
| 48 | if (frame.data[i] > 250) { |
| 49 | count++; |
| 50 | } |
| 51 | } |
| 52 | if (count > 6) { |
| 53 | return Classification::DEEP_PRESS; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return Classification::NONE; |
| 58 | } |
| 59 | |
| 60 | } // namespace implementation |
| 61 | } // namespace V1_0 |
| 62 | } // namespace classifier |
| 63 | } // namespace input |
| 64 | } // namespace hardware |
| 65 | } // namespace android |