dev-vibra: Allow to check if the device is busy
We accept `NULL` to make the case of no haptic easy to handle. Signed-off-by: Guido Günther <agx@sigxcpu.org>
This commit is contained in:
@@ -219,6 +219,7 @@ fbd_dev_vibra_class_init (FbdDevVibraClass *klass)
|
|||||||
static void
|
static void
|
||||||
fbd_dev_vibra_init (FbdDevVibra *self)
|
fbd_dev_vibra_init (FbdDevVibra *self)
|
||||||
{
|
{
|
||||||
|
self->id = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
FbdDevVibra *
|
FbdDevVibra *
|
||||||
@@ -330,11 +331,16 @@ fbd_dev_vibra_remove_effect (FbdDevVibra *self)
|
|||||||
{
|
{
|
||||||
g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE);
|
g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE);
|
||||||
|
|
||||||
|
if (self->id == -1)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
g_debug("Erasing vibra effect (%d)", self->fd);
|
g_debug("Erasing vibra effect (%d)", self->fd);
|
||||||
if (ioctl(self->fd, EVIOCRMFF, self->id) == -1) {
|
if (ioctl(self->fd, EVIOCRMFF, self->id) == -1) {
|
||||||
g_warning ("Failed to erase vibra effect with id %d: %s", self->id, strerror(errno));
|
g_warning ("Failed to erase vibra effect with id %d: %s", self->id, strerror(errno));
|
||||||
|
self->id = -1;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
self->id = -1;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,6 +352,9 @@ fbd_dev_vibra_stop (FbdDevVibra *self)
|
|||||||
|
|
||||||
g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE);
|
g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE);
|
||||||
|
|
||||||
|
if (self->id == -1)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
stop.type = EV_FF;
|
stop.type = EV_FF;
|
||||||
stop.code = self->id;
|
stop.code = self->id;
|
||||||
stop.value = 0;
|
stop.value = 0;
|
||||||
@@ -365,3 +374,22 @@ fbd_dev_vibra_get_device (FbdDevVibra *self)
|
|||||||
|
|
||||||
return self->device;
|
return self->device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fbd_dev_vibra_is_busy:
|
||||||
|
* @self: The vibra device
|
||||||
|
*
|
||||||
|
* Check whether the device is currently in used
|
||||||
|
*
|
||||||
|
* Returns: `TRUE` when the device is in use, otherwise `FALSE`
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
fbd_dev_vibra_is_busy (FbdDevVibra *self)
|
||||||
|
{
|
||||||
|
if (self == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), TRUE);
|
||||||
|
|
||||||
|
return self->id != -1;
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -21,6 +21,6 @@ gboolean fbd_dev_vibra_periodic (FbdDevVibra *self, guint duration, guint ma
|
|||||||
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);
|
||||||
|
gboolean fbd_dev_vibra_is_busy (FbdDevVibra *self);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
Reference in New Issue
Block a user