summaryrefslogtreecommitdiffstats
path: root/vibrator
diff options
context:
space:
mode:
authorDemon000 <demonsingur@gmail.com>2017-10-01 21:25:26 +0300
committerDemon Singur <demonsingur@gmail.com>2017-12-23 13:03:49 +0000
commitc94981d5d288cad2222e40f10a5893f93002f839 (patch)
treebbeffb19369960428afb9dfb277f575b8782206f /vibrator
parenta0c7eddf3c545e28a52f60548fe2c15af86f3e54 (diff)
downloadandroid_hardware_lineage_interfaces-c94981d5d288cad2222e40f10a5893f93002f839.tar.gz
android_hardware_lineage_interfaces-c94981d5d288cad2222e40f10a5893f93002f839.tar.bz2
android_hardware_lineage_interfaces-c94981d5d288cad2222e40f10a5893f93002f839.zip
lineage/interfaces: vibrator: add binderized service
The timed output device must be at "/sys/devices/virtual/timed_output/vibrator" and provide the following sysfs entries: * "vtg_min", used to get the minimum allowed voltage * "vtg_max", used to get the maximum allowed voltage * "vtg_level", used to set the voltage within vtg_min and vtg_max range To use this, add PRODUCT_PACKAGES += \ android.hardware.vibrator@1.0-service.lineage Change-Id: I8bc1f4386fd04b4943a5ccb38ddfac333a7530d2
Diffstat (limited to 'vibrator')
-rw-r--r--vibrator/1.0-lineage/Android.bp31
-rw-r--r--vibrator/1.0-lineage/Vibrator.cpp162
-rw-r--r--vibrator/1.0-lineage/Vibrator.h49
-rw-r--r--vibrator/1.0-lineage/android.hardware.vibrator@1.0-service.lineage.rc12
-rw-r--r--vibrator/1.0-lineage/service.cpp49
-rw-r--r--vibrator/Android.bp4
6 files changed, 307 insertions, 0 deletions
diff --git a/vibrator/1.0-lineage/Android.bp b/vibrator/1.0-lineage/Android.bp
new file mode 100644
index 0000000..2151e68
--- /dev/null
+++ b/vibrator/1.0-lineage/Android.bp
@@ -0,0 +1,31 @@
+//
+// Copyright (C) 2017 The LineageOS Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_binary {
+ name: "android.hardware.vibrator@1.0-service.lineage",
+ relative_install_path: "hw",
+ init_rc: ["android.hardware.vibrator@1.0-service.lineage.rc"],
+ srcs: ["service.cpp", "Vibrator.cpp"],
+ shared_libs: [
+ "libhidlbase",
+ "libhidltransport",
+ "liblog",
+ "libhwbinder",
+ "libutils",
+ "libhardware",
+ "android.hardware.vibrator@1.0",
+ ],
+ proprietary: true,
+}
diff --git a/vibrator/1.0-lineage/Vibrator.cpp b/vibrator/1.0-lineage/Vibrator.cpp
new file mode 100644
index 0000000..50ca82e
--- /dev/null
+++ b/vibrator/1.0-lineage/Vibrator.cpp
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2017 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "VibratorService"
+
+#include <log/log.h>
+
+#include "Vibrator.h"
+
+#include <cmath>
+#include <fstream>
+
+namespace android {
+namespace hardware {
+namespace vibrator {
+namespace V1_0 {
+namespace implementation {
+
+#define VIBRATOR "/sys/devices/virtual/timed_output/vibrator/"
+
+#define ENABLE "enable"
+#define VTG_LEVEL "vtg_level"
+#define VTG_MIN "vtg_min"
+#define VTG_MAX "vtg_max"
+
+#define CLICK_TIMING_MS 20
+
+#define DEFAULT_MIN_VTG 0
+#define DEFAULT_MAX_VTG 255
+
+static int get(std::string path, int defaultValue) {
+ int value = defaultValue;
+ std::ifstream file(path);
+
+ if (!file) {
+ ALOGE("Failed to open %s", path.c_str());
+ return value;
+ }
+
+ file >> value;
+
+ if (!file) {
+ ALOGE("Failed to read value from %s", path.c_str());
+ }
+
+ return value;
+}
+
+static int set(std::string path, int value) {
+ std::ofstream file(path);
+
+ if (!file) {
+ ALOGE("Failed to open %s", path.c_str());
+ return -1;
+ }
+
+ file << value;
+
+ if (!file) {
+ ALOGE("Failed to write %d to %s", value, path.c_str());
+ return -1;
+ }
+
+ return 0;
+}
+
+Vibrator::Vibrator() {
+ minVoltage = get(VIBRATOR VTG_MIN, DEFAULT_MIN_VTG);
+ maxVoltage = get(VIBRATOR VTG_MAX, DEFAULT_MAX_VTG);
+}
+
+Return<Status> Vibrator::on(uint32_t timeout_ms) {
+ if (set(VIBRATOR ENABLE, timeout_ms)) {
+ return Status::UNKNOWN_ERROR;
+ }
+
+ return Status::OK;
+}
+
+Return<Status> Vibrator::off() {
+ if (set(VIBRATOR ENABLE, 0)) {
+ return Status::UNKNOWN_ERROR;
+ }
+
+ return Status::OK;
+}
+
+Return<bool> Vibrator::supportsAmplitudeControl() {
+ return true;
+}
+
+Return<Status> Vibrator::setAmplitude(uint8_t amplitude) {
+ if (amplitude == 0) {
+ return Status::BAD_VALUE;
+ }
+
+ /*
+ * Scale the voltage such that an amplitude of 1 is minVoltage
+ * and an amplitude of 255 is maxVoltage.
+ */
+ uint32_t voltage =
+ std::lround((amplitude - 1) / 254.0 * (maxVoltage - minVoltage) + minVoltage);
+
+ if (set(VIBRATOR VTG_LEVEL, voltage)) {
+ return Status::UNKNOWN_ERROR;
+ }
+
+ ALOGI("Voltage set to: %u", voltage);
+
+ return Status::OK;
+}
+
+Return<void> Vibrator::perform(Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
+ switch (effect) {
+ case Effect::CLICK:
+ uint8_t amplitude;
+
+ switch (strength) {
+ case EffectStrength::LIGHT:
+ amplitude = 36;
+ break;
+ case EffectStrength::MEDIUM:
+ amplitude = 128;
+ break;
+ case EffectStrength::STRONG:
+ amplitude = 255;
+ break;
+ default:
+ _hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
+ return Void();
+ }
+
+ on(CLICK_TIMING_MS);
+ setAmplitude(amplitude);
+ _hidl_cb(Status::OK, CLICK_TIMING_MS);
+ break;
+ default:
+ _hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
+ break;
+ }
+
+ return Void();
+}
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace vibrator
+} // namespace hardware
+} // namespace android
diff --git a/vibrator/1.0-lineage/Vibrator.h b/vibrator/1.0-lineage/Vibrator.h
new file mode 100644
index 0000000..7624917
--- /dev/null
+++ b/vibrator/1.0-lineage/Vibrator.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2017 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ANDROID_HARDWARE_VIBRATOR_V1_0_VIBRATOR_H
+#define ANDROID_HARDWARE_VIBRATOR_V1_0_VIBRATOR_H
+
+#include <android/hardware/vibrator/1.0/IVibrator.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace vibrator {
+namespace V1_0 {
+namespace implementation {
+
+class Vibrator : public IVibrator {
+public:
+ Vibrator();
+
+ Return<Status> on(uint32_t timeoutMs) override;
+ Return<Status> off() override;
+ Return<bool> supportsAmplitudeControl() override;
+ Return<Status> setAmplitude(uint8_t amplitude) override;
+ Return<void> perform(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override;
+
+private:
+ uint32_t minVoltage;
+ uint32_t maxVoltage;
+};
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace vibrator
+} // namespace hardware
+} // namespace android
+
+#endif // ANDROID_HARDWARE_VIBRATOR_V1_0_VIBRATOR_H
diff --git a/vibrator/1.0-lineage/android.hardware.vibrator@1.0-service.lineage.rc b/vibrator/1.0-lineage/android.hardware.vibrator@1.0-service.lineage.rc
new file mode 100644
index 0000000..46f54b2
--- /dev/null
+++ b/vibrator/1.0-lineage/android.hardware.vibrator@1.0-service.lineage.rc
@@ -0,0 +1,12 @@
+on boot
+ chown system system /sys/devices/virtual/timed_output/vibrator/vtg_level
+ chown system system /sys/devices/virtual/timed_output/vibrator/vtg_max
+ chown system system /sys/devices/virtual/timed_output/vibrator/vtg_min
+ chmod 0644 /sys/devices/virtual/timed_output/vibrator/vtg_level
+ chmod 0444 /sys/devices/virtual/timed_output/vibrator/vtg_max
+ chmod 0444 /sys/devices/virtual/timed_output/vibrator/vtg_min
+
+service vibrator-1-0 /vendor/bin/hw/android.hardware.vibrator@1.0-service.lineage
+ class hal
+ user system
+ group system
diff --git a/vibrator/1.0-lineage/service.cpp b/vibrator/1.0-lineage/service.cpp
new file mode 100644
index 0000000..9772726
--- /dev/null
+++ b/vibrator/1.0-lineage/service.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2017 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#define LOG_TAG "android.hardware.vibrator@1.0-service.lineage"
+
+#include <hidl/HidlTransportSupport.h>
+
+#include "Vibrator.h"
+
+using android::hardware::configureRpcThreadpool;
+using android::hardware::joinRpcThreadpool;
+
+using android::hardware::vibrator::V1_0::IVibrator;
+using android::hardware::vibrator::V1_0::implementation::Vibrator;
+
+using android::OK;
+using android::sp;
+using android::status_t;
+
+int main() {
+ android::sp<IVibrator> vibrator = new Vibrator();
+
+ configureRpcThreadpool(1, true);
+
+ status_t status = vibrator->registerAsService();
+ if (status != OK) {
+ ALOGE("Cannot register Vibrator HAL service.");
+ return 1;
+ }
+
+ ALOGI("Vibrator HAL service ready.");
+
+ joinRpcThreadpool();
+
+ ALOGI("Vibrator HAL service failed to join thread pool.");
+ return 1;
+}
diff --git a/vibrator/Android.bp b/vibrator/Android.bp
new file mode 100644
index 0000000..8dbb698
--- /dev/null
+++ b/vibrator/Android.bp
@@ -0,0 +1,4 @@
+// This is an autogenerated file, do not edit.
+subdirs = [
+ "1.0-lineage",
+]