summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornotsyncing <song.fc@gmail.com>2018-06-06 14:26:47 +0200
committerSimon Shi <simonsmh@gmail.com>2019-01-16 09:43:42 +0100
commitc7c78d2fea4e9a53da09657ccb4155ec1344bd03 (patch)
tree05e8fd1920ed51b16b35fe89447f181076952794
parentminuitwrp: Respect TARGET_RECOVERY_PIXEL_FORMAT config. (diff)
downloadandroid_bootable_recovery-c7c78d2fea4e9a53da09657ccb4155ec1344bd03.tar
android_bootable_recovery-c7c78d2fea4e9a53da09657ccb4155ec1344bd03.tar.gz
android_bootable_recovery-c7c78d2fea4e9a53da09657ccb4155ec1344bd03.tar.bz2
android_bootable_recovery-c7c78d2fea4e9a53da09657ccb4155ec1344bd03.tar.lz
android_bootable_recovery-c7c78d2fea4e9a53da09657ccb4155ec1344bd03.tar.xz
android_bootable_recovery-c7c78d2fea4e9a53da09657ccb4155ec1344bd03.tar.zst
android_bootable_recovery-c7c78d2fea4e9a53da09657ccb4155ec1344bd03.zip
-rw-r--r--minuitwrp/events.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/minuitwrp/events.cpp b/minuitwrp/events.cpp
index 94b800ea6..bd29f718d 100644
--- a/minuitwrp/events.cpp
+++ b/minuitwrp/events.cpp
@@ -26,7 +26,7 @@
#include <unistd.h>
#include <stdio.h>
#include <string.h>
-
+#include <fstream>
#include "../common.h"
@@ -39,6 +39,9 @@
#define VIBRATOR_TIMEOUT_FILE "/sys/class/timed_output/vibrator/enable"
#define VIBRATOR_TIME_MS 50
+#define LEDS_HAPTICS_DURATION_FILE "/sys/class/leds/vibrator/duration"
+#define LEDS_HAPTICS_ACTIVATE_FILE "/sys/class/leds/vibrator/activate"
+
#ifndef SYN_REPORT
#define SYN_REPORT 0x00
#endif
@@ -108,24 +111,27 @@ static inline int ABS(int x) {
return x<0?-x:x;
}
+int write_to_file(const std::string& fn, const std::string& line) {
+ FILE *file;
+ file = fopen(fn.c_str(), "w");
+ if (file != NULL) {
+ fwrite(line.c_str(), line.size(), 1, file);
+ fclose(file);
+ return 0;
+ }
+ LOGI("Cannot find file %s\n", fn.c_str());
+ return -1;
+}
+
int vibrate(int timeout_ms)
{
- char str[20];
- int fd;
- int ret;
-
if (timeout_ms > 10000) timeout_ms = 1000;
- fd = open(VIBRATOR_TIMEOUT_FILE, O_WRONLY);
- if (fd < 0)
- return -1;
-
- ret = snprintf(str, sizeof(str), "%d", timeout_ms);
- ret = write(fd, str, ret);
- close(fd);
-
- if (ret < 0)
- return -1;
+ if (std::ifstream(LEDS_HAPTICS_ACTIVATE_FILE).good()) {
+ write_to_file(LEDS_HAPTICS_DURATION_FILE, std::to_string(timeout_ms));
+ write_to_file(LEDS_HAPTICS_ACTIVATE_FILE, "1");
+ } else
+ write_to_file(VIBRATOR_TIMEOUT_FILE, std::to_string(timeout_ms));
return 0;
}