blob: f059b61eab479ec6038f8c13205bb2a609e7b79b [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 "GloveMode.h"
20
21namespace vendor {
22namespace lineage {
23namespace touch {
24namespace V1_0 {
Paul Keith2b27b272019-01-09 00:11:40 +010025namespace samsung {
Paul Keith5b3bd862019-01-08 23:45:03 +010026
Paul Keith2b27b272019-01-09 00:11:40 +010027bool 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)) {
Jan Altensen6f3af5a2019-07-20 01:00:46 +020032 if (!line.compare("glove_mode")) return true;
Paul Keith2b27b272019-01-09 00:11:40 +010033 }
34 file.close();
35 }
36 return false;
Paul Keith5b3bd862019-01-08 23:45:03 +010037}
38
Paul Keith2b27b272019-01-09 00:11:40 +010039// Methods from ::vendor::lineage::touch::V1_0::IGloveMode follow.
40Return<bool> GloveMode::isEnabled() {
41 std::ifstream file("/sys/class/sec/tsp/cmd_result");
42 if (file.is_open()) {
43 std::string line;
44 getline(file, line);
Jan Altensen6f3af5a2019-07-20 01:00:46 +020045 if (!line.compare("glove_mode,1:OK")) return true;
Paul Keith2b27b272019-01-09 00:11:40 +010046 file.close();
47 }
48 return false;
49}
Paul Keith5b3bd862019-01-08 23:45:03 +010050
Paul Keith2b27b272019-01-09 00:11:40 +010051Return<bool> GloveMode::setEnabled(bool enabled) {
52 std::ofstream file("/sys/class/sec/tsp/cmd");
53 file << "glove_mode," << (enabled ? "1" : "0");
54 return true;
55}
Paul Keith5b3bd862019-01-08 23:45:03 +010056
Paul Keith2b27b272019-01-09 00:11:40 +010057} // namespace samsung
Paul Keith5b3bd862019-01-08 23:45:03 +010058} // namespace V1_0
59} // namespace touch
60} // namespace lineage
61} // namespace vendor