From f4b38ef0d8c0fd6a3d634212c69694211163a1e7 Mon Sep 17 00:00:00 2001 From: Hikari-no-Tenshi Date: Thu, 14 Nov 2019 10:32:07 +0200 Subject: [PATCH] tri-state-key: Add hall sensor calibration support Change-Id: I8449041eec5c8ab4153bd2942ebc7fda9ceb743e --- tri-state-key/main.cpp | 11 +++++++++++ tri-state-key/tri-state-key_daemon.rc | 3 +++ 2 files changed, 14 insertions(+) diff --git a/tri-state-key/main.cpp b/tri-state-key/main.cpp index a0ad12d..9cc8ec3 100644 --- a/tri-state-key/main.cpp +++ b/tri-state-key/main.cpp @@ -16,6 +16,7 @@ #define LOG_TAG "tri-state-key_daemon" +#include #include #include #include @@ -24,10 +25,15 @@ #include "uevent_listener.h" +#define HALL_CALIBRATION_DATA "/sys/devices/platform/soc/soc:tri_state_key/hall_data_calib" +#define HALL_PERSIST_CALIBRATION_DATA "/mnt/vendor/persist/engineermode/tri_state_hall_data" + #define KEY_MODE_NORMAL 601 #define KEY_MODE_VIBRATION 602 #define KEY_MODE_SILENCE 603 +using android::base::ReadFileToString; +using android::base::WriteStringToFile; using android::Uevent; using android::UeventListener; @@ -39,6 +45,11 @@ int main() { LOG(INFO) << "Started"; + if (std::string hallData; ReadFileToString(HALL_PERSIST_CALIBRATION_DATA, &hallData)) { + std::replace(hallData.begin(), hallData.end(), ';', ','); + WriteStringToFile(hallData, HALL_CALIBRATION_DATA); + } + uinputFd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); if (uinputFd < 0) { LOG(ERROR) << "Unable to open uinput node"; diff --git a/tri-state-key/tri-state-key_daemon.rc b/tri-state-key/tri-state-key_daemon.rc index 028d472..0886ab9 100644 --- a/tri-state-key/tri-state-key_daemon.rc +++ b/tri-state-key/tri-state-key_daemon.rc @@ -1,4 +1,7 @@ on fs + chown system system /sys/devices/platform/soc/soc:tri_state_key/hall_data_calib + chown system system /mnt/vendor/persist/engineermode/tri_state_hall_data + start tri-state-key_daemon service tri-state-key_daemon /vendor/bin/tri-state-key_daemon