blob: a78bbc5c942cc2a8807de76902fa51e964ea5f93 [file] [log] [blame]
Siarhei Vishniakoua0e7f732018-01-17 11:49:04 -08001/*
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
Siarhei Vishniakou45c1d0c2019-01-24 10:38:02 -080024using namespace android::hardware::input::common::V1_0;
Siarhei Vishniakoua0e7f732018-01-17 11:49:04 -080025
26namespace android {
27namespace hardware {
28namespace input {
29namespace classifier {
30namespace V1_0 {
31namespace implementation {
32
33// Methods from ::android::hardware::input::classifier::V1_0::IInputClassifier follow.
34Return<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
Siarhei Vishniakouba9d3c82019-01-23 15:14:20 -080060Return<void> InputClassifier::reset() {
61 // We don't have any internal state in this example implementation,
62 // so no work needed here.
63 return Void();
64}
65
66Return<void> InputClassifier::resetDevice(int32_t /*deviceId*/) {
67 // We don't have any internal per-device state in this example implementation,
68 // so no work needed here.
69 return Void();
70}
71
Siarhei Vishniakoua0e7f732018-01-17 11:49:04 -080072} // namespace implementation
73} // namespace V1_0
74} // namespace classifier
75} // namespace input
76} // namespace hardware
77} // namespace android