56 lines
1.5 KiB
Diff
56 lines
1.5 KiB
Diff
From f384120189427f03fa4c3b20849e4f71b864351e Mon Sep 17 00:00:00 2001
|
|
From: Arian <arian.kulmer@web.de>
|
|
Date: Wed, 29 Mar 2023 17:38:34 +0200
|
|
Subject: [PATCH 12/15] sensors: Handle fod press status without coordinates
|
|
|
|
Also fix the error handling of sscanf which returns the
|
|
number of matched variables on partial success.
|
|
|
|
Change-Id: I785c0e3f73e89f79addcf18e1b5111e93e25e430
|
|
---
|
|
sensors/Sensor.cpp | 28 ++++++++++++++++++++++++++++
|
|
1 file changed, 28 insertions(+)
|
|
|
|
diff --git a/sensors/Sensor.cpp b/sensors/Sensor.cpp
|
|
index 646e852..4fcfd86 100644
|
|
--- a/sensors/Sensor.cpp
|
|
+++ b/sensors/Sensor.cpp
|
|
@@ -45,6 +45,34 @@ static bool readBool(int fd, bool seek) {
|
|
return c != '0';
|
|
}
|
|
|
|
+static bool readFpState(int fd, int& screenX, int& screenY) {
|
|
+ char buffer[512];
|
|
+ int state = 0;
|
|
+ int rc;
|
|
+ rc = lseek(fd, 0, SEEK_SET);
|
|
+ if (rc) {
|
|
+ ALOGE("failed to seek: %d", rc);
|
|
+ return false;
|
|
+ }
|
|
+ rc = read(fd, &buffer, sizeof(buffer));
|
|
+ if (rc < 0) {
|
|
+ ALOGE("failed to read state: %d", rc);
|
|
+ return false;
|
|
+ }
|
|
+ rc = sscanf(buffer, "%d,%d,%d", &screenX, &screenY, &state);
|
|
+ if (rc == 1) {
|
|
+ // If only the first variable can be matched assume
|
|
+ // that the node only reports the state
|
|
+ state = screenX;
|
|
+ screenX = 0;
|
|
+ screenY = 0;
|
|
+ } else if (rc < 3) {
|
|
+ ALOGE("failed to parse fp state: %d", rc);
|
|
+ return false;
|
|
+ }
|
|
+ return state > 0;
|
|
+}
|
|
+
|
|
} // anonymous namespace
|
|
|
|
namespace android {
|
|
--
|
|
2.25.1
|
|
|