[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator.spec
^
|
|
[-]
[+]
|
Added |
_service:tar_git:ngfd-plugin-droid-vibrator-0.91.4.tar.gz/50-droid-vibrator.ini
^
|
@@ -0,0 +1,24 @@
+[droid-vibrator]
+
+# For each string in EFFECT_LIST define a sequence
+EFFECT_LIST = touch,short,strong,alarm,notice,message,ringtone
+
+# Sequence has following syntax:
+# sequence_name = <action>=<value>
+#
+# Actions:
+# on - Run vibra for value ms
+# pause - Pause for value ms
+# repeat - Repeat for value times, or forever for forever
+#
+# For example, to have vibra run twice for 200ms and pause for 100ms:
+# 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=500,pause=300,repeat=1
+message = on=200,pause=200,repeat=1
+ringtone = on=2000,pause=500,repeat=forever
|
[-]
[+]
|
Changed |
_service:tar_git:ngfd-plugin-droid-vibrator-0.91.4.tar.gz/CMakeLists.txt
^
|
@@ -22,3 +22,4 @@
target_link_libraries(ngfd_droid-vibrator ${LIBHARDWARE_LIBRARIES})
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-0.91.4.tar.gz/src/droid-vibrator.c
^
|
@@ -3,7 +3,7 @@
*
* Copyright (C) 2010 Nokia Corporation.
* Contact: Xun Chen <xun.chen@nokia.com>
- * Copyright (C) 2014 Jolla Ltd.
+ * Copyright (C) 2014,2017 Jolla Ltd.
* Contact: Simonas Leleiva <simonas.leleiva@jollamobile.com>
*
* This work is free software; you can redistribute it and/or
@@ -23,27 +23,230 @@
#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
#define AV_KEY "plugin.droid-vibrator.data"
#define LOG_CAT "droid-vibrator: "
-typedef struct _DroidVibratorData
+#define EFFECT_LIST "EFFECT_LIST"
+#define EFFECT_LIST_DELIMITER ","
+#define EFFECT_VIBRA "on"
+#define EFFECT_PAUSE "pause"
+#define EFFECT_REPEAT "repeat"
+#define EFFECT_REPEAT_FOREVER "forever"
+#define MAX_STEP_TIME (10000) /* 10 seconds */
+#define MIN_STEP_TIME (1) /* 1 ms */
+#define MAX_REPEATS (100)
+#define REPEAT_FOREVER (-1)
+
+enum EffectStepType {
+ EFFECT_STEP_NONE,
+ /* vibrator on for *value* ms */
+ EFFECT_STEP_VIBRA,
+ /* pause for *value* ms */
+ EFFECT_STEP_PAUSE,
+ /* repeat the whole sequence from the beginning of
+ the sqeuence *value* times,
+ -1 forever, 0 no repeat, 1+ n repeats */
+ EFFECT_STEP_REPEAT
+};
+
+typedef struct DroidVibratorEffectStep
+{
+ enum EffectStepType type;
+ int value;
+} DroidVibratorEffectStep;
+
+typedef struct DroidVibratorEffect
+{
+ GSList *steps;
+ int repeat;
+} DroidVibratorEffect;
+
+typedef struct DroidVibratorData
{
- NRequest *request;
- NSinkInterface *iface;
- guint timeout_id;
+ NRequest *request;
+ NSinkInterface *iface;
+ guint sequence_id;
+ DroidVibratorEffect *current_effect;
+ GSList *current_step;
+ int repeat_count;
} 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.1")
+N_PLUGIN_VERSION ("0.2")
N_PLUGIN_DESCRIPTION ("Haptic feedback using Droid Vibrator HAL via libhybris")
+static void
+effect_free (gpointer data)
+{
+ DroidVibratorEffect *effect = (DroidVibratorEffect*) data;
+ g_slist_free_full (effect->steps, g_free);
+ g_free (effect);
+}
+
+static DroidVibratorEffect*
+effect_parse (const char *name, const NProplist *properties)
+{
+ 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);
+ return NULL;
+ }
+ sequence_parts = g_strsplit(sequence, EFFECT_LIST_DELIMITER, 0);
+
+ effect = g_new0 (DroidVibratorEffect, 1);
+
+ for (i = 0; sequence_parts[i]; i++) {
+ enum EffectStepType step_type = EFFECT_STEP_NONE;
+ DroidVibratorEffectStep *s;
+ gchar **step;
+ gint64 value;
+
+ step = g_strsplit(sequence_parts[i], "=", 0);
+ if (!step[0] || !step[1]) {
+ g_strfreev (step);
+ effect_free (effect);
+ effect = NULL;
+ N_WARNING (LOG_CAT "bad sequence string '%s', ignoring sequence %s", sequence, name);
+ goto done;
+ }
+
+ if (g_strcmp0 (step[0], EFFECT_VIBRA) == 0)
+ step_type = EFFECT_STEP_VIBRA;
+ else if (g_strcmp0 (step[0], EFFECT_PAUSE) == 0)
+ step_type = EFFECT_STEP_PAUSE;
+ else if (g_strcmp0 (step[0], EFFECT_REPEAT) == 0)
+ step_type = EFFECT_STEP_REPEAT;
+
+ switch (step_type) {
+ case EFFECT_STEP_VIBRA:
+ /* fall through */
+ case EFFECT_STEP_PAUSE:
+ s = g_new0 (DroidVibratorEffectStep, 1);
+ s->type = step_type;
+ value = g_ascii_strtoll (step[1], NULL, 10);
+ if (value > MAX_STEP_TIME)
+ value = MAX_STEP_TIME;
+ else if (value < MIN_STEP_TIME)
+ value = MIN_STEP_TIME;
+ s->value = (int) value;
+ effect->steps = g_slist_append (effect->steps, s);
+ break;
+
+ case EFFECT_STEP_REPEAT:
+ if (g_strcmp0 (step[1], EFFECT_REPEAT_FOREVER) == 0)
+ value = REPEAT_FOREVER;
+ else {
+ value = g_ascii_strtoll (step[1], NULL, 10);
+ if (value > MAX_REPEATS)
+ value = MAX_REPEATS;
+ else if (value <= -1)
+ value = REPEAT_FOREVER;
+ }
+ effect->repeat = (int) value;
+ break;
+
+ default:
+ N_WARNING (LOG_CAT "incorrect sequence type %s, ignoring", step[0]);
+ break;
+ }
+
+ g_strfreev (step);
+ }
+
+done:
+ g_strfreev (sequence_parts);
+
+ if (effect && !effect->steps) {
+ N_WARNING (LOG_CAT "no valid effect steps, ignoring sequence %s", name);
+ effect_free (effect);
+ effect = NULL;
+ }
+
+ return effect;
+}
+
+static GHashTable*
+effects_parse (const NProplist *properties)
+{
+ GHashTable *effects = NULL;
+ const gchar *effect_data;
+ gchar **effect_names;
+ int i;
+
+ effect_data = n_proplist_get_string (properties, EFFECT_LIST);
+
+ if (!effect_data) {
+ N_WARNING (LOG_CAT "no " EFFECT_LIST " defined");
+ return NULL;
+ }
+
+ effect_names = g_strsplit (effect_data, EFFECT_LIST_DELIMITER, 0);
+ if (!effect_names[0]) {
+ N_WARNING (LOG_CAT "Empty " EFFECT_LIST "string");
+ goto effect_list_done;
+ }
+
+ N_DEBUG (LOG_CAT "creating effect list for %s", effect_data);
|