Skip to content

Instantly share code, notes, and snippets.

@rhodrid
Created November 11, 2020 12:19
Show Gist options
  • Save rhodrid/0963c228ebac265752ef30701c290a07 to your computer and use it in GitHub Desktop.
Save rhodrid/0963c228ebac265752ef30701c290a07 to your computer and use it in GitHub Desktop.
QNAP LCD control
#!/bin/bash
TEXT="${@:2:$#}"
function printUsage() {
echo "Usage: $0 <off|on>"
echo "Usage: $0 <1|2> Text Message"
exit 0
}
function setDisplay() {
if [ ${#2} -gt 15 ]; then
echo "String to set can be max 16 characters!"
exit 1
fi
printf "Setting line $1 on display to \"%s\"\n" "$2"
# Text we print must be padded to exactly 16 characters to wipe old text
printf "M\f\x`expr $1 - 1` %-16s" "$2" > /dev/ttyS1
}
if [ $# -eq 0 ]; then
printUsage
fi
stty -F /dev/ttyS1 1200
if [ $1 = "off" ]; then
echo "Turning display off"
echo -e "M^\x0" > /dev/ttyS1
exit 0
fi
if [ $1 = "on" ]; then
echo "Turning display on"
echo -e "M^\x1" > /dev/ttyS1
exit 0
fi
if [ $1 = "1" ] || [ $1 = "2" ]; then
setDisplay $1 "$TEXT"
exit 0
fi
printUsage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment