From 781a02dce68e924fed62f0bb60c6bc74e96dac78 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sat, 16 May 2020 16:29:32 +0200 Subject: [PATCH] Add printer scripts --- printer/scripts/convert.sh | 29 ++++++++++++++++++++++++++++ printer/scripts/print.sh | 39 ++++++++++++++++++++++++++++++++++++++ printer/scripts/shared.sh | 6 ++++++ 3 files changed, 74 insertions(+) create mode 100755 printer/scripts/convert.sh create mode 100755 printer/scripts/print.sh create mode 100755 printer/scripts/shared.sh diff --git a/printer/scripts/convert.sh b/printer/scripts/convert.sh new file mode 100755 index 0000000..5cf372e --- /dev/null +++ b/printer/scripts/convert.sh @@ -0,0 +1,29 @@ +#!/bin/bash +source shared.sh + +if [ "$1" == "" ]; then + echo "usage: $0 " + exit; +fi + +mkdir -p out +rm out/* + +echo ".ll $LL" > out/header +cat "$1" | sed 's/\./\\\&./g' > out/text +echo ".sp 0" > out/footer +cat out/header out/text out/footer | nroff -Tascii > out/render + +cline=0 +page=1 +while IFS="" read -r p || [ -n "$p" ] +do + cline=$(($cline + 1)) + if [ $cline -eq $PL ]; then + page=$(($page + 1)) + cline=0 + fi + printf '%s\n' "$p" >> "out/out$page.txt" +done < out/render + +echo "Created $page pages." diff --git a/printer/scripts/print.sh b/printer/scripts/print.sh new file mode 100755 index 0000000..18d408e --- /dev/null +++ b/printer/scripts/print.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +source shared.sh + +ML=$(( (110-$LL) / 2)) +MT=$(( (64 - $PL) / 2 )) +echo "Margin left: $ML" +echo "Margin top : $MT" +echo "Page width : $LL" +echo "Page length: $PL" + +if [ $MT -gt 127 ]; then + echo "Margin top > 127 not supported because I am lazy. Is $MT." + exit +fi +MT=$(( $MT + 128 )) # Set "move by n line bit" +#exit +echo -ne $(printf "\\\\x%02x\\\\x%02x" 224 $ML) > /dev/lw35 +MR=$((ML + $LL + 2)); # Plus 2 because bug in FW in conjunction with manual newlines +echo -ne $(printf "\\\\x%02x\\\\x%02x" 225 $MR) > /dev/lw35 + +for file in ./out/out*; do + foo="" + while [ true ]; do + echo "Insert a piece of paper and press enter. When you're done, enter y." + read foo + if [ "$foo" == "y" ]; then + break; + fi + echo -ne "\xE3\x8C" > /dev/lw35 # Draw in until at top of paper + echo -ne $(printf "\\\\x%02x\\\\x%02x" 0xE3 $MT) > /dev/lw35 # Move over margin top + done + echo "Printing part $file..." + + cat $file > /dev/lw35 + echo "Part done." +done + +echo "Done." diff --git a/printer/scripts/shared.sh b/printer/scripts/shared.sh new file mode 100755 index 0000000..fe4a8a5 --- /dev/null +++ b/printer/scripts/shared.sh @@ -0,0 +1,6 @@ +#!/bin/bash + + # Limits for A4 vertical +LL=80 # Max 90 +PL=58 # Max 64 +