vibra-rumble: Add magnitude property
We add a magnitude property and set it to 0.5 by default. This ensure the relative magnitude stays the same when switching from 0xFFFF to 0x7FFF in dev-vibra. Signed-off-by: Guido Günther <agx@sigxcpu.org>
This commit is contained in:
committed by
Guido Günther
parent
69c4ee3344
commit
f089ad2fd0
@@ -27,6 +27,7 @@ enum {
|
|||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_COUNT,
|
PROP_COUNT,
|
||||||
PROP_PAUSE,
|
PROP_PAUSE,
|
||||||
|
PROP_MAGNITUDE,
|
||||||
PROP_LAST_PROP,
|
PROP_LAST_PROP,
|
||||||
};
|
};
|
||||||
static GParamSpec *props[PROP_LAST_PROP];
|
static GParamSpec *props[PROP_LAST_PROP];
|
||||||
@@ -34,12 +35,13 @@ static GParamSpec *props[PROP_LAST_PROP];
|
|||||||
typedef struct _FbdFeedbackVibraRumble {
|
typedef struct _FbdFeedbackVibraRumble {
|
||||||
FbdFeedbackVibra parent;
|
FbdFeedbackVibra parent;
|
||||||
|
|
||||||
guint count; /* number of rumbles */
|
guint count; /* number of rumbles */
|
||||||
guint pause; /* pause in msecs */
|
guint pause; /* pause in msecs */
|
||||||
|
|
||||||
guint rumble; /* rumble in msecs */
|
double magnitude; /* magnitude [0.0, 1.0] */
|
||||||
guint periods; /* number of periods to play */
|
guint rumble; /* rumble in msecs */
|
||||||
guint timer_id;
|
guint periods; /* number of periods to play */
|
||||||
|
guint timer_id;
|
||||||
} FbdFeedbackVibraRumble;
|
} FbdFeedbackVibraRumble;
|
||||||
|
|
||||||
G_DEFINE_TYPE (FbdFeedbackVibraRumble, fbd_feedback_vibra_rumble, FBD_TYPE_FEEDBACK_VIBRA);
|
G_DEFINE_TYPE (FbdFeedbackVibraRumble, fbd_feedback_vibra_rumble, FBD_TYPE_FEEDBACK_VIBRA);
|
||||||
@@ -59,6 +61,9 @@ fbd_feedback_vibra_rumble_set_property (GObject *object,
|
|||||||
case PROP_PAUSE:
|
case PROP_PAUSE:
|
||||||
self->pause = g_value_get_uint (value);
|
self->pause = g_value_get_uint (value);
|
||||||
break;
|
break;
|
||||||
|
case PROP_MAGNITUDE:
|
||||||
|
self->magnitude = g_value_get_double (value);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
break;
|
break;
|
||||||
@@ -80,6 +85,9 @@ fbd_feedback_vibra_rumble_get_property (GObject *object,
|
|||||||
case PROP_PAUSE:
|
case PROP_PAUSE:
|
||||||
g_value_set_uint (value, self->pause);
|
g_value_set_uint (value, self->pause);
|
||||||
break;
|
break;
|
||||||
|
case PROP_MAGNITUDE:
|
||||||
|
g_value_set_double (value, self->magnitude);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
break;
|
break;
|
||||||
@@ -181,6 +189,11 @@ fbd_feedback_vibra_rumble_class_init (FbdFeedbackVibraRumbleClass *klass)
|
|||||||
0, G_MAXINT, 0,
|
0, G_MAXINT, 0,
|
||||||
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||||
|
|
||||||
|
props[PROP_MAGNITUDE] =
|
||||||
|
g_param_spec_double ("magnitude", "", "",
|
||||||
|
0, 1.0, 0.5,
|
||||||
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||||
|
|
||||||
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
|
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,4 +201,5 @@ static void
|
|||||||
fbd_feedback_vibra_rumble_init (FbdFeedbackVibraRumble *self)
|
fbd_feedback_vibra_rumble_init (FbdFeedbackVibraRumble *self)
|
||||||
{
|
{
|
||||||
self->count = 1;
|
self->count = 1;
|
||||||
|
self->magnitude = 0.5;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,50 @@
|
|||||||
#define GMOBILE_USE_UNSTABLE_API
|
#define GMOBILE_USE_UNSTABLE_API
|
||||||
#include "fbd-feedback-manager.h"
|
#include "fbd-feedback-manager.h"
|
||||||
#include "fbd-feedback-vibra-pattern.h"
|
#include "fbd-feedback-vibra-pattern.h"
|
||||||
|
#include "fbd-feedback-vibra-rumble.h"
|
||||||
|
|
||||||
#include <json-glib/json-glib.h>
|
#include <json-glib/json-glib.h>
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_fbd_feedback_vibra_rumble (void)
|
||||||
|
{
|
||||||
|
/* Create manager upfront so we can dispose it, otherwise creating
|
||||||
|
* any feedback would create it implicitly */
|
||||||
|
FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
|
||||||
|
g_autoptr (GError) err = NULL;
|
||||||
|
g_autoptr (JsonNode) node = NULL;
|
||||||
|
GObject *object;
|
||||||
|
double magnitude;
|
||||||
|
guint count, duration;
|
||||||
|
|
||||||
|
node = json_from_string("{"
|
||||||
|
" \"event-name\" : \"button-pressed\","
|
||||||
|
" \"type\" : \"VibraRumble\","
|
||||||
|
" \"magnitude\" : 0.7,"
|
||||||
|
" \"duration\" : 100,"
|
||||||
|
" \"count\" : 2"
|
||||||
|
"}", &err);
|
||||||
|
g_assert_no_error (err);
|
||||||
|
|
||||||
|
object = json_gobject_deserialize (FBD_TYPE_FEEDBACK_VIBRA_RUMBLE, node);
|
||||||
|
g_test_assert_expected_messages ();
|
||||||
|
|
||||||
|
g_object_get (object,
|
||||||
|
"magnitude", &magnitude,
|
||||||
|
"duration", &duration,
|
||||||
|
"count", &count,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
g_assert_cmpfloat_with_epsilon (magnitude, 0.7, FLT_EPSILON);
|
||||||
|
g_assert_cmpint (duration, ==, 100);
|
||||||
|
g_assert_cmpint (count, ==, 2);
|
||||||
|
|
||||||
|
g_assert_finalize_object (object);
|
||||||
|
g_assert_finalize_object (manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_fbd_feedback_vibra_pattern (void)
|
test_fbd_feedback_vibra_pattern (void)
|
||||||
{
|
{
|
||||||
@@ -60,6 +100,7 @@ main (gint argc, gchar *argv[])
|
|||||||
{
|
{
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
g_test_add_func("/feedbackd/fbd/feedback-vibra/rumble", test_fbd_feedback_vibra_rumble);
|
||||||
g_test_add_func("/feedbackd/fbd/feedback-vibra/pattern", test_fbd_feedback_vibra_pattern);
|
g_test_add_func("/feedbackd/fbd/feedback-vibra/pattern", test_fbd_feedback_vibra_pattern);
|
||||||
|
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
|
|||||||
Reference in New Issue
Block a user