-
-
Save atcasanova/005b707d7997bcefb3f4bdccb333a13a to your computer and use it in GitHub Desktop.
Driver para decibelímetro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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