-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoverride_max_pressure.cc
54 lines (46 loc) · 1.49 KB
/
override_max_pressure.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/* override_max_pressure: This command line tool is designed to override the max
* pressure of the target device under /dev/input/
* Usage:
* $override_max_pressure --device=event4 --maxpressure=2048
*/
#include <linux/input.h>
#include <iostream>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <brillo/flag_helper.h>
int main(int argc, char **argv) {
DEFINE_string(device, "", "Path of the device");
DEFINE_int32(maxpressure, -1,
"Max pressure to override.");
brillo::FlagHelper::Init(
argc, argv, "override_stylus_pressure, Override max pressure of device.");
if (FLAGS_device == "") {
LOG(ERROR) << "Please provide path to the device";
exit(1);
}
if (FLAGS_maxpressure < 0) {
LOG(ERROR) << "Please set max pressure to a non-negative value";
exit(1);
}
std::string dev_path = "/dev/input/" + FLAGS_device;
int fd = open(dev_path.c_str(), O_RDONLY | O_CLOEXEC);
if (fd < 0) {
PLOG(ERROR) << "Cannot open device: " << dev_path;
exit(1);
}
input_absinfo absinfo;
if (ioctl(fd, EVIOCGABS(ABS_PRESSURE), &absinfo)) {
PLOG(ERROR) << "ioctl EVIOCGABS falied";
exit(1);
}
absinfo.maximum = FLAGS_maxpressure;
if (ioctl(fd, EVIOCSABS(ABS_PRESSURE), &absinfo)) {
PLOG(ERROR) << "ioctl EVIOCSABS falied";
exit(1);
}
return 0;
}