[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -1,6 +1,7 @@
<services>
<service name="tar_git">
- <param name="url">https://github.com/mer-hybris/ngfd-plugin-droid-vibrator.git</param>
+ <param name="url">https://github.com/mer-hybris/ngfd-plugin-droid-vibrator</param>
<param name="branch">master</param>
+ <param name="revision">HEAD</param>
</service>
-</services>
+</services>
\ No newline at end of file
|
[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator-1.0.tar.gz/50-droid-vibrator.ini
^
|
@@ -1,7 +1,7 @@
[droid-vibrator]
# For each string in EFFECT_LIST define a sequence
-EFFECT_LIST = touch,short,strong,alarm,notice,message,ringtone
+EFFECT_LIST = touch,short,strong,long,notice,message,attention,alarm,ringtone,default
# Sequence has following syntax:
# sequence_name = <action>=<value>
@@ -15,10 +15,13 @@
# vibra = on=200,pause=100,repeat=1
#
-touch = on=20
-short = on=33
-strong = on=66
-alarm = on=1000,pause=500,repeat=forever
-notice = on=100,pause=300,repeat=1
-message = on=200,pause=200,repeat=1
+touch = on=20
+short = on=33
+strong = on=66
+long = on=800
+notice = on=100,pause=500,repeat=1
+message = on=200,pause=200,repeat=1
+attention= on=100,pause=100,repeat=2
+alarm = on=1000,pause=500,repeat=forever
ringtone = on=2000,pause=500,repeat=forever
+default = on=66
|
[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator-1.0.tar.gz/CMakeLists.txt
^
|
@@ -1,25 +1,38 @@
cmake_minimum_required(VERSION 2.6)
+option(NATIVE_VIBRATOR "Use vibra directly through kernel interface instead of using HAL" OFF)
+
project(ngfd-plugin-droid-vibrator)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(NGFD_PLUGIN REQUIRED ngf-plugin)
-pkg_check_modules(ANDROID_HEADERS REQUIRED android-headers)
-pkg_check_modules(DROID_VIBRATOR REQUIRED libvibrator)
-pkg_check_modules(LIBHARDWARE REQUIRED libhardware)
+
+if(NATIVE_VIBRATOR)
+ add_definitions(-DNATIVE_VIBRATOR=1)
+else()
+ pkg_check_modules(ANDROID_HEADERS REQUIRED android-headers)
+ pkg_check_modules(DROID_VIBRATOR REQUIRED libvibrator)
+ pkg_check_modules(LIBHARDWARE REQUIRED libhardware)
+endif()
include_directories(${GLIB_INCLUDE_DIRS})
include_directories(${NGFD_PLUGIN_INCLUDE_DIRS})
-include_directories(${ANDROID_HEADERS_INCLUDE_DIRS})
-include_directories(${DROID_VIBRATOR_INCLUDE_DIRS})
-include_directories(${LIBHARDWARE_INCLUDE_DIRS})
-
-add_library(ngfd_droid-vibrator SHARED src/droid-vibrator.c)
-
-target_link_libraries(ngfd_droid-vibrator ${NGFD_PLUGIN_LIBRARIES})
-target_link_libraries(ngfd_droid-vibrator ${DROID_VIBRATOR_LIBRARIES})
-target_link_libraries(ngfd_droid-vibrator ${LIBHARDWARE_LIBRARIES})
+if(NOT NATIVE_VIBRATOR)
+ include_directories(${ANDROID_HEADERS_INCLUDE_DIRS})
+ include_directories(${DROID_VIBRATOR_INCLUDE_DIRS})
+ include_directories(${LIBHARDWARE_INCLUDE_DIRS})
+endif()
+
+if(NATIVE_VIBRATOR)
+ add_library(ngfd_droid-vibrator SHARED src/droid-vibrator.c src/native.c)
+ target_link_libraries(ngfd_droid-vibrator ${NGFD_PLUGIN_LIBRARIES})
+else()
+ add_library(ngfd_droid-vibrator SHARED src/droid-vibrator.c src/hal.c)
+ target_link_libraries(ngfd_droid-vibrator ${NGFD_PLUGIN_LIBRARIES})
+ target_link_libraries(ngfd_droid-vibrator ${DROID_VIBRATOR_LIBRARIES})
+ target_link_libraries(ngfd_droid-vibrator ${LIBHARDWARE_LIBRARIES})
+endif()
install(TARGETS ngfd_droid-vibrator LIBRARY DESTINATION lib/ngf)
install(FILES 50-droid-vibrator.ini DESTINATION share/ngfd/plugins.d)
|
[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator-1.0.tar.gz/README
^
|
@@ -1,5 +1,8 @@
Non-graphical feedback daemon: Droid Vibrator HAL plugin
--------------------------------------------------------
-This plugin builds against libhybris' libvibrator and libhardware wrappers to
+There are two implementations, one using kernel API directly (bypassing HAL)
+and one using libvibrator through libhybris.
+
+HAL variant builds against libhybris' libvibrator and libhardware wrappers to
provide haptic feedback for mer-hybris hardware adaptations.
|
[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator-1.0.tar.gz/src/droid-vibrator.c
^
|
@@ -23,15 +23,10 @@
#include <ngf/plugin.h>
#include <ngf/haptic.h>
-#include <android-version.h>
-#if ANDROID_VERSION_MAJOR >= 7
-#include <hardware/vibrator.h>
-#else
-#include <hardware_legacy/vibrator.h>
-#endif
+
+#include "implementation.h"
#define AV_KEY "plugin.droid-vibrator.data"
-#define LOG_CAT "droid-vibrator: "
#define EFFECT_LIST "EFFECT_LIST"
#define EFFECT_LIST_DELIMITER ","
@@ -79,15 +74,10 @@
} DroidVibratorData;
static GHashTable *plugin_effects;
-static const NProplist *plugin_properties;
-
-#if ANDROID_VERSION_MAJOR >= 7
-static vibrator_device_t *dev;
-#endif
N_PLUGIN_NAME ("droid-vibrator")
-N_PLUGIN_VERSION ("0.2")
-N_PLUGIN_DESCRIPTION ("Haptic feedback using Droid Vibrator HAL via libhybris")
+N_PLUGIN_VERSION ("0.3")
+N_PLUGIN_DESCRIPTION (IMPLEMENTATION_DESCRIPTION)
static void
effect_free (gpointer data)
@@ -224,45 +214,6 @@
}
static int
-droid_vibrator_sink_initialize (NSinkInterface *iface)
-{
- (void) iface;
- N_DEBUG (LOG_CAT "sink initialize");
-
-#if ANDROID_VERSION_MAJOR >= 7
- struct hw_module_t *hwmod;
-
- hw_get_module (VIBRATOR_HARDWARE_MODULE_ID, (const hw_module_t **)(&hwmod));
- g_assert(hwmod != NULL);
-
- if (vibrator_open (hwmod, &dev) < 0) {
- N_DEBUG (LOG_CAT "unable to open vibrator device");
- return FALSE;
- }
-#endif
-
- g_assert(plugin_properties);
- plugin_effects = effects_parse (plugin_properties);
-
- if (!plugin_effects)
- return FALSE;
-
- return TRUE;
-}
-
-static void
-droid_vibrator_sink_shutdown (NSinkInterface *iface)
-{
- (void) iface;
- N_DEBUG (LOG_CAT "sink shutdown");
-
- if (plugin_effects) {
- g_hash_table_destroy (plugin_effects);
- plugin_effects = NULL;
- }
-}
-
-static int
droid_vibrator_sink_can_handle (NSinkInterface *iface, NRequest *request)
{
N_DEBUG (LOG_CAT "sink can_handle");
@@ -274,15 +225,11 @@
{
DroidVibratorData *data;
DroidVibratorEffect *effect;
- const NProplist *props;
const gchar *key;
N_DEBUG (LOG_CAT "sink prepare");
- props = n_request_get_properties (request);
-
- key = n_proplist_get_string(props, HAPTIC_TYPE_KEY);
- if (key == NULL) {
+ if (!(key = n_haptic_effect_for_request (request))) {
N_DEBUG (LOG_CAT "no effect key found for this effect");
return FALSE;
}
@@ -343,12 +290,7 @@
data->sequence_id = g_timeout_add (step->value, sequence_cb, data);
if (step->type == EFFECT_STEP_VIBRA)
-#if ANDROID_VERSION_MAJOR >= 7
- dev->vibrator_on (dev, step->value);
-#else
- vibrator_on (step->value);
-#endif
-
+ h_vibrator_on (step->value);
}
static int
@@ -372,11 +314,7 @@
if (data->sequence_id > 0) {
g_source_remove (data->sequence_id);
data->sequence_id = 0;
-#if ANDROID_VERSION_MAJOR >= 7
- dev->vibrator_off (dev);
-#else
- vibrator_off ();
-#endif
+ h_vibrator_off ();
}
}
@@ -411,12 +349,13 @@
N_PLUGIN_LOAD (plugin)
{
- N_DEBUG (LOG_CAT "plugin load");
+ const NProplist *properties;
static const NSinkInterfaceDecl decl = {
- .name = "droid-vibrator",
- .initialize = droid_vibrator_sink_initialize,
- .shutdown = droid_vibrator_sink_shutdown,
+ .name = IMPLEMENTATION_NAME,
+ .type = N_SINK_INTERFACE_TYPE_VIBRATOR,
+ .initialize = NULL,
+ .shutdown = NULL,
.can_handle = droid_vibrator_sink_can_handle,
.prepare = droid_vibrator_sink_prepare,
.play = droid_vibrator_sink_play,
@@ -424,10 +363,17 @@
.stop = droid_vibrator_sink_stop
};
-#if ANDROID_VERSION_MAJOR >= 7
- dev = NULL;
-#endif
- plugin_properties = n_plugin_get_params (plugin);
+ properties = n_plugin_get_params (plugin);
+ g_assert (properties);
+
+ if (h_vibrator_open (properties) < 0)
+ return FALSE;
+
+ plugin_effects = effects_parse (properties);
+
+ if (!plugin_effects)
+ return FALSE;
+
n_plugin_register_sink (plugin, &decl);
return TRUE;
@@ -437,5 +383,10 @@
{
(void) plugin;
- N_DEBUG (LOG_CAT "plugin unload");
+ if (plugin_effects) {
+ g_hash_table_destroy (plugin_effects);
+ plugin_effects = NULL;
+ }
+
+ h_vibrator_close ();
}
|
[-]
[+]
|
Added |
_service:tar_git:ngfd-plugin-droid-vibrator-1.0.tar.gz/src/hal.c
^
|
@@ -0,0 +1,62 @@
+#include "implementation.h"
+
+#include <ngf/proplist.h>
+#include <ngf/log.h>
+
+#include <android-version.h>
+#if ANDROID_VERSION_MAJOR >= 7
+#include <hardware/vibrator.h>
+#else
+#include <hardware_legacy/vibrator.h>
+#endif
+
+#if ANDROID_VERSION_MAJOR >= 7
+static vibrator_device_t *dev;
+#endif
+
+int h_vibrator_open (const NProplist *properties)
+{
+ (void) properties;
+
+#if ANDROID_VERSION_MAJOR >= 7
+ struct hw_module_t *hwmod;
+
+ hw_get_module (VIBRATOR_HARDWARE_MODULE_ID, (const hw_module_t **)(&hwmod));
+ g_assert(hwmod != NULL);
+ dev = NULL;
+
+ if (vibrator_open (hwmod, &dev) < 0) {
+ N_DEBUG (LOG_CAT "unable to open vibrator device");
+ return -1;
+ }
+#endif
+ return 0;
+}
+
+void h_vibrator_close (void)
+{
+#if ANDROID_VERSION_MAJOR >= 7
+ if (dev)
+ dev->common.close((hw_device_t *) dev), dev = NULL;
+#endif
+}
+
+void h_vibrator_on (uint32_t timeout_ms)
+{
+#if ANDROID_VERSION_MAJOR >= 7
+ if (dev)
+ dev->vibrator_on (dev, timeout_ms);
+#else
+ vibrator_on (timeout_ms);
+#endif
+
+}
+
+void h_vibrator_off (void)
+{
+#if ANDROID_VERSION_MAJOR >= 7
+ dev->vibrator_off (dev);
+#else
+ vibrator_off ();
+#endif
+}
|
[-]
[+]
|
Added |
_service:tar_git:ngfd-plugin-droid-vibrator-1.0.tar.gz/src/implementation.h
^
|
@@ -0,0 +1,27 @@
+#ifndef _NGFD_PLUGIN_VIBRATOR_
+#define _NGFD_PLUGIN_VIBRATOR_
+
+#include <ngf/proplist.h>
+#include <stdint.h>
+
+#ifdef NATIVE_VIBRATOR
+
+#define IMPLEMENTATION_NAME "native-vibrator"
+#define IMPLEMENTATION_DESCRIPTION "Haptic feedback using droid vibrator device"
+#define NATIVE_FILE_PATH_KEY "native.path"
+
+#else
+
+#define IMPLEMENTATION_NAME "droid-vibrator"
+#define IMPLEMENTATION_DESCRIPTION "Haptic feedback using Droid Vibrator HAL via libhybris"
+
+#endif
+
+#define LOG_CAT IMPLEMENTATION_NAME ": "
+
+int h_vibrator_open (const NProplist *properties);
+void h_vibrator_close (void);
+void h_vibrator_on (uint32_t timeout_ms);
+void h_vibrator_off (void);
+
+#endif
|
[-]
[+]
|
Added |
_service:tar_git:ngfd-plugin-droid-vibrator-1.0.tar.gz/src/native.c
^
|
@@ -0,0 +1,60 @@
+#include "implementation.h"
+
+#include <ngf/proplist.h>
+#include <ngf/log.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#define DEFAULT_NATIVE_FILE_PATH "/sys/class/timed_output/vibrator/enable"
+
+static int vibra_fd;
+
+int h_vibrator_open (const NProplist *properties)
+{
+ const char *device_path;
+
+ vibra_fd = -1;
+
+ if (!(device_path = n_proplist_get_string (properties, NATIVE_FILE_PATH_KEY)))
+ device_path = DEFAULT_NATIVE_FILE_PATH;
+
+ if ((vibra_fd = open (device_path, O_WRONLY)) < 0) {
+ N_INFO (LOG_CAT "cannot open native vibra control file '%s'", device_path);
+ return -1;
+ }
+
+ return 0;
+}
+
+void h_vibrator_close (void)
+{
+ if (vibra_fd > 0)
+ close (vibra_fd), vibra_fd = -1;
+}
+
+static void vibrator_write (uint32_t value)
+{
+ char value_str[12]; /* fits UINT32_MAX value with newline */
+ int length;
+
+ if (vibra_fd < 0)
+ return;
+
+ length = snprintf (value_str, sizeof (value_str), "%u\n", value);
+ if (write (vibra_fd, value_str, length) != length)
+ N_ERROR (LOG_CAT "failed to write to vibra control file");
+}
+
+void h_vibrator_on (uint32_t timeout_ms)
+{
+ vibrator_write (timeout_ms);
+}
+
+void h_vibrator_off (void)
+{
+ vibrator_write (0);
+}
|