#!/bin/sh
#miror ==============================
#Display text mirorred verticaly and horizontally using NiLuJe's tools
# ʇɟǝןʎdoƆ (ↄ) 2020-11-19 PoP under Creative Commons Attribution-ShareAlike 3.0 Unported License
#2019-11-19 v0.10 initial version
#Usage:
#turn [-S NUM] [-F FONTNAME] [other] [-T "TEXT"] where
#           -S is the font scaling factor
#           -F FONTNAME fixed pixel fontname to use
#           -T "TEXT" ASCII text to print (defaults to a suitable latin palindrome)
#           other parameters to pass to fbink
#dependencies: fbink / fbgrab v1.22.2 from usbnet v0.22 hack 
#              convert cli from ImageMagick v6.9.11-34 from linkss v0.25 hack 

#https://en.wikipedia.org/wiki/Sator_Square
T=$'SATOR\nAREPO\nTENET\nOPERA\nROTAS'

#beware: a "-" in the string, would cause fbink to parse it as an argument, hence the "_" above
S=0;F="IBM";other="";COLOR="BLACK";

while [ "$1" != '' ]; do #parse parameters, no validation!
  case "$1" in
        -S) shift;S=$1;shift;;
        -F) shift;F=$1;shift;;
        -T) shift;T="$1";shift;;
         *) other="$other $1";shift;;
  esac
done
$q="-q" #to debug $q=" "

#Quiet the Kindle
  lipc-set-prop com.lab126.powerd preventScreenSaver 1 #disable screen saver
  killall -stop cvm # pause framework

cd /mnt/us
fbink $q -c -M -m -B GRAY9 -g file=satorsquare.png,halign=CENTER,valign=CENTER

fbgrab fbgrab.png #grab it

#top left
         fbink $q -O -S $S -C $COLOR -F $F "$T" #overly the text to write
         fbgrab fbgrab.png
#top right
         ./linkss/bin/convert -flip fbgrab.png fbgrab.png #miror vertically
         fbink $q -g file=fbgrab.png
         fbink $q -O -S $S -C $COLOR -F $F "$T" #overly the text to write
         fbgrab fbgrab.png
#bottom left
         ./linkss/bin/convert -flip -flop fbgrab.png fbgrab.png #miror vertically and horizontally
         fbink $q -g file=fbgrab.png
         fbink $q -O -S $S -C $COLOR -F $F "$T" #overly the text to write
         fbgrab fbgrab.png
#bottom right
         ./linkss/bin/convert -flip fbgrab.png fbgrab.png #miror vertically
         fbink $q -g file=fbgrab.png
         fbink $q -O -S $S -C $COLOR -F $F "$T" #overly the text to write
         fbgrab fbgrab.png

#Revive the Kindle
    ./linkss/bin/convert -flip -flop fbgrab.png fbgrab.png #back to initial state
    killall -cont cvm #resume framework activity
    lipc-set-prop com.lab126.powerd preventScreenSaver 0  #enable screen saver