imu-setup: Check status before configuring

Configuration is not possible while buffer mode is ongoing. The previous
code was making sure that it was disabled but was always enabling it
once done, even if it was not enabled before. But if only the sampling
frequency has been set, it could happen that enabling was not possible.
For example, if no channel was selected. Leading to error messages in
the logs.

BugzID: 62694
This commit is contained in:
Alexandre Bard 2020-04-29 16:54:55 +02:00
parent 99f672de40
commit c628a3f981
1 changed files with 16 additions and 5 deletions

15
recipes-extended/imu-setup/files/imu-setup.sh Normal file → Executable file
View File

@ -2,14 +2,25 @@
ACC_SYSFS_PATH="/sys/bus/iio/devices/iio:device0" ACC_SYSFS_PATH="/sys/bus/iio/devices/iio:device0"
GYRO_SYSFS_PATH="/sys/bus/iio/devices/iio:device1" GYRO_SYSFS_PATH="/sys/bus/iio/devices/iio:device1"
if [ -f "$ACC_SYSFS_PATH/buffer" ]; then if [ -d "$ACC_SYSFS_PATH/buffer" ]; then
echo 0 > $ACC_SYSFS_PATH/buffer/enable buffer_enable=$(cat "$ACC_SYSFS_PATH/buffer/enable")
if [ "$buffer_enable" = "1" ]; then
echo 0 > "$ACC_SYSFS_PATH/buffer/enable"
fi
echo $ACC_SAMPLING_FREQUENCY > $ACC_SYSFS_PATH/sampling_frequency echo $ACC_SAMPLING_FREQUENCY > $ACC_SYSFS_PATH/sampling_frequency
if [ "$buffer_enable" = "1" ]; then
echo 1 > $ACC_SYSFS_PATH/buffer/enable echo 1 > $ACC_SYSFS_PATH/buffer/enable
fi
buffer_enable=$(cat $GYRO_SYSFS_PATH/buffer/enable)
if [ "$buffer_enable" = "1" ]; then
echo 0 > $GYRO_SYSFS_PATH/buffer/enable echo 0 > $GYRO_SYSFS_PATH/buffer/enable
fi
echo $GYRO_SAMPLING_FREQUENCY > $GYRO_SYSFS_PATH/sampling_frequency echo $GYRO_SAMPLING_FREQUENCY > $GYRO_SYSFS_PATH/sampling_frequency
if [ "$buffer_enable" = "1" ]; then
echo 1 > $GYRO_SYSFS_PATH/buffer/enable echo 1 > $GYRO_SYSFS_PATH/buffer/enable
fi
else else
imu-poll & imu-poll &
fi fi