Advertisement
atcasanova

Untitled

Jan 20th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.78 KB | None | 0 0
  1. #!/bin/bash
  2. LID_CLOSED=21
  3. BUTTON_PRESSED=22
  4. LID_OPEN=23
  5.  
  6. last=$LID_CLOSED
  7. buffer="\x08\x00\x00\x00\x00\x00\x00\x02"
  8.  
  9. while true
  10. do
  11.         echo -ne "$buffer" > /dev/hidraw3
  12.         buf=$(head -c1 /dev/hidraw3)
  13.         [ ${#buf} -eq 1 ] || continue
  14.         status=$(head -c1 <<< $buf)
  15.         status=$(echo -ne "$status" | hexdump -v -e '/1 "%d"')
  16.         if [ $last -eq $LID_CLOSED -a $status -eq $LID_OPEN ]
  17.         then
  18.                 echo LID OPEN $last $status
  19.         elif [ $last -ne $BUTTON_PRESSED -a $status -eq $BUTTON_PRESSED ]
  20.         then
  21.                 echo FIRE $last $status
  22.         elif [ $last -ne $LID_CLOSED -a $status -eq $LID_CLOSED ]
  23.         then
  24.                 echo LID CLOSED $last $status
  25.         fi
  26.         last=$status
  27.         sleep 0.02
  28. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement