Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- fullPage=10 # How many pages before a full refresh?
- ### Do not edit below this line unless you know what you are doing ###
- ## Get cvm PID
- read cvmPid < /var/run/cvm.pid
- if [[ -z "$cvmPid" ]]; then
- echo "cvm isn't running..."
- exit 2
- fi
- pCount=0
- fullPage="$(($fullPage-1))"
- if [[ ! -e "/var/run/flashDis.pid" ]]; then
- echo $$ > "/var/run/flashDis.pid"
- else
- echo "Flash disabler is already running"
- exit 1
- fi
- trap "enableFlash ; rm /var/run/flashDis.pid ; exit" SIGINT SIGTERM
- update() {
- waitForEink
- ## Do some fancy stuff to make the page look decent
- echo 19 0 > /proc/eink_fb/update_display
- echo 0 > /sys/devices/platform/eink_fb.0/override_upd_mode
- echo 18 0 > /proc/eink_fb/update_display
- echo 1 > /sys/devices/platform/eink_fb.0/override_upd_mode
- echo 19 4 > /proc/eink_fb/update_display
- ## Sets the next page turn to be a full refresh
- let pCount+=1
- if [[ "$pCount" -ge "$fullPage" ]]; then
- echo 0 > /sys/devices/platform/eink_fb.0/override_upd_mode
- echo 19 0 > /proc/eink_fb/update_display
- pCount=0
- fi
- }
- enableFlash() {
- echo 0 > /sys/devices/platform/eink_fb.0/override_upd_mode
- echo 19 0 > /proc/eink_fb/update_display
- }
- ## Check if we need to look for a book/check if current book is open
- bookCheck() {
- if [[ -n "$fd" -a -n "$book" ]]; then
- if [[ "$(realpath /proc/$cvmPid/fd/$fd 2> /dev/null)" == "$book" ]]; then
- if [[ "$bookType" != "BAD" ]]; then
- update
- else
- enableFlash
- fi
- else
- book=""
- bookType=""
- findBook
- fi
- else
- findBook
- fi
- }
- ## Check if cvm has a file descriptor open in /mnt/us/documents
- findBook() {
- enableFlash
- fd="$(ls -l /proc/$cvmPid/fd/ | awk '/\/mnt\/us\/documents\// {print $9}')"
- if [[ -n "$fd" ]]; then
- book="$(realpath /proc/$cvmPid/fd/$fd 2> /dev/null)"
- bookType="${book##*.}"
- case $bookType in
- [Mm][Oo][Bb][Ii]|[Pp][Dd][Ff]|[Pp][Rr][Cc]|[Aa][Zz][Ww]*|[Tt][Xx][Tt])
- update
- ;;
- *)
- bookType="BAD"
- ;;
- esac
- fi
- }
- ## Check if /var/log/messages has changed within the last second
- waitForEink() {
- c=1
- while [[ "$(stat -c %Y /var/log/messages)" -lt "$time" -a "$c" -lt "10" ]]; do
- let c+=1
- usleep 100000
- done
- }
- ## Wait for page turn
- while :; do
- case "$(waitforkey)" in
- 191*|109*|104*|193*)
- time="$(($(date +%s)-1))"
- bookCheck
- ;;
- esac
- usleep 100000
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement