/** * iio_fixup_sampling_frequency: Fixup devices *sampling_frequency attributes * @dev: the IIO device to fix the sampling frequencies for * * Make sure devices with *sampling_frequency attributes are sampling at * 10Hz or more. This fixes 2 problems: * 1) Some buffered devices default their sampling_frequency to 0Hz and then * never produce any readings. * 2) Some polled devices default to 1Hz and wait for a fresh sample before * returning from sysfs *_raw reads, blocking all of iio-sensor-proxy for * multiple seconds **/ gboolean iio_fixup_sampling_frequency (GUdevDevice *dev) { GDir *dir; const char *device_dir; const char *name; GError *error = NULL; double sample_freq; device_dir = g_udev_device_get_sysfs_path (dev); dir = g_dir_open (g_udev_device_get_sysfs_path (dev), 0, &error); if (!dir) { g_warning ("Failed to open directory '%s': %s", device_dir, error->message); g_error_free (error); return FALSE; } while ((name = g_dir_read_name (dir))) { if (g_str_has_suffix (name, "sampling_frequency") == FALSE) continue; sample_freq = g_udev_device_get_sysfs_attr_as_double (dev, name); if (sample_freq >= IIO_MIN_SAMPLING_FREQUENCY) continue; /* Continue with pre-set sample freq. */ /* Sample freq too low, set it to 10Hz */ if (write_sysfs_int (name, device_dir, IIO_MIN_SAMPLING_FREQUENCY) < 0) g_warning ("Could not fix sample-freq for %s/%s", device_dir, name); } g_dir_close (dir); return TRUE; }
static gboolean iio_poll_accel_open (GUdevDevice *device, ReadingsUpdateFunc callback_func, gpointer user_data) { drv_data = g_new0 (DrvData, 1); drv_data->dev = g_object_ref (device); drv_data->callback_func = callback_func; drv_data->user_data = user_data; drv_data->scale = SCALE_TO_FF(g_udev_device_get_sysfs_attr_as_double (device, "in_accel_scale")); if (drv_data->scale == 0.0) drv_data->scale = 1.0; return TRUE; }