[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator.spec
^
|
|
[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator-1.4.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,long,notice,message,attention,alarm,ringtone,default
+EFFECT_LIST = drag_start,release_weak,drag_fail,drag_boundary,touch_weak,drag_end,release,touch,release_strong,touch_strong,short,strong,long,notice,message,attention,alarm,ringtone,default
# Sequence has following syntax:
# sequence_name = <action>=<value>
@@ -15,13 +15,22 @@
# vibra = on=200,pause=100,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
+drag_start = on=5
+release_weak = on=7
+drag_fail = on=9
+drag_boundary = on=10
+touch_weak = on=10
+drag_end = on=15
+release = on=18
+touch = on=20
+release_strong = on=25
+touch_strong = on=30
+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.4.0.tar.gz/CMakeLists.txt
^
|
@@ -4,6 +4,8 @@
project(ngfd-plugin-droid-vibrator)
+include(GNUInstallDirs)
+
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(NGFD_PLUGIN REQUIRED ngf-plugin)
@@ -34,5 +36,5 @@
target_link_libraries(ngfd_droid-vibrator ${LIBHARDWARE_LIBRARIES})
endif()
-install(TARGETS ngfd_droid-vibrator LIBRARY DESTINATION lib/ngf)
+install(TARGETS ngfd_droid-vibrator LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/ngf)
install(FILES 50-droid-vibrator.ini DESTINATION share/ngfd/plugins.d)
|
[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator-1.4.0.tar.gz/src/droid-vibrator.c
^
|
@@ -38,6 +38,8 @@
#define MIN_STEP_TIME (1) /* 1 ms */
#define MAX_REPEATS (100)
#define REPEAT_FOREVER (-1)
+#define HAPTIC_DURATION "haptic.duration"
+#define EFFECT_SEQUENCE "haptic.sequence"
enum EffectStepType {
EFFECT_STEP_NONE,
@@ -70,7 +72,10 @@
guint sequence_id;
DroidVibratorEffect *current_effect;
GSList *current_step;
+ guint remaining;
int repeat_count;
+ /* Effect is parsed for the event and freed after use. */
+ gboolean one_shot;
} DroidVibratorData;
static GHashTable *plugin_effects;
@@ -88,17 +93,15 @@
}
static DroidVibratorEffect*
-effect_parse (const char *name, const NProplist *properties)
+effect_parse (const char *sequence)
{
DroidVibratorEffect *effect = NULL;
- const gchar *sequence = NULL;
gchar **sequence_parts = NULL;
int i;
- if (!(sequence = n_proplist_get_string (properties, name))) {
- N_WARNING (LOG_CAT "sequence missing for %s", name);
+ if (!sequence || !*sequence)
return NULL;
- }
+
sequence_parts = g_strsplit(sequence, EFFECT_LIST_DELIMITER, 0);
effect = g_new0 (DroidVibratorEffect, 1);
@@ -114,7 +117,7 @@
g_strfreev (step);
effect_free (effect);
effect = NULL;
- N_WARNING (LOG_CAT "bad sequence string '%s', ignoring sequence %s", sequence, name);
+ N_WARNING (LOG_CAT "bad sequence string '%s', ignoring sequence", sequence);
goto done;
}
@@ -165,7 +168,7 @@
g_strfreev (sequence_parts);
if (effect && !effect->steps) {
- N_WARNING (LOG_CAT "no valid effect steps, ignoring sequence %s", name);
+ N_WARNING (LOG_CAT "no valid effect steps, ignoring sequence '%s'", sequence);
effect_free (effect);
effect = NULL;
}
@@ -173,6 +176,19 @@
return effect;
}
+static DroidVibratorEffect*
+effect_parse_from_proplist (const char *name, const NProplist *properties)
+{
+ const gchar *sequence = NULL;
+
+ if (!(sequence = n_proplist_get_string (properties, name))) {
+ N_WARNING (LOG_CAT "sequence missing for %s", name);
+ return NULL;
+ }
+
+ return effect_parse (sequence);
+}
+
static GHashTable*
effects_parse (const NProplist *properties)
{
@@ -203,7 +219,7 @@
for (i = 0; effect_names[i]; i++) {
DroidVibratorEffect *e;
- if ((e = effect_parse (effect_names[i], properties)))
+ if ((e = effect_parse_from_proplist (effect_names[i], properties)))
g_hash_table_insert (effects, g_strdup(effect_names[i]), e);
}
@@ -225,18 +241,30 @@
{
DroidVibratorData *data;
DroidVibratorEffect *effect;
+ gboolean one_shot = FALSE;
const gchar *key;
+ const gchar *sequence;
+ const NProplist *properties = n_request_get_properties (request);
N_DEBUG (LOG_CAT "sink prepare");
- if (!(key = n_haptic_effect_for_request (request))) {
- N_DEBUG (LOG_CAT "no effect key found for this effect");
- return FALSE;
- }
+ if ((sequence = n_proplist_get_string (properties, EFFECT_SEQUENCE))) {
+ effect = effect_parse (sequence);
+ if (!effect) {
+ N_DEBUG (LOG_CAT "invalid effect sequence: %s", sequence);
+ return FALSE;
+ }
+ one_shot = TRUE;
+ } else {
+ if (!(key = n_haptic_effect_for_request (request))) {
+ N_DEBUG (LOG_CAT "no effect key found for this request");
+ return FALSE;
+ }
- if (!(effect = g_hash_table_lookup (plugin_effects, key))) {
- N_DEBUG (LOG_CAT "no effect with key %s found for this effect", key);
- return FALSE;
+ if (!(effect = g_hash_table_lookup (plugin_effects, key))) {
+ N_DEBUG (LOG_CAT "no effect with key %s found for this effect", key);
+ return FALSE;
+ }
}
data = g_slice_new0 (DroidVibratorData);
@@ -245,7 +273,9 @@
data->sequence_id = 0;
data->current_effect = effect;
data->current_step = effect->steps;
- data->repeat_count = effect->repeat;
+ data->remaining = n_proplist_get_uint (properties, HAPTIC_DURATION);
+ data->repeat_count = data->remaining ? REPEAT_FOREVER : effect->repeat;
+ data->one_shot = one_shot;
n_request_store_data (request, AV_KEY, data);
n_sink_interface_synchronize (iface, request);
@@ -273,6 +303,7 @@
sequence_play (DroidVibratorData *data)
{
DroidVibratorEffectStep *step;
+ guint duration;
if (!data->current_step) {
if (data->repeat_count == REPEAT_FOREVER)
@@ -288,9 +319,30 @@
step = g_slist_nth_data (data->current_step, 0);
- data->sequence_id = g_timeout_add (step->value, sequence_cb, data);
+ if (data->remaining) {
+ /* If remaining duration was specified, clamp step length to it and
+ decrease remaining by that value. If remaining runs out, stop the
+ effect. */
+ if (data->remaining > step->value) {
+ if (step->type == EFFECT_STEP_VIBRA && !g_slist_next(data->current_effect->steps))
+ /* If the effect consists only of single vibration sequence,
+ play it as long as possible. */
+ duration = data->remaining < MAX_STEP_TIME ? data->remaining : MAX_STEP_TIME;
+ else
+ duration = step->value;
+ } else
+ duration = data->remaining;
+ data->remaining -= duration;
+ if (data->remaining == 0) {
+ data->current_step = NULL;
+ data->repeat_count = 0;
+ }
+ } else {
+ duration = step->value;
+ }
+ data->sequence_id = g_timeout_add (duration, sequence_cb, data);
if (step->type == EFFECT_STEP_VIBRA)
- h_vibrator_on (step->value);
+ h_vibrator_on (duration);
}
static int
@@ -344,6 +396,8 @@
data = (DroidVibratorData*) n_request_get_data (request, AV_KEY);
g_assert (data);
sequence_stop (data);
+ if (data->one_shot)
+ effect_free (data->current_effect);
g_slice_free (DroidVibratorData, data);
}
|
[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator-1.4.0.tar.gz/src/implementation.h
^
|
@@ -6,14 +6,15 @@
#ifdef NATIVE_VIBRATOR
-#define IMPLEMENTATION_NAME "native-vibrator"
-#define IMPLEMENTATION_DESCRIPTION "Haptic feedback using droid vibrator device"
-#define NATIVE_FILE_PATH_KEY "native.path"
+#define IMPLEMENTATION_NAME "native-vibrator"
+#define IMPLEMENTATION_DESCRIPTION "Haptic feedback using droid vibrator device"
+#define NATIVE_FILE_DURATION_PATH_KEY "native.path"
+#define NATIVE_FILE_ACTIVATE_PATH_KEY "native.activate_path"
#else
-#define IMPLEMENTATION_NAME "droid-vibrator"
-#define IMPLEMENTATION_DESCRIPTION "Haptic feedback using Droid Vibrator HAL via libhybris"
+#define IMPLEMENTATION_NAME "droid-vibrator"
+#define IMPLEMENTATION_DESCRIPTION "Haptic feedback using Droid Vibrator HAL via libhybris"
#endif
|
[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator-1.4.0.tar.gz/src/native.c
^
|
@@ -9,52 +9,105 @@
#include <unistd.h>
#include <stdio.h>
-#define DEFAULT_NATIVE_FILE_PATH "/sys/class/timed_output/vibrator/enable"
+struct file_location {
+ const char *duration;
+ const char *activate;
+};
+
+static struct file_location file_locations[] = {
+ { NULL, NULL }, /* Filled from user set values */
+ { "/sys/class/timed_output/vibrator/enable", NULL },
+ { "/sys/class/leds/vibrator/duration", "/sys/class/leds/vibrator/activate" },
+};
-static int vibra_fd;
+#define ACTIVATE_ON (1)
+#define ACTIVATE_OFF (0)
+
+static int duration_fd;
+static int activate_fd;
int h_vibrator_open (const NProplist *properties)
{
- const char *device_path;
-
- vibra_fd = -1;
+ const char *duration_path;
+ const char *activate_path;
+ int count = sizeof(file_locations) / sizeof(file_locations[0]);
+ int i = 0;
+
+ duration_fd = -1;
+ activate_fd = -1;
+
+ if ((file_locations[0].duration = n_proplist_get_string (properties, NATIVE_FILE_DURATION_PATH_KEY)))
+ file_locations[0].activate = n_proplist_get_string (properties, NATIVE_FILE_ACTIVATE_PATH_KEY);
+ else
+ i++;
+
+ for (; i < count; i++) {
+ duration_path = file_locations[i].duration;
+ activate_path = file_locations[i].activate;
+ N_DEBUG (LOG_CAT "look for %s %s", duration_path, activate_path ? activate_path : "<none>");
+
+ if ((duration_fd = open (duration_path, O_WRONLY)) < 0) {
+ duration_path = NULL;
+ continue;
+ }
+
+ if (activate_path) {
+ if ((activate_fd = open (activate_path, O_WRONLY)) < 0) {
+ h_vibrator_close ();
+ duration_path = NULL;
+ activate_path = NULL;
+ continue;
+ }
+ }
- if (!(device_path = n_proplist_get_string (properties, NATIVE_FILE_PATH_KEY)))
- device_path = DEFAULT_NATIVE_FILE_PATH;
+ break;
+ }
- if ((vibra_fd = open (device_path, O_WRONLY)) < 0) {
- N_INFO (LOG_CAT "cannot open native vibra control file '%s'", device_path);
+ if (duration_fd < 0) {
+ N_INFO (LOG_CAT "could not open native vibra control.");
return -1;
}
+ N_DEBUG (LOG_CAT "open native vibrator control path: %s%s%s",
+ duration_path,
+ activate_fd >= 0 ? " activate path: " : "",
+ activate_fd >= 0 ? activate_path : "");
+
return 0;
}
void h_vibrator_close (void)
{
- if (vibra_fd > 0)
- close (vibra_fd), vibra_fd = -1;
+ if (duration_fd >= 0)
+ close (duration_fd), duration_fd = -1;
+ if (activate_fd >= 0)
+ close (activate_fd), activate_fd = -1;
}
-static void vibrator_write (uint32_t value)
+static void vibrator_write (int fd, uint32_t value)
{
char value_str[12]; /* fits UINT32_MAX value with newline */
int length;
- if (vibra_fd < 0)
+ if (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");
+ if (write (fd, value_str, length) != length)
+ N_ERROR (LOG_CAT "failed to write to control file (fd %d)", fd);
}
void h_vibrator_on (uint32_t timeout_ms)
{
- vibrator_write (timeout_ms);
+ vibrator_write (duration_fd, timeout_ms);
+ if (activate_fd >= 0)
+ vibrator_write (activate_fd, ACTIVATE_ON);
}
void h_vibrator_off (void)
{
- vibrator_write (0);
+ if (activate_fd >= 0)
+ vibrator_write (activate_fd, ACTIVATE_OFF);
+ else
+ vibrator_write (duration_fd, ACTIVATE_OFF);
}
|