dev-vibra: Allow to set magnitude

Allows for more subtle feedback

Signed-off-by: Guido Günther <agx@sigxcpu.org>
This commit is contained in:
Guido Günther
2024-12-15 18:35:44 +01:00
parent 58221c7416
commit 386c98c381
3 changed files with 8 additions and 5 deletions
+2 -2
View File
@@ -233,7 +233,7 @@ fbd_dev_vibra_new (GUdevDevice *device, GError **error)
}
gboolean
fbd_dev_vibra_rumble (FbdDevVibra *self, guint duration, gboolean upload)
fbd_dev_vibra_rumble (FbdDevVibra *self, double magnitude, guint duration, gboolean upload)
{
struct input_event event = { 0 };
struct ff_effect effect = { 0 };
@@ -243,7 +243,7 @@ fbd_dev_vibra_rumble (FbdDevVibra *self, guint duration, gboolean upload)
memset(&effect, 0, sizeof(effect));
effect.type = FF_RUMBLE;
effect.id = -1;
effect.u.rumble.strong_magnitude = 0x8000;
effect.u.rumble.strong_magnitude = (0x8000 * magnitude);
effect.u.rumble.weak_magnitude = 0;
effect.replay.length = duration;
effect.replay.delay = 0;
+4 -1
View File
@@ -15,7 +15,10 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (FbdDevVibra, fbd_dev_vibra, FBD, DEV_VIBRA, GObject);
FbdDevVibra *fbd_dev_vibra_new (GUdevDevice *device, GError **error);
gboolean fbd_dev_vibra_rumble (FbdDevVibra *device, guint duration, gboolean upload);
gboolean fbd_dev_vibra_rumble (FbdDevVibra *device,
double magnitude,
guint duration,
gboolean upload);
gboolean fbd_dev_vibra_periodic (FbdDevVibra *self, guint duration, guint magnitude,
guint fade_in_level, guint fade_in_time);
gboolean fbd_dev_vibra_stop (FbdDevVibra *self);
+2 -2
View File
@@ -92,7 +92,7 @@ on_period_ended (FbdFeedbackVibraRumble *self)
g_return_val_if_fail (FBD_IS_FEEDBACK_VIBRA_RUMBLE (self), G_SOURCE_REMOVE);
if (self->periods) {
fbd_dev_vibra_rumble (dev, self->rumble, FALSE);
fbd_dev_vibra_rumble (dev, 1.0, self->rumble, FALSE);
self->periods--;
return G_SOURCE_CONTINUE;
}
@@ -130,7 +130,7 @@ fbd_feedback_vibra_rumble_start_vibra (FbdFeedbackVibra *vibra)
g_debug ("Rumble Vibra event: duration %d, rumble: %d, pause: %d, period: %d",
duration, self->rumble, self->pause, period);
fbd_dev_vibra_rumble (dev, self->rumble, TRUE);
fbd_dev_vibra_rumble (dev, 1.0, self->rumble, TRUE);
self->periods--;
if (self->periods) {
self->timer_id = g_timeout_add (period, (GSourceFunc) on_period_ended, self);