summarylogtreecommitdiffstats
path: root/wait-for-als-sensor.sh
blob: e187bdb7457f205d852860fe497f0a86b9d3ecf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash

find_iio_device_with_illuminance() {
    for device in /sys/bus/iio/devices/iio:device*; do
        if [ -f "$device/in_illuminance_raw" ]; then
            echo "$device"
            return 0
        fi
    done
    echo "No device found."
    return 1
}


# Timeout in seconds
TIMEOUT=30
INTERVAL=1

while [ $TIMEOUT -gt 0 ]; do
    DEVICE_PATH=$(find_iio_device_with_illuminance)
    if [[ $DEVICE_PATH != "No device found." ]]; then
        echo "Ambient Light Sensor is ready @ $DEVICE_PATH"
        exit 0
    fi
    sleep $INTERVAL
    TIMEOUT=$(( TIMEOUT - INTERVAL ))
done

echo "Ambient Light Sensor not found within the timeout period."
exit 1