Merge branch 'haptic-motor-strength' into 'main'

haptic: Honor maximum strength gsetting

Closes #84

See merge request Librem5/feedbackd!156
This commit is contained in:
Guido Günther
2025-03-11 15:03:31 +00:00
8 changed files with 91 additions and 14 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ dbus_inc = include_directories('.')
install_data(dbus_interfaces, install_dir: ifacedir)
schemas = ['org.sigxcpu.feedbackd.gschema.xml']
compiled = gnome.compile_schemas(build_by_default: true)
compiled = gnome.compile_schemas(depend_files: schemas, build_by_default: true)
compile_schemas = find_program('glib-compile-schemas', required: false)
if compile_schemas.found()
+10
View File
@@ -41,6 +41,16 @@
setting the 'important' hint on the submitted event.
</description>
</key>
<key name="max-haptic-strength" type="d">
<range min="0.0" max="1.0"/>
<default>1.0</default>
<summary>Maximum haptic strength</summary>
<description>
The maximum haptic strength to use when providing feedback.
</description>
</key>
</schema>
<schema id="org.sigxcpu.feedbackd.application">
+2
View File
@@ -54,6 +54,8 @@ These gsettings are used by ``feedbackd``:
- `prefer-flash`: Prefer camera flash over status LED
- `theme`: The feedback theme to use. This can be used to override
the feedback theme picked by feedbackd based on device information.
- `max-haptic-strength`: Limits th maximum strenght used for the
haptic motor `[0.0, 1.0]`.
- `org.sigxcpu.feedbackd.application`
+5 -1
View File
@@ -199,8 +199,12 @@ do_pattern_step (FbdFeedbackVibraPattern *self)
/* Removing any pending effect */
fbd_dev_vibra_remove_effect (dev);
if (*magnitude != 0.0)
if (*magnitude != 0.0) {
double max_strength = fbd_feedback_vibra_get_max_strength (FBD_FEEDBACK_VIBRA (self));
*magnitude = MIN (*magnitude, max_strength);
fbd_dev_vibra_rumble (dev, *magnitude, *duration, TRUE);
}
self->timer_id = g_timeout_add_once (*duration,
on_timer_expired,
+14 -6
View File
@@ -7,6 +7,7 @@
#define G_LOG_DOMAIN "fbd-feedback-vibra-periodic"
#include "fbd-enums.h"
#include "fbd-feedback-vibra-priv.h"
#include "fbd-feedback-vibra-periodic.h"
#include "fbd-feedback-manager.h"
@@ -20,6 +21,8 @@
* #FbdDevVibra for that.
*/
#define MAX_MAGNITUDE 0xFFFF
enum {
PROP_0,
PROP_MAGNITUDE,
@@ -103,13 +106,18 @@ fbd_feedback_vibra_periodic_start_vibra (FbdFeedbackVibra *vibra)
FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);
guint duration = fbd_feedback_vibra_get_duration (vibra);
double max_strength = fbd_feedback_vibra_get_max_strength (FBD_FEEDBACK_VIBRA (self));
double fade_in_ratio = (double)self->fade_in_level / self->magnitude;
guint max_magnitude, fade_in_level;
g_return_if_fail (FBD_IS_DEV_VIBRA (dev));
g_debug ("Periodic Vibra: %d %d %d %d",
duration, self->magnitude, self->fade_in_level, self->fade_in_time);
max_magnitude = MIN (MAX_MAGNITUDE * max_strength, self->magnitude);
fade_in_level = MIN (max_magnitude * fade_in_ratio, self->fade_in_level);
fbd_dev_vibra_periodic (dev, duration, self->magnitude, self->fade_in_level,
self->fade_in_time);
g_debug ("Periodic Vibra: %d %d %d %d",
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);
}
static gboolean
@@ -141,7 +149,7 @@ fbd_feedback_vibra_periodic_class_init (FbdFeedbackVibraPeriodicClass *klass)
"magnitude",
"Magnitude",
"total magnitude",
0, 0xFFFF, 0x7FFF,
0, MAX_MAGNITUDE, 0x7FFF,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PROP_FADE_IN_TIME] =
@@ -157,7 +165,7 @@ fbd_feedback_vibra_periodic_class_init (FbdFeedbackVibraPeriodicClass *klass)
"fade-in-level",
"Fade in level",
"Fade in start level",
0, 0xFFFF, 0x7FFF,
0, MAX_MAGNITUDE, 0x7FFF,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
+2 -1
View File
@@ -9,6 +9,7 @@
G_BEGIN_DECLS
void fbd_feedback_vibra_set_duration (FbdFeedbackVibra *self, guint duration);
void fbd_feedback_vibra_set_duration (FbdFeedbackVibra *self, guint duration);
double fbd_feedback_vibra_get_max_strength (FbdFeedbackVibra *self);
G_END_DECLS
+5 -3
View File
@@ -7,6 +7,7 @@
#define G_LOG_DOMAIN "fbd-feedback-vibra-rumble"
#include "fbd-enums.h"
#include "fbd-feedback-vibra-priv.h"
#include "fbd-feedback-vibra-rumble.h"
#include "fbd-feedback-manager.h"
@@ -119,6 +120,7 @@ fbd_feedback_vibra_rumble_start_vibra (FbdFeedbackVibra *vibra)
FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);
guint duration = fbd_feedback_vibra_get_duration (vibra);
double strength = fbd_feedback_vibra_get_max_strength (FBD_FEEDBACK_VIBRA (self));
guint period;
self->rumble = (duration / self->count) - self->pause;
@@ -130,9 +132,9 @@ fbd_feedback_vibra_rumble_start_vibra (FbdFeedbackVibra *vibra)
period = self->rumble + self->pause;
self->periods = self->count;
g_debug ("Rumble Vibra event: duration %d, rumble: %d, pause: %d, period: %d",
duration, self->rumble, self->pause, period);
fbd_dev_vibra_rumble (dev, 1.0, self->rumble, TRUE);
g_debug ("Rumble Vibra event: duration %d, rumble: %d, pause: %d, period: %d, strength %f",
duration, self->rumble, self->pause, period, strength);
fbd_dev_vibra_rumble (dev, strength, self->rumble, TRUE);
self->periods--;
if (self->periods) {
self->timer_id = g_timeout_add (period, (GSourceFunc) on_period_ended, self);
+52 -2
View File
@@ -6,6 +6,7 @@
#define G_LOG_DOMAIN "fbd-feedback-vibra"
#include "fbd.h"
#include "fbd-enums.h"
#include "fbd-feedback-vibra.h"
#include "fbd-feedback-vibra-priv.h"
@@ -29,13 +30,26 @@ enum {
static GParamSpec *props[PROP_LAST_PROP];
typedef struct _FbdFeedbackVibraPrivate {
guint duration;
guint timer_id;
guint duration;
guint timer_id;
double max_strength;
GSettings *settings;
} FbdFeedbackVibraPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (FbdFeedbackVibra, fbd_feedback_vibra, FBD_TYPE_FEEDBACK_BASE);
static void
on_max_haptic_strength_changed (FbdFeedbackVibra *self)
{
FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self);
priv->max_strength = g_settings_get_double (priv->settings, "max-haptic-strength");
g_debug ("Max haptic strength: %f", priv->max_strength);
}
static void
on_timeout_expired (FbdFeedbackVibra *self)
{
@@ -122,12 +136,26 @@ fbd_feedback_vibra_get_property (GObject *object,
}
}
static void
fbd_feedback_vibra_finalize (GObject *object)
{
FbdFeedbackVibra *self = FBD_FEEDBACK_VIBRA (object);
FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self);
g_clear_object (&priv->settings);
G_OBJECT_CLASS (fbd_feedback_vibra_parent_class)->finalize (object);
}
static void
fbd_feedback_vibra_class_init (FbdFeedbackVibraClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass);
object_class->finalize = fbd_feedback_vibra_finalize;
object_class->set_property = fbd_feedback_vibra_set_property;
object_class->get_property = fbd_feedback_vibra_get_property;
@@ -151,6 +179,15 @@ fbd_feedback_vibra_class_init (FbdFeedbackVibraClass *klass)
static void
fbd_feedback_vibra_init (FbdFeedbackVibra *self)
{
FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self);
priv->settings = g_settings_new (FEEDBACKD_SCHEMA_ID);
g_signal_connect_object (priv->settings,
"changed::max-haptic-strength",
G_CALLBACK (on_max_haptic_strength_changed),
self,
G_CONNECT_SWAPPED);
on_max_haptic_strength_changed (self);
}
guint
@@ -179,3 +216,16 @@ fbd_feedback_vibra_set_duration (FbdFeedbackVibra *self, guint duration)
priv->duration = duration;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_DURATION]);
}
double
fbd_feedback_vibra_get_max_strength (FbdFeedbackVibra *self)
{
FbdFeedbackVibraPrivate *priv;
g_return_val_if_fail (FBD_IS_FEEDBACK_VIBRA (self), 1.0);
priv = fbd_feedback_vibra_get_instance_private (self);
return priv->max_strength;
}