blob: c0091a6d57d7bf37a671f7bc70d481873b8349af [file] [log] [blame]
Paul Keith5b3bd862019-01-08 23:45:03 +01001/*
2 * Copyright (C) 2019 The LineageOS 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
Paul Keith2b27b272019-01-09 00:11:40 +010017#include <fstream>
18
Paul Keith5b3bd862019-01-08 23:45:03 +010019#include "TouchscreenGesture.h"
20
21namespace vendor {
22namespace lineage {
23namespace touch {
24namespace V1_0 {
Paul Keith2b27b272019-01-09 00:11:40 +010025namespace samsung {
26
27static constexpr const char* kGeasturePath = "/sys/class/sec/sec_epen/epen_gestures";
28
29const std::map<int32_t, TouchscreenGesture::GestureInfo> TouchscreenGesture::kGestureInfoMap = {
Jan Altensen6f3af5a2019-07-20 01:00:46 +020030 // clang-format off
Paul Keith2b27b272019-01-09 00:11:40 +010031 {0, {0x2f1, "Swipe up stylus"}},
32 {1, {0x2f2, "Swipe down stylus"}},
33 {2, {0x2f3, "Swipe left stylus"}},
34 {3, {0x2f4, "Swipe right stylus"}},
35 {4, {0x2f5, "Long press stylus"}},
Jan Altensen6f3af5a2019-07-20 01:00:46 +020036 // clang-format on
Paul Keith2b27b272019-01-09 00:11:40 +010037};
38
Paul Keith2b27b272019-01-09 00:11:40 +010039bool TouchscreenGesture::isSupported() {
40 std::ifstream file(kGeasturePath);
41 return file.good();
42}
Paul Keith5b3bd862019-01-08 23:45:03 +010043
44// Methods from ::vendor::lineage::touch::V1_0::ITouchscreenGesture follow.
Paul Keith2b27b272019-01-09 00:11:40 +010045Return<void> TouchscreenGesture::getSupportedGestures(getSupportedGestures_cb resultCb) {
46 std::vector<Gesture> gestures;
47
48 for (const auto& entry : kGestureInfoMap) {
49 gestures.push_back({entry.first, entry.second.name, entry.second.keycode});
50 }
51 resultCb(gestures);
52
Paul Keith5b3bd862019-01-08 23:45:03 +010053 return Void();
54}
55
Paul Keith2b27b272019-01-09 00:11:40 +010056Return<bool> TouchscreenGesture::setGestureEnabled(
57 const ::vendor::lineage::touch::V1_0::Gesture& gesture, bool enabled) {
58 std::fstream file(kGeasturePath);
59 int gestureMode;
60 int mask = 1 << gesture.id;
Jan Altensen6f3af5a2019-07-20 01:00:46 +020061
Paul Keith2b27b272019-01-09 00:11:40 +010062 file >> gestureMode;
63
64 if (enabled)
65 gestureMode |= mask;
66 else
67 gestureMode &= ~mask;
68
69 file << gestureMode;
70
71 return !file.fail();
Paul Keith5b3bd862019-01-08 23:45:03 +010072}
73
Paul Keith5b3bd862019-01-08 23:45:03 +010074// Methods from ::android::hidl::base::V1_0::IBase follow.
75
Paul Keith2b27b272019-01-09 00:11:40 +010076} // namespace samsung
Paul Keith5b3bd862019-01-08 23:45:03 +010077} // namespace V1_0
78} // namespace touch
79} // namespace lineage
80} // namespace vendor