Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 1 | /* |
| 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 Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 17 | #include <fstream> |
| 18 | |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 19 | #include "TouchscreenGesture.h" |
| 20 | |
| 21 | namespace vendor { |
| 22 | namespace lineage { |
| 23 | namespace touch { |
| 24 | namespace V1_0 { |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 25 | namespace samsung { |
| 26 | |
| 27 | static constexpr const char* kGeasturePath = "/sys/class/sec/sec_epen/epen_gestures"; |
| 28 | |
| 29 | const std::map<int32_t, TouchscreenGesture::GestureInfo> TouchscreenGesture::kGestureInfoMap = { |
Jan Altensen | 6f3af5a | 2019-07-20 01:00:46 +0200 | [diff] [blame] | 30 | // clang-format off |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 31 | {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 Altensen | 6f3af5a | 2019-07-20 01:00:46 +0200 | [diff] [blame] | 36 | // clang-format on |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 37 | }; |
| 38 | |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 39 | bool TouchscreenGesture::isSupported() { |
| 40 | std::ifstream file(kGeasturePath); |
| 41 | return file.good(); |
| 42 | } |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 43 | |
| 44 | // Methods from ::vendor::lineage::touch::V1_0::ITouchscreenGesture follow. |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 45 | Return<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 Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 53 | return Void(); |
| 54 | } |
| 55 | |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 56 | Return<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 Altensen | 6f3af5a | 2019-07-20 01:00:46 +0200 | [diff] [blame] | 61 | |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 62 | file >> gestureMode; |
| 63 | |
| 64 | if (enabled) |
| 65 | gestureMode |= mask; |
| 66 | else |
| 67 | gestureMode &= ~mask; |
| 68 | |
| 69 | file << gestureMode; |
| 70 | |
| 71 | return !file.fail(); |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 72 | } |
| 73 | |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 74 | // Methods from ::android::hidl::base::V1_0::IBase follow. |
| 75 | |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 76 | } // namespace samsung |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 77 | } // namespace V1_0 |
| 78 | } // namespace touch |
| 79 | } // namespace lineage |
| 80 | } // namespace vendor |