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:
+1
-1
@@ -22,7 +22,7 @@ dbus_inc = include_directories('.')
|
|||||||
install_data(dbus_interfaces, install_dir: ifacedir)
|
install_data(dbus_interfaces, install_dir: ifacedir)
|
||||||
|
|
||||||
schemas = ['org.sigxcpu.feedbackd.gschema.xml']
|
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)
|
compile_schemas = find_program('glib-compile-schemas', required: false)
|
||||||
if compile_schemas.found()
|
if compile_schemas.found()
|
||||||
|
|||||||
@@ -41,6 +41,16 @@
|
|||||||
setting the 'important' hint on the submitted event.
|
setting the 'important' hint on the submitted event.
|
||||||
</description>
|
</description>
|
||||||
</key>
|
</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>
|
||||||
|
|
||||||
<schema id="org.sigxcpu.feedbackd.application">
|
<schema id="org.sigxcpu.feedbackd.application">
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ These gsettings are used by ``feedbackd``:
|
|||||||
- `prefer-flash`: Prefer camera flash over status LED
|
- `prefer-flash`: Prefer camera flash over status LED
|
||||||
- `theme`: The feedback theme to use. This can be used to override
|
- `theme`: The feedback theme to use. This can be used to override
|
||||||
the feedback theme picked by feedbackd based on device information.
|
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`
|
- `org.sigxcpu.feedbackd.application`
|
||||||
|
|
||||||
|
|||||||
@@ -199,8 +199,12 @@ do_pattern_step (FbdFeedbackVibraPattern *self)
|
|||||||
/* Removing any pending effect */
|
/* Removing any pending effect */
|
||||||
fbd_dev_vibra_remove_effect (dev);
|
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);
|
fbd_dev_vibra_rumble (dev, *magnitude, *duration, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
self->timer_id = g_timeout_add_once (*duration,
|
self->timer_id = g_timeout_add_once (*duration,
|
||||||
on_timer_expired,
|
on_timer_expired,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#define G_LOG_DOMAIN "fbd-feedback-vibra-periodic"
|
#define G_LOG_DOMAIN "fbd-feedback-vibra-periodic"
|
||||||
|
|
||||||
#include "fbd-enums.h"
|
#include "fbd-enums.h"
|
||||||
|
#include "fbd-feedback-vibra-priv.h"
|
||||||
#include "fbd-feedback-vibra-periodic.h"
|
#include "fbd-feedback-vibra-periodic.h"
|
||||||
#include "fbd-feedback-manager.h"
|
#include "fbd-feedback-manager.h"
|
||||||
|
|
||||||
@@ -20,6 +21,8 @@
|
|||||||
* #FbdDevVibra for that.
|
* #FbdDevVibra for that.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define MAX_MAGNITUDE 0xFFFF
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_MAGNITUDE,
|
PROP_MAGNITUDE,
|
||||||
@@ -103,13 +106,18 @@ fbd_feedback_vibra_periodic_start_vibra (FbdFeedbackVibra *vibra)
|
|||||||
FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
|
FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
|
||||||
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 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_return_if_fail (FBD_IS_DEV_VIBRA (dev));
|
||||||
g_debug ("Periodic Vibra: %d %d %d %d",
|
max_magnitude = MIN (MAX_MAGNITUDE * max_strength, self->magnitude);
|
||||||
duration, self->magnitude, self->fade_in_level, self->fade_in_time);
|
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,
|
g_debug ("Periodic Vibra: %d %d %d %d",
|
||||||
self->fade_in_time);
|
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
|
static gboolean
|
||||||
@@ -141,7 +149,7 @@ fbd_feedback_vibra_periodic_class_init (FbdFeedbackVibraPeriodicClass *klass)
|
|||||||
"magnitude",
|
"magnitude",
|
||||||
"Magnitude",
|
"Magnitude",
|
||||||
"total magnitude",
|
"total magnitude",
|
||||||
0, 0xFFFF, 0x7FFF,
|
0, MAX_MAGNITUDE, 0x7FFF,
|
||||||
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,7 +165,7 @@ fbd_feedback_vibra_periodic_class_init (FbdFeedbackVibraPeriodicClass *klass)
|
|||||||
"fade-in-level",
|
"fade-in-level",
|
||||||
"Fade in level",
|
"Fade in level",
|
||||||
"Fade in start level",
|
"Fade in start level",
|
||||||
0, 0xFFFF, 0x7FFF,
|
0, MAX_MAGNITUDE, 0x7FFF,
|
||||||
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);
|
||||||
|
|||||||
@@ -10,5 +10,6 @@
|
|||||||
G_BEGIN_DECLS
|
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
|
G_END_DECLS
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#define G_LOG_DOMAIN "fbd-feedback-vibra-rumble"
|
#define G_LOG_DOMAIN "fbd-feedback-vibra-rumble"
|
||||||
|
|
||||||
#include "fbd-enums.h"
|
#include "fbd-enums.h"
|
||||||
|
#include "fbd-feedback-vibra-priv.h"
|
||||||
#include "fbd-feedback-vibra-rumble.h"
|
#include "fbd-feedback-vibra-rumble.h"
|
||||||
#include "fbd-feedback-manager.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 ();
|
FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
|
||||||
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 strength = fbd_feedback_vibra_get_max_strength (FBD_FEEDBACK_VIBRA (self));
|
||||||
guint period;
|
guint period;
|
||||||
|
|
||||||
self->rumble = (duration / self->count) - self->pause;
|
self->rumble = (duration / self->count) - self->pause;
|
||||||
@@ -130,9 +132,9 @@ fbd_feedback_vibra_rumble_start_vibra (FbdFeedbackVibra *vibra)
|
|||||||
period = self->rumble + self->pause;
|
period = self->rumble + self->pause;
|
||||||
self->periods = self->count;
|
self->periods = self->count;
|
||||||
|
|
||||||
g_debug ("Rumble Vibra event: duration %d, rumble: %d, pause: %d, period: %d",
|
g_debug ("Rumble Vibra event: duration %d, rumble: %d, pause: %d, period: %d, strength %f",
|
||||||
duration, self->rumble, self->pause, period);
|
duration, self->rumble, self->pause, period, strength);
|
||||||
fbd_dev_vibra_rumble (dev, 1.0, self->rumble, TRUE);
|
fbd_dev_vibra_rumble (dev, strength, self->rumble, TRUE);
|
||||||
self->periods--;
|
self->periods--;
|
||||||
if (self->periods) {
|
if (self->periods) {
|
||||||
self->timer_id = g_timeout_add (period, (GSourceFunc) on_period_ended, self);
|
self->timer_id = g_timeout_add (period, (GSourceFunc) on_period_ended, self);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#define G_LOG_DOMAIN "fbd-feedback-vibra"
|
#define G_LOG_DOMAIN "fbd-feedback-vibra"
|
||||||
|
|
||||||
|
#include "fbd.h"
|
||||||
#include "fbd-enums.h"
|
#include "fbd-enums.h"
|
||||||
#include "fbd-feedback-vibra.h"
|
#include "fbd-feedback-vibra.h"
|
||||||
#include "fbd-feedback-vibra-priv.h"
|
#include "fbd-feedback-vibra-priv.h"
|
||||||
@@ -31,11 +32,24 @@ static GParamSpec *props[PROP_LAST_PROP];
|
|||||||
typedef struct _FbdFeedbackVibraPrivate {
|
typedef struct _FbdFeedbackVibraPrivate {
|
||||||
guint duration;
|
guint duration;
|
||||||
guint timer_id;
|
guint timer_id;
|
||||||
|
double max_strength;
|
||||||
|
|
||||||
|
GSettings *settings;
|
||||||
} FbdFeedbackVibraPrivate;
|
} FbdFeedbackVibraPrivate;
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_PRIVATE (FbdFeedbackVibra, fbd_feedback_vibra, FBD_TYPE_FEEDBACK_BASE);
|
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
|
static void
|
||||||
on_timeout_expired (FbdFeedbackVibra *self)
|
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
|
static void
|
||||||
fbd_feedback_vibra_class_init (FbdFeedbackVibraClass *klass)
|
fbd_feedback_vibra_class_init (FbdFeedbackVibraClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_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->set_property = fbd_feedback_vibra_set_property;
|
||||||
object_class->get_property = fbd_feedback_vibra_get_property;
|
object_class->get_property = fbd_feedback_vibra_get_property;
|
||||||
|
|
||||||
@@ -151,6 +179,15 @@ fbd_feedback_vibra_class_init (FbdFeedbackVibraClass *klass)
|
|||||||
static void
|
static void
|
||||||
fbd_feedback_vibra_init (FbdFeedbackVibra *self)
|
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
|
guint
|
||||||
@@ -179,3 +216,16 @@ fbd_feedback_vibra_set_duration (FbdFeedbackVibra *self, guint duration)
|
|||||||
priv->duration = duration;
|
priv->duration = duration;
|
||||||
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user