vibra-periodic: Use same range as in rumble and periodic
We use [0.0, 1.0] in the other haptic feedbacks so let's make periodic do the same. We adjust dev-vibra to match that. Closes: https://source.puri.sm/Librem5/feedbackd/-/issues/86 Signed-off-by: Guido Günther <agx@sigxcpu.org>
This commit is contained in:
+8
-5
@@ -272,8 +272,11 @@ 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 };
|
||||||
@@ -281,7 +284,7 @@ fbd_dev_vibra_periodic (FbdDevVibra *self, guint duration, guint magnitude,
|
|||||||
g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE);
|
g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE);
|
||||||
|
|
||||||
if (!magnitude)
|
if (!magnitude)
|
||||||
magnitude = 0x7FFF;
|
magnitude = 0.5;
|
||||||
|
|
||||||
if (!fade_in_level)
|
if (!fade_in_level)
|
||||||
fade_in_level = magnitude;
|
fade_in_level = magnitude;
|
||||||
@@ -293,12 +296,12 @@ fbd_dev_vibra_periodic (FbdDevVibra *self, guint duration, guint magnitude,
|
|||||||
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);
|
||||||
|
|||||||
@@ -23,8 +23,6 @@
|
|||||||
* #FbdDevVibra for that.
|
* #FbdDevVibra for that.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MAX_MAGNITUDE 0xFFFF
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_MAGNITUDE,
|
PROP_MAGNITUDE,
|
||||||
@@ -37,8 +35,8 @@ 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;
|
||||||
|
|
||||||
@@ -54,10 +52,10 @@ fbd_feedback_vibra_periodic_set_property (GObject *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);
|
||||||
@@ -78,10 +76,10 @@ fbd_feedback_vibra_periodic_get_property (GObject *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);
|
||||||
@@ -109,15 +107,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);
|
||||||
}
|
}
|
||||||
@@ -147,8 +145,8 @@ 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 ("magnitude", "", "",
|
g_param_spec_double ("magnitude", "", "",
|
||||||
0, MAX_MAGNITUDE, 0x7FFF,
|
0.0, 1.0, 0.5,
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||||
|
|
||||||
props[PROP_FADE_IN_TIME] =
|
props[PROP_FADE_IN_TIME] =
|
||||||
@@ -157,8 +155,8 @@ fbd_feedback_vibra_periodic_class_init (FbdFeedbackVibraPeriodicClass *klass)
|
|||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||||
|
|
||||||
props[PROP_FADE_IN_LEVEL] =
|
props[PROP_FADE_IN_LEVEL] =
|
||||||
g_param_spec_uint ("fade-in-level", "", "",
|
g_param_spec_double ("fade-in-level", "", "",
|
||||||
0, MAX_MAGNITUDE, 0x7FFF,
|
0.0, 1.0, 0.5,
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user