Skip to content

Instantly share code, notes, and snippets.

@atcasanova
Created May 4, 2020 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atcasanova/005b707d7997bcefb3f4bdccb333a13a to your computer and use it in GitHub Desktop.
Save atcasanova/005b707d7997bcefb3f4bdccb333a13a to your computer and use it in GitHub Desktop.
Driver para decibelímetro
#!/bin/bash
initialize(){
random=$(printf '\\x%x' $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256)))
local buffer="\xb3$random\x00\x00\x00\x00"
echo "Initializing with $buffer"
echo -ne "$buffer" > /dev/hidraw2
}
get_status(){
status=
while (( ${#status} != 8 )); do
status+=$(timeout 0.5 head -c8 /dev/hidraw2)
echo $status ${#status}
done
reply=$(echo -n "$status" | hexdump -e '"%d"')
}
print_db(){
get_status
db=${reply:0:2}.${reply:2}
local now=$(date "+%Y-%m-%d %H:%M:%S")
echo "$now $db"
}
initialize
while true; do
print_db
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment