Last active
August 29, 2015 14:27
-
-
Save benlinton/8bb7941582e5303980cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
### BEGIN INIT INFO | |
# Provides: lcd | |
# Required-Start: | |
# Required-Stop: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Update LCD display | |
# Description: Update LCD display on the front of the machine. | |
### END INIT INFO | |
# ------------------------------------------------------------------------------ | |
# Initialize local variables | |
# Each line will be truncated after 16 characters | |
# ------------------------------------------------------------------------------ | |
SCRIPT_NAME="lcd" | |
LINE_ONE="Debian" | |
LINE_TWO="`uname -r`" | |
# ------------------------------------------------------------------------------ | |
# Function: mount lcd device | |
# ------------------------------------------------------------------------------ | |
mount_lcd() { | |
/bin/stty -F /dev/ttyS1 1200 | |
} | |
# ------------------------------------------------------------------------------ | |
# Function: disable lcd | |
# ------------------------------------------------------------------------------ | |
disable_lcd() { | |
echo -e "M^\x0" > /dev/ttyS1 | |
} | |
# ------------------------------------------------------------------------------ | |
# Function: enable lcd | |
# ------------------------------------------------------------------------------ | |
enable_lcd() { | |
echo -e "M^\x1" > /dev/ttyS1 | |
} | |
# ------------------------------------------------------------------------------ | |
# Function: write to lcd | |
# Each line will be forced to 16 characters | |
# ------------------------------------------------------------------------------ | |
write_to_lcd() { | |
FORMATTED_LINE_ONE="`printf "%-16.16s" "${LINE_ONE}"`" | |
FORMATTED_LINE_TWO="`printf "%-16.16s" "${LINE_TWO}"`" | |
echo -e "M\f\x0 ${FORMATTED_LINE_ONE}" > /dev/ttyS1 | |
echo -e "M\f\x1 ${FORMATTED_LINE_TWO}" > /dev/ttyS1 | |
} | |
# ------------------------------------------------------------------------------ | |
# Carry out specific functions when asked to by the system | |
# ------------------------------------------------------------------------------ | |
case "$1" in | |
start) | |
echo "Starting ${SCRIPT_NAME}" | |
mount_lcd | |
enable_lcd | |
write_to_lcd | |
;; | |
stop) | |
echo "Stopping ${SCRIPT_NAME}" | |
mount_lcd | |
disable_lcd | |
;; | |
*) | |
echo "Usage: /etc/init.d/${SCRIPT_NAME} {start|stop}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
This file contains hidden or 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
# First mount the LCD | |
stty -F /dev/ttyS1 1200 | |
# Turn off LCD | |
echo -e "M^\x0" > /dev/ttyS1 | |
# Turn on LCD | |
echo -e "M^\x1" > /dev/ttyS1 | |
# Write a message to LCD | |
# Each line should be 16 characters, so pad with spaces if necessary | |
echo -e "M\f\x0 THIS IS 1st LINE" > /dev/ttyS1 | |
echo -e "M\f\x1 THIS IS 2nd LINE" > /dev/ttyS1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment