Advertisement
atcasanova

Untitled

Jan 20th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.98 KB | None | 0 0
  1. #!/bin/bash
  2. # Bash script to control dream-cheeky red button
  3. # Inspirated by Malcolm Sparks <malcolm@congreve.com> C driver
  4. # for the same device.
  5. # developed mostly by Fernando Merces <www.mentebinaria.com.br>
  6. # with some contributions by Alfredo Casanova <atcasanova@gmail.com>
  7. ######################################################################
  8.  
  9. lid_closed=21
  10. button_pressed=22
  11. lid_open=23
  12.  
  13. last=$lid_closed
  14. buffer="\x08\x00\x00\x00\x00\x00\x00\x02"
  15.  
  16. while true; do
  17.     sleep 0.05
  18.     echo -ne "$buffer" > /dev/hidraw3
  19.     buf=$(timeout 0.02 head -c1 /dev/hidraw3)
  20.     [ ${#buf} -eq 1 ] || continue
  21.     status=$(echo -ne "$buf" | hexdump -ve '"%d"')
  22.     if (( $last == $lid_closed )) && (( $status == $lid_open )); then
  23.         echo "LID OPEN $last $status"
  24.     elif (( $last != $button_pressed )) && (( $status == $button_pressed )); then
  25.         echo "FIRE $last $status"
  26.     elif (( $last != $lid_closed )) && (( $status == $lid_closed )); then
  27.         echo "LID CLOSED $last $status"
  28.     fi
  29.     last=$status
  30. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement