Merge branch 'periodic-magnitude' into 'main'
Use [0.0, 0.1] for periodic pattern too Closes #86 and #84 See merge request Librem5/feedbackd!162
This commit is contained in:
+9
-10
@@ -97,10 +97,8 @@
|
|||||||
{
|
{
|
||||||
"event-name" : "alarm-clock-elapsed",
|
"event-name" : "alarm-clock-elapsed",
|
||||||
"type" : "VibraPeriodic",
|
"type" : "VibraPeriodic",
|
||||||
"magnitude" : 32767,
|
"magnitude" : 0.5,
|
||||||
"duration" : 10000,
|
"duration" : 1000
|
||||||
"fade-in-time" : 10000,
|
|
||||||
"fade-in-level": 4096
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"event-name" : "bell-terminal",
|
"event-name" : "bell-terminal",
|
||||||
@@ -120,9 +118,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"event-name" : "message-new-cellbroadcast",
|
"event-name" : "message-new-cellbroadcast",
|
||||||
"type" : "VibraPeriodic",
|
"type" : "VibraPattern",
|
||||||
"magnitude" : 10000,
|
"magnitudes" : [1.0, 0.0],
|
||||||
"duration" : 3000
|
"durations" : [200, 200]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"event-name" : "message-new-email",
|
"event-name" : "message-new-email",
|
||||||
@@ -157,7 +155,8 @@
|
|||||||
{
|
{
|
||||||
"event-name" : "phone-incoming-call",
|
"event-name" : "phone-incoming-call",
|
||||||
"type" : "VibraPeriodic",
|
"type" : "VibraPeriodic",
|
||||||
"duration" : 10000
|
"magnitude" : 0.5,
|
||||||
|
"duration" : 1000
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"event-name" : "timeout-completed",
|
"event-name" : "timeout-completed",
|
||||||
@@ -167,8 +166,8 @@
|
|||||||
{
|
{
|
||||||
"event-name" : "theme-demo",
|
"event-name" : "theme-demo",
|
||||||
"type" : "VibraPeriodic",
|
"type" : "VibraPeriodic",
|
||||||
"magnitude" : 32767,
|
"magnitude" : 0.5,
|
||||||
"duration" : 5000
|
"duration" : 1000
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"event-name" : "window-close",
|
"event-name" : "window-close",
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ app that triggered it crashes.
|
|||||||
For details refer to the event and feedback theme specs at
|
For details refer to the event and feedback theme specs at
|
||||||
`<https://source.puri.sm/Librem5/feedbackd/>`__
|
`<https://source.puri.sm/Librem5/feedbackd/>`__
|
||||||
|
|
||||||
|
Feedbackd reloads the feedback theme on `SIGHUP` (i.e. `pkill -HUP feedbackd`).
|
||||||
|
|
||||||
Options
|
Options
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
|||||||
+7
-13
@@ -272,33 +272,27 @@ fbd_dev_vibra_rumble (FbdDevVibra *self, double magnitude, guint duration, gbool
|
|||||||
|
|
||||||
/* TODO: fall back to multiple rumbles when sine not supported */
|
/* TODO: fall back to multiple rumbles when sine not supported */
|
||||||
gboolean
|
gboolean
|
||||||
fbd_dev_vibra_periodic (FbdDevVibra *self, guint duration, guint magnitude,
|
fbd_dev_vibra_periodic (FbdDevVibra *self,
|
||||||
guint fade_in_level, guint fade_in_time)
|
guint duration,
|
||||||
|
double magnitude,
|
||||||
|
double fade_in_level,
|
||||||
|
guint fade_in_time)
|
||||||
{
|
{
|
||||||
struct input_event event;
|
struct input_event event;
|
||||||
struct ff_effect effect = { 0 };
|
struct ff_effect effect = { 0 };
|
||||||
|
|
||||||
g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE);
|
g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE);
|
||||||
|
|
||||||
if (!magnitude)
|
|
||||||
magnitude = 0x7FFF;
|
|
||||||
|
|
||||||
if (!fade_in_level)
|
|
||||||
fade_in_level = magnitude;
|
|
||||||
|
|
||||||
if (!fade_in_time)
|
|
||||||
fade_in_time = duration;
|
|
||||||
|
|
||||||
effect.type = FF_PERIODIC;
|
effect.type = FF_PERIODIC;
|
||||||
effect.id = -1;
|
effect.id = -1;
|
||||||
effect.u.periodic.waveform = FF_SINE;
|
effect.u.periodic.waveform = FF_SINE;
|
||||||
effect.u.periodic.period = 10;
|
effect.u.periodic.period = 10;
|
||||||
effect.u.periodic.magnitude = magnitude;
|
effect.u.periodic.magnitude = 0x7FFF * magnitude;
|
||||||
effect.u.periodic.offset = 0;
|
effect.u.periodic.offset = 0;
|
||||||
effect.u.periodic.phase = 0;
|
effect.u.periodic.phase = 0;
|
||||||
effect.direction = 0x4000;
|
effect.direction = 0x4000;
|
||||||
effect.u.periodic.envelope.attack_length = fade_in_time;
|
effect.u.periodic.envelope.attack_length = fade_in_time;
|
||||||
effect.u.periodic.envelope.attack_level = fade_in_level;;
|
effect.u.periodic.envelope.attack_level = 0x7FFF * fade_in_level;
|
||||||
effect.u.periodic.envelope.fade_length = 0;
|
effect.u.periodic.envelope.fade_length = 0;
|
||||||
effect.u.periodic.envelope.fade_level = 0;
|
effect.u.periodic.envelope.fade_level = 0;
|
||||||
effect.trigger.button = 0;
|
effect.trigger.button = 0;
|
||||||
|
|||||||
+5
-2
@@ -19,8 +19,11 @@ gboolean fbd_dev_vibra_rumble (FbdDevVibra *device,
|
|||||||
double magnitude,
|
double magnitude,
|
||||||
guint duration,
|
guint duration,
|
||||||
gboolean upload);
|
gboolean upload);
|
||||||
gboolean fbd_dev_vibra_periodic (FbdDevVibra *self, guint duration, guint magnitude,
|
gboolean fbd_dev_vibra_periodic (FbdDevVibra *self,
|
||||||
guint fade_in_level, guint fade_in_time);
|
guint duration,
|
||||||
|
double magnitude,
|
||||||
|
double fade_in_level,
|
||||||
|
guint fade_in_time);
|
||||||
gboolean fbd_dev_vibra_stop (FbdDevVibra *self);
|
gboolean fbd_dev_vibra_stop (FbdDevVibra *self);
|
||||||
gboolean fbd_dev_vibra_remove_effect (FbdDevVibra *self);
|
gboolean fbd_dev_vibra_remove_effect (FbdDevVibra *self);
|
||||||
GUdevDevice *fbd_dev_vibra_get_device(FbdDevVibra *self);
|
GUdevDevice *fbd_dev_vibra_get_device(FbdDevVibra *self);
|
||||||
|
|||||||
@@ -11,18 +11,18 @@
|
|||||||
#include "fbd-feedback-vibra-periodic.h"
|
#include "fbd-feedback-vibra-periodic.h"
|
||||||
#include "fbd-feedback-manager.h"
|
#include "fbd-feedback-manager.h"
|
||||||
|
|
||||||
|
#include <json-glib/json-glib.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:fbd-feedback-vibra-periodic
|
* FbdFeedbackVibraPeriodic:
|
||||||
* @short_description: Describes a periodic feedback via a haptic motor
|
*
|
||||||
* @Title: FbdFeedbackVibraPeriodic
|
* Describes a periodic feedback via a haptic motor
|
||||||
*
|
*
|
||||||
* The #FbdVibraVibraPeriodic describes the properties of a haptic feedback
|
* The #FbdVibraVibraPeriodic describes the properties of a haptic feedback
|
||||||
* event. It knows nothing about the hardware itself but calls
|
* event. It knows nothing about the hardware itself but calls
|
||||||
* #FbdDevVibra for that.
|
* #FbdDevVibra for that.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MAX_MAGNITUDE 0xFFFF
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_MAGNITUDE,
|
PROP_MAGNITUDE,
|
||||||
@@ -35,27 +35,73 @@ static GParamSpec *props[PROP_LAST_PROP];
|
|||||||
typedef struct _FbdFeedbackVibraPeriodic {
|
typedef struct _FbdFeedbackVibraPeriodic {
|
||||||
FbdFeedbackVibra parent;
|
FbdFeedbackVibra parent;
|
||||||
|
|
||||||
guint magnitude;
|
double magnitude;
|
||||||
guint fade_in_level;
|
double fade_in_level;
|
||||||
guint fade_in_time;
|
guint fade_in_time;
|
||||||
} FbdFeedbackVibraPeriodic;
|
} FbdFeedbackVibraPeriodic;
|
||||||
|
|
||||||
G_DEFINE_TYPE (FbdFeedbackVibraPeriodic, fbd_feedback_vibra_periodic, FBD_TYPE_FEEDBACK_VIBRA);
|
static void json_serializable_iface_init (JsonSerializableIface *iface);
|
||||||
|
|
||||||
|
G_DEFINE_TYPE_WITH_CODE (FbdFeedbackVibraPeriodic, fbd_feedback_vibra_periodic,
|
||||||
|
FBD_TYPE_FEEDBACK_VIBRA,
|
||||||
|
G_IMPLEMENT_INTERFACE (JSON_TYPE_SERIALIZABLE,
|
||||||
|
json_serializable_iface_init));
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
fbd_feedback_vibra_periodic_serializable_deserialize_property (JsonSerializable *serializable,
|
||||||
|
const gchar *property_name,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec,
|
||||||
|
JsonNode *property_node)
|
||||||
|
{
|
||||||
|
if (g_strcmp0 (property_name, "magnitude") == 0) {
|
||||||
|
if (JSON_NODE_TYPE (property_node) == JSON_NODE_VALUE) {
|
||||||
|
double magnitude = json_node_get_double (property_node);
|
||||||
|
|
||||||
|
/* Backward compat handling: Initially magnitude was given as [0, 0xFFFF] */
|
||||||
|
if (magnitude > 1.0) {
|
||||||
|
g_warning_once ("Too large magnitude %.2f detected, please update the theme", magnitude);
|
||||||
|
magnitude = magnitude / 0xFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
g_value_set_double (value, magnitude);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
} else if (g_strcmp0 (property_name, "fade-in-level") == 0) {
|
||||||
|
if (JSON_NODE_TYPE (property_node) == JSON_NODE_VALUE) {
|
||||||
|
double fade_in_level = json_node_get_double (property_node);
|
||||||
|
|
||||||
|
/* Backward compat handling: Initially duration was given as [0, 0xFFFF] */
|
||||||
|
if (fade_in_level > 1.0) {
|
||||||
|
g_warning_once ("Too large fade-in-level %.2f detected, please update the theme",
|
||||||
|
fade_in_level);
|
||||||
|
fade_in_level = fade_in_level / 0xFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_value_set_double (value, fade_in_level);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fbd_feedback_vibra_periodic_set_property (GObject *object,
|
fbd_feedback_vibra_periodic_set_property (GObject *object,
|
||||||
guint property_id,
|
guint property_id,
|
||||||
const GValue *value,
|
const GValue *value,
|
||||||
GParamSpec *pspec)
|
GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
FbdFeedbackVibraPeriodic *self = FBD_FEEDBACK_VIBRA_PERIODIC (object);
|
FbdFeedbackVibraPeriodic *self = FBD_FEEDBACK_VIBRA_PERIODIC (object);
|
||||||
|
|
||||||
switch (property_id) {
|
switch (property_id) {
|
||||||
case PROP_MAGNITUDE:
|
case PROP_MAGNITUDE:
|
||||||
self->magnitude = g_value_get_uint (value);
|
self->magnitude = g_value_get_double (value);
|
||||||
break;
|
break;
|
||||||
case PROP_FADE_IN_LEVEL:
|
case PROP_FADE_IN_LEVEL:
|
||||||
self->fade_in_level = g_value_get_uint (value);
|
self->fade_in_level = g_value_get_double (value);
|
||||||
break;
|
break;
|
||||||
case PROP_FADE_IN_TIME:
|
case PROP_FADE_IN_TIME:
|
||||||
self->fade_in_time = g_value_get_uint (value);
|
self->fade_in_time = g_value_get_uint (value);
|
||||||
@@ -68,18 +114,18 @@ fbd_feedback_vibra_periodic_set_property (GObject *object,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
fbd_feedback_vibra_periodic_get_property (GObject *object,
|
fbd_feedback_vibra_periodic_get_property (GObject *object,
|
||||||
guint property_id,
|
guint property_id,
|
||||||
GValue *value,
|
GValue *value,
|
||||||
GParamSpec *pspec)
|
GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
FbdFeedbackVibraPeriodic *self = FBD_FEEDBACK_VIBRA_PERIODIC (object);
|
FbdFeedbackVibraPeriodic *self = FBD_FEEDBACK_VIBRA_PERIODIC (object);
|
||||||
|
|
||||||
switch (property_id) {
|
switch (property_id) {
|
||||||
case PROP_MAGNITUDE:
|
case PROP_MAGNITUDE:
|
||||||
g_value_set_uint (value, self->magnitude);
|
g_value_set_double (value, self->magnitude);
|
||||||
break;
|
break;
|
||||||
case PROP_FADE_IN_LEVEL:
|
case PROP_FADE_IN_LEVEL:
|
||||||
g_value_set_uint (value, self->fade_in_level);
|
g_value_set_double (value, self->fade_in_level);
|
||||||
break;
|
break;
|
||||||
case PROP_FADE_IN_TIME:
|
case PROP_FADE_IN_TIME:
|
||||||
g_value_set_uint (value, self->fade_in_time);
|
g_value_set_uint (value, self->fade_in_time);
|
||||||
@@ -107,15 +153,15 @@ fbd_feedback_vibra_periodic_start_vibra (FbdFeedbackVibra *vibra)
|
|||||||
FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);
|
FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);
|
||||||
guint duration = fbd_feedback_vibra_get_duration (vibra);
|
guint duration = fbd_feedback_vibra_get_duration (vibra);
|
||||||
double max_strength = fbd_feedback_vibra_get_max_strength (FBD_FEEDBACK_VIBRA (self));
|
double max_strength = fbd_feedback_vibra_get_max_strength (FBD_FEEDBACK_VIBRA (self));
|
||||||
double fade_in_ratio = (double)self->fade_in_level / self->magnitude;
|
double fade_in_ratio = self->fade_in_level / self->magnitude;
|
||||||
guint max_magnitude, fade_in_level;
|
double max_magnitude, fade_in_level;
|
||||||
|
|
||||||
g_return_if_fail (FBD_IS_DEV_VIBRA (dev));
|
g_return_if_fail (FBD_IS_DEV_VIBRA (dev));
|
||||||
max_magnitude = MIN (MAX_MAGNITUDE * max_strength, self->magnitude);
|
max_magnitude = MIN (max_strength, self->magnitude);
|
||||||
fade_in_level = MIN (max_magnitude * fade_in_ratio, self->fade_in_level);
|
fade_in_level = MIN (max_magnitude * fade_in_ratio, self->fade_in_level);
|
||||||
|
|
||||||
g_debug ("Periodic Vibra: %d %d %d %d",
|
g_debug ("Periodic Vibra: (%f,%d) (%f,%d)",
|
||||||
duration, max_magnitude, fade_in_level, self->fade_in_time);
|
max_magnitude, duration, fade_in_level, self->fade_in_time);
|
||||||
|
|
||||||
fbd_dev_vibra_periodic (dev, duration, max_magnitude, fade_in_level, self->fade_in_time);
|
fbd_dev_vibra_periodic (dev, duration, max_magnitude, fade_in_level, self->fade_in_time);
|
||||||
}
|
}
|
||||||
@@ -129,6 +175,14 @@ fbd_feedback_vibra_periodic_is_available (FbdFeedbackBase *base)
|
|||||||
return FBD_IS_DEV_VIBRA (dev);
|
return FBD_IS_DEV_VIBRA (dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
json_serializable_iface_init (JsonSerializableIface *iface)
|
||||||
|
{
|
||||||
|
iface->deserialize_property = fbd_feedback_vibra_periodic_serializable_deserialize_property;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fbd_feedback_vibra_periodic_class_init (FbdFeedbackVibraPeriodicClass *klass)
|
fbd_feedback_vibra_periodic_class_init (FbdFeedbackVibraPeriodicClass *klass)
|
||||||
{
|
{
|
||||||
@@ -145,28 +199,19 @@ fbd_feedback_vibra_periodic_class_init (FbdFeedbackVibraPeriodicClass *klass)
|
|||||||
vibra_class->end_vibra = fbd_feedback_vibra_periodic_end_vibra;
|
vibra_class->end_vibra = fbd_feedback_vibra_periodic_end_vibra;
|
||||||
|
|
||||||
props[PROP_MAGNITUDE] =
|
props[PROP_MAGNITUDE] =
|
||||||
g_param_spec_uint (
|
g_param_spec_double ("magnitude", "", "",
|
||||||
"magnitude",
|
0.0, 1.0, 0.5,
|
||||||
"Magnitude",
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||||
"total magnitude",
|
|
||||||
0, MAX_MAGNITUDE, 0x7FFF,
|
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
|
||||||
|
|
||||||
props[PROP_FADE_IN_TIME] =
|
props[PROP_FADE_IN_TIME] =
|
||||||
g_param_spec_uint (
|
g_param_spec_uint ("fade-in-time", "", "",
|
||||||
"fade-in-time",
|
0, G_MAXINT, 500,
|
||||||
"Fade in time",
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||||
"Fade in time until full strength",
|
|
||||||
0, G_MAXINT, 0,
|
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
|
||||||
|
|
||||||
props[PROP_FADE_IN_LEVEL] =
|
props[PROP_FADE_IN_LEVEL] =
|
||||||
g_param_spec_uint (
|
g_param_spec_double ("fade-in-level", "", "",
|
||||||
"fade-in-level",
|
0.0, 1.0, 0.0,
|
||||||
"Fade in level",
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||||
"Fade in start level",
|
|
||||||
0, MAX_MAGNITUDE, 0x7FFF,
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -174,4 +219,7 @@ fbd_feedback_vibra_periodic_class_init (FbdFeedbackVibraPeriodicClass *klass)
|
|||||||
static void
|
static void
|
||||||
fbd_feedback_vibra_periodic_init (FbdFeedbackVibraPeriodic *self)
|
fbd_feedback_vibra_periodic_init (FbdFeedbackVibraPeriodic *self)
|
||||||
{
|
{
|
||||||
|
self->magnitude = 0.5;
|
||||||
|
self->fade_in_level = 0.0;
|
||||||
|
self->fade_in_time = 500;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#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-periodic.h"
|
||||||
#include "fbd-feedback-vibra-rumble.h"
|
#include "fbd-feedback-vibra-rumble.h"
|
||||||
|
|
||||||
#include <json-glib/json-glib.h>
|
#include <json-glib/json-glib.h>
|
||||||
@@ -95,6 +96,86 @@ test_fbd_feedback_vibra_pattern (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_fbd_feedback_vibra_periodic (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, fade_in_level;
|
||||||
|
guint fade_in_time;
|
||||||
|
|
||||||
|
node = json_from_string("{"
|
||||||
|
" \"event-name\" : \"button-pressed\","
|
||||||
|
" \"type\" : \"VibraPeriodic\","
|
||||||
|
" \"magnitude\" : 0.7,"
|
||||||
|
" \"fade-in-level\" : 0.3"
|
||||||
|
"}", &err);
|
||||||
|
g_assert_no_error (err);
|
||||||
|
|
||||||
|
object = json_gobject_deserialize (FBD_TYPE_FEEDBACK_VIBRA_PERIODIC, node);
|
||||||
|
g_object_get (object,
|
||||||
|
"magnitude", &magnitude,
|
||||||
|
"fade-in-level", &fade_in_level,
|
||||||
|
"fade-in-time", &fade_in_time,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
g_assert_cmpfloat_with_epsilon (magnitude, 0.7, FLT_EPSILON);
|
||||||
|
g_assert_cmpfloat_with_epsilon (fade_in_level, 0.3, FLT_EPSILON);
|
||||||
|
g_assert_cmpint (fade_in_time, ==, 500);
|
||||||
|
|
||||||
|
g_assert_finalize_object (object);
|
||||||
|
g_assert_finalize_object (manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_fbd_feedback_vibra_periodic_fallback (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, fade_in_level;
|
||||||
|
guint fade_in_time;
|
||||||
|
|
||||||
|
node = json_from_string("{"
|
||||||
|
" \"event-name\" : \"button-pressed\","
|
||||||
|
" \"type\" : \"VibraPeriodic\","
|
||||||
|
" \"magnitude\" : 65535,"
|
||||||
|
" \"fade-in-level\" : 13107"
|
||||||
|
"}", &err);
|
||||||
|
g_assert_no_error (err);
|
||||||
|
|
||||||
|
g_test_expect_message ("fbd-feedback-vibra-periodic",
|
||||||
|
G_LOG_LEVEL_WARNING,
|
||||||
|
"Too large magnitude 65535.00 detected*");
|
||||||
|
g_test_expect_message ("fbd-feedback-vibra-periodic",
|
||||||
|
G_LOG_LEVEL_WARNING,
|
||||||
|
"Too large fade-in-level 13107.00 detected*");
|
||||||
|
object = json_gobject_deserialize (FBD_TYPE_FEEDBACK_VIBRA_PERIODIC, node);
|
||||||
|
g_test_assert_expected_messages ();
|
||||||
|
|
||||||
|
g_object_get (object,
|
||||||
|
"magnitude", &magnitude,
|
||||||
|
"fade-in-level", &fade_in_level,
|
||||||
|
"fade-in-time", &fade_in_time,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
g_assert_cmpfloat_with_epsilon (magnitude, 1.0, FLT_EPSILON);
|
||||||
|
g_assert_cmpfloat_with_epsilon (fade_in_level, 0.2, FLT_EPSILON);
|
||||||
|
g_assert_cmpint (fade_in_time, ==, 500);
|
||||||
|
|
||||||
|
g_assert_finalize_object (object);
|
||||||
|
g_assert_finalize_object (manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
gint
|
gint
|
||||||
main (gint argc, gchar *argv[])
|
main (gint argc, gchar *argv[])
|
||||||
{
|
{
|
||||||
@@ -102,6 +183,9 @@ main (gint argc, gchar *argv[])
|
|||||||
|
|
||||||
g_test_add_func("/feedbackd/fbd/feedback-vibra/rumble", test_fbd_feedback_vibra_rumble);
|
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);
|
||||||
|
g_test_add_func("/feedbackd/fbd/feedback-vibra/periodic", test_fbd_feedback_vibra_periodic);
|
||||||
|
g_test_add_func("/feedbackd/fbd/feedback-vibra/periodic/fallback",
|
||||||
|
test_fbd_feedback_vibra_periodic_fallback);
|
||||||
|
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user