diff --git a/init_printer.sh b/init_printer.sh new file mode 100755 index 0000000..d1472e3 --- /dev/null +++ b/init_printer.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e +dev=/dev/usb/lp0 + +# Initialize printer +printf '\x1B@' > $dev + +# Set print speed +printf '\x1D(K\2\0' > $dev +printf '21' > $dev + +# Set head energizing +printf '\x1D(K\2\0' > $dev +printf 'a4' > $dev # 0-4, or \x80 for automatic, default=0 diff --git a/print_barcode.sh b/print_barcode.sh index 5ccbe3c..d37a15d 100755 --- a/print_barcode.sh +++ b/print_barcode.sh @@ -1,4 +1,5 @@ #!/bin/bash +./init_printer.sh printf '\x1Dk\x05'$1'\0' > /dev/usb/lp0 ./cut_paper.sh diff --git a/print_image.sh b/print_image.sh index b9f8d3a..6ca9e1d 100755 --- a/print_image.sh +++ b/print_image.sh @@ -15,16 +15,7 @@ size="$(hex_size "$(("$size" + 10))")" size_x="$(hex_size "$(echo "$data_header" | cut -d' ' -f 1)")" size_y="$(hex_size "$(echo "$data_header" | cut -d' ' -f 2)")" -# Initialize printer -printf '\x1B@' > $dev - -# Set print speed -printf '\x1D(K\2\0' > $dev -printf '21' > $dev - -# Set head energizing -printf '\x1D(K\2\0' > $dev -printf 'a4' > $dev # 0-4, or \x80 for automatic, default=0 +./init_printer.sh # Upload graphics data printf '\x1D(L' > $dev @@ -40,5 +31,4 @@ echo "$data" | base64 -d > $dev printf '\x1D(L\2\0' > $dev printf '02' > $dev -# Cut paper ./cut_paper.sh diff --git a/print_qrcode.sh b/print_qrcode.sh index c51b398..dfa3626 100755 --- a/print_qrcode.sh +++ b/print_qrcode.sh @@ -7,6 +7,8 @@ size="$(printf '%s' "$text" | wc -c)" size="$(expr "$size" + 3)" size="$(printf '%04x' "$size" | sed -e 's/\(..\)\(..\)/\\x\2\\x\1/g')" +./init_printer.sh + # Store data printf '\x1D(k' > $dev printf "$size" > $dev @@ -17,5 +19,4 @@ printf '%s' "$text" > $dev printf '\x1D(k' > $dev printf '\x03\0\x31\x51\x30' > $dev -# Cut paper -printf '\x1DVA\0' > $dev +./cut_paper.sh