#!/bin/bash
# program:
#      program shows the detect of headset function. 
# History:
# 2013/11/6  Zhifang Hu  First release

if test $# = 0; then
    set -- headset
fi

for x in $(seq 1 30); do
    n1=$(cat /sys/devices/virtual/switch/h2w/state)
    if test "$n1" == 0; then
        sleep 1
    else
        echo headset interrupt detected:
        echo "after:  $n1"
        exit 0
    fi
done

die "Did not get headset interrupt after 30 seconds"

