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 "GloveMode.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 { |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 26 | |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 27 | bool GloveMode::isSupported() { |
| 28 | std::ifstream file("/sys/class/sec/tsp/cmd_list"); |
| 29 | if (file.is_open()) { |
| 30 | std::string line; |
| 31 | while (getline(file, line)) { |
| 32 | if (!line.compare("glove_mode")) |
| 33 | return true; |
| 34 | } |
| 35 | file.close(); |
| 36 | } |
| 37 | return false; |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 38 | } |
| 39 | |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 40 | // Methods from ::vendor::lineage::touch::V1_0::IGloveMode follow. |
| 41 | Return<bool> GloveMode::isEnabled() { |
| 42 | std::ifstream file("/sys/class/sec/tsp/cmd_result"); |
| 43 | if (file.is_open()) { |
| 44 | std::string line; |
| 45 | getline(file, line); |
| 46 | if (!line.compare("glove_mode,1:OK")) |
| 47 | return true; |
| 48 | file.close(); |
| 49 | } |
| 50 | return false; |
| 51 | } |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 52 | |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 53 | Return<bool> GloveMode::setEnabled(bool enabled) { |
| 54 | std::ofstream file("/sys/class/sec/tsp/cmd"); |
| 55 | file << "glove_mode," << (enabled ? "1" : "0"); |
| 56 | return true; |
| 57 | } |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 58 | |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 59 | } // namespace samsung |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 60 | } // namespace V1_0 |
| 61 | } // namespace touch |
| 62 | } // namespace lineage |
| 63 | } // namespace vendor |