imu-setup: Add support for polling mode
Required for HW23. The code is not really clean but helps make the difference between HW21 and HW23. Polling creates a device /dev/imu0 giving the poll frequency. BugzID: 61346
This commit is contained in:
parent
6e851a9fe7
commit
b8370406c5
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import time
|
||||
|
||||
def create_pty(dev):
|
||||
master, slave = os.openpty()
|
||||
slave_file = os.readlink('/proc/self/fd/{}'.format(slave))
|
||||
if os.path.exists(dev):
|
||||
os.remove(dev)
|
||||
os.symlink(slave_file, dev)
|
||||
os.close(slave)
|
||||
return master
|
||||
|
||||
|
||||
def set_sampling_freq(iio_nbr):
|
||||
f = open('/sys/bus/iio/devices/iio:device{}/sampling_frequency'.format(iio_nbr), 'w')
|
||||
f.write('416')
|
||||
|
||||
set_sampling_freq(1)
|
||||
set_sampling_freq(2)
|
||||
|
||||
dev = create_pty('/dev/imu0')
|
||||
|
||||
while True:
|
||||
os.write(dev, b'poll\n')
|
||||
time.sleep(0.1)
|
||||
|
|
@ -7,6 +7,7 @@ Before=gpsd.service
|
|||
Type=oneshot
|
||||
ExecStart=/usr/bin/imu-setup
|
||||
EnvironmentFile=/etc/imu-lsm6ds3.conf
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
WantedBy=multi-user.target
|
||||
|
|
|
|||
|
|
@ -2,12 +2,15 @@
|
|||
ACC_SYSFS_PATH="/sys/bus/iio/devices/iio:device0"
|
||||
GYRO_SYSFS_PATH="/sys/bus/iio/devices/iio:device1"
|
||||
|
||||
echo 0 > $ACC_SYSFS_PATH/buffer/enable
|
||||
echo $ACC_SAMPLING_FREQUENCY > $ACC_SYSFS_PATH/sampling_frequency
|
||||
echo 1 > $ACC_SYSFS_PATH/buffer/enable
|
||||
|
||||
echo 0 > $GYRO_SYSFS_PATH/buffer/enable
|
||||
echo $GYRO_SAMPLING_FREQUENCY > $GYRO_SYSFS_PATH/sampling_frequency
|
||||
echo 1 > $GYRO_SYSFS_PATH/buffer/enable
|
||||
if [ -f "$ACC_SYSFS_PATH/buffer" ]; then
|
||||
echo 0 > $ACC_SYSFS_PATH/buffer/enable
|
||||
echo $ACC_SAMPLING_FREQUENCY > $ACC_SYSFS_PATH/sampling_frequency
|
||||
echo 1 > $ACC_SYSFS_PATH/buffer/enable
|
||||
|
||||
echo 0 > $GYRO_SYSFS_PATH/buffer/enable
|
||||
echo $GYRO_SAMPLING_FREQUENCY > $GYRO_SYSFS_PATH/sampling_frequency
|
||||
echo 1 > $GYRO_SYSFS_PATH/buffer/enable
|
||||
else
|
||||
imu-poll &
|
||||
fi
|
||||
exit 0
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ RDEPENDS_${PN} = "bash"
|
|||
SRC_URI = " \
|
||||
file://imu-setup.service \
|
||||
file://imu-setup.sh \
|
||||
file://imu-poll.py \
|
||||
file://imu-lsm6ds3.conf \
|
||||
"
|
||||
|
||||
|
|
@ -26,6 +27,7 @@ do_install() {
|
|||
|
||||
install -d ${D}${bindir}
|
||||
install -m 744 ${WORKDIR}/imu-setup.sh ${D}${bindir}/imu-setup
|
||||
install -m 755 ${WORKDIR}/imu-poll.py ${D}${bindir}/imu-poll
|
||||
|
||||
install -d ${D}/etc
|
||||
install -m 644 ${WORKDIR}/imu-lsm6ds3.conf ${D}/etc/imu-lsm6ds3.conf
|
||||
|
|
|
|||
Loading…
Reference in New Issue