Browse Source

Split out initializing the printer

master
mid-kid 1 year ago
parent
commit
3b15f30906
  1. 14
      init_printer.sh
  2. 1
      print_barcode.sh
  3. 12
      print_image.sh
  4. 5
      print_qrcode.sh

14
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

1
print_barcode.sh

@ -1,4 +1,5 @@
#!/bin/bash
./init_printer.sh
printf '\x1Dk\x05'$1'\0' > /dev/usb/lp0
./cut_paper.sh

12
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

5
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

Loading…
Cancel
Save