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:
Guido Günther
2025-03-20 07:48:42 +00:00
committed by Guido Günther
parent 69c4ee3344
commit f089ad2fd0
2 changed files with 60 additions and 5 deletions
+14
View File
@@ -27,6 +27,7 @@ enum {
PROP_0,
PROP_COUNT,
PROP_PAUSE,
PROP_MAGNITUDE,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
@@ -37,6 +38,7 @@ typedef struct _FbdFeedbackVibraRumble {
guint count; /* number of rumbles */
guint pause; /* pause in msecs */
double magnitude; /* magnitude [0.0, 1.0] */
guint rumble; /* rumble in msecs */
guint periods; /* number of periods to play */
guint timer_id;
@@ -59,6 +61,9 @@ fbd_feedback_vibra_rumble_set_property (GObject *object,
case PROP_PAUSE:
self->pause = g_value_get_uint (value);
break;
case PROP_MAGNITUDE:
self->magnitude = g_value_get_double (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -80,6 +85,9 @@ fbd_feedback_vibra_rumble_get_property (GObject *object,
case PROP_PAUSE:
g_value_set_uint (value, self->pause);
break;
case PROP_MAGNITUDE:
g_value_set_double (value, self->magnitude);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -181,6 +189,11 @@ fbd_feedback_vibra_rumble_class_init (FbdFeedbackVibraRumbleClass *klass)
0, G_MAXINT, 0,
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);
}
@@ -188,4 +201,5 @@ static void
fbd_feedback_vibra_rumble_init (FbdFeedbackVibraRumble *self)
{
self->count = 1;
self->magnitude = 0.5;
}
+41
View File
@@ -9,10 +9,50 @@
#define GMOBILE_USE_UNSTABLE_API
#include "fbd-feedback-manager.h"
#include "fbd-feedback-vibra-pattern.h"
#include "fbd-feedback-vibra-rumble.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
test_fbd_feedback_vibra_pattern (void)
{
@@ -60,6 +100,7 @@ main (gint argc, gchar *argv[])
{
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);
return g_test_run();