Advertisement
atcasanova

redbutton driver

Jan 20th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.75 KB | None | 0 0
  1. #!/bin/bash
  2. LID_CLOSED=21
  3. BUTTON_PRESSED=22
  4. LID_OPEN=23
  5.  
  6. while true
  7. do
  8.     echo -ne "\x08\x00\x00\x00\x00\x00\x00\x02" > buf
  9.     dd if=buf of=/dev/hidraw3 bs=8 count=1 conv=notrunc
  10.     rm -f buf
  11.     dd if=/dev/hidraw3 of=buf bs=1 count=1
  12.     last=$LID_CLOSED
  13.     siz=$(cat buf | wc -c)
  14.     [ $siz -eq 1 ] || continue
  15.     status=$(head -c1 buf)
  16.     estado=$(echo $status | od -h | grep -Eo "0a[0-9]{2}" | cut -f2 -da)
  17.     echo $estado
  18.     status=$((16#$estado))
  19.     echo last: $last
  20.     echo status: $status
  21.     [ $last -eq $LID_CLOSED -a $status -eq $LID_OPEN ] && echo LID OPEN $last $status
  22.     [ $last -ne $BUTTON_PRESSED -a $status -eq $BUTTON_PRESSED ] && echo FIRE $last $status
  23.     [ $last -ne $LID_CLOSED -a $status -eq $LID_CLOSED ] && echo LID CLOSED $last $status
  24.     last=$status
  25. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement