Hey there,
I keep running into a problem whereby my script does not act as I would like it to.
What my goal is:
To read an input (USB RFID reader - emulates PS/2 keyboard via USB) and then have the script perform an action based on the input from the RFID reader. In this case, I want my script to use festival to read out a line of text when a certain card is swiped. The RFID reader reads the swiped tag and outputs a 10-digit number, followed by a line break. This is factory default operation and cannot be customised as this is a sealed unit with no configurable options.
Problem:
Unfortunately the RFID reader is quite sensitive and occasionally double-scans the tag, resulting in e.g. 1234567890\n1234567890\n rather than just 1234567890\n
When swiping the tag and it reads correctly, the script works fine. When a double(or more) swipe occurs, the script acts fine, but then once it has read and spoken, it then does this again and again until all of the duplicate reads are spoken.
I have tried various solutions (e.g. "sleep 3" after the "echo text to say | festival --tts" line, clearing and unsetting the myTag variable, adding an extra "rubbish" variable to the read command but these do not help).
Please find below my latest version of the script so far:
Code:
#!/bin/bash
while(true); do
clear
read -p "swipe tag: " -n 10 myTag rubbish
if [ $myTag == "1234567890" ]; then
echo "you swiped my tag" | festival --tts
else
echo "you did not swipe my tag" | festival --tts
fi
done
I've been puzzling over this for a week now and I just can't seem to see what I've done wrong here. I look forward to seeing some fresh perspectives on this.