blob: dcac846a3d493195718b01e70af6d742a3350aae [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)) {
32 if (!line.compare("glove_mode"))
33 return true;
34 }
35 file.close();
36 }
37 return false;
Paul Keith5b3bd862019-01-08 23:45:03 +010038}
39
Paul Keith2b27b272019-01-09 00:11:40 +010040// Methods from ::vendor::lineage::touch::V1_0::IGloveMode follow.
41Return<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 Keith5b3bd862019-01-08 23:45:03 +010052
Paul Keith2b27b272019-01-09 00:11:40 +010053Return<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 Keith5b3bd862019-01-08 23:45:03 +010058
Paul Keith2b27b272019-01-09 00:11:40 +010059} // namespace samsung
Paul Keith5b3bd862019-01-08 23:45:03 +010060} // namespace V1_0
61} // namespace touch
62} // namespace lineage
63} // namespace vendor