#!/bin/bash

# bash current-test-on-device Acc accelerometer "CyWee CWMI Accelerometer"

if test $# != 4; then
    die 'Internal error: must take 4 arguments, like this: Acc accelerometer "CyWee CWMI Accelerometer" start'
fi

input_dev=
for x in /sys/class/input/input*; do
    if test "$(cat $x/name | tr -d \\n)" = "$3"; then
	input_dev=$x
	break
    fi
done

if test -z "$input_dev"; then
    die "Internal error: device '$3' not found"
fi

if ! test -e "$input_dev/active"; then
    die "Internal error: device node $input_dev/active not found"
fi

shift 3
if test "$1" = start -o "$1" = on; then
    echo 1 > $sensor_switch
else 
    echo 0 > $sensor_switch
fi

