Skip to content

Commit

Permalink
build_bitmap_print_tspl_cmd 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sukso96100 committed Jun 22, 2024
1 parent e1161a7 commit 1b490e0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions usbserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import usb.core
import usb.backend.libusb1
import os
import struct
import codecs

app = Flask(__name__)

Expand All @@ -23,6 +25,18 @@ def get_device_list():
})
return device_list_dict

def build_bitmap_print_tspl_cmd(x, y, img_width_px, img_height_px, canvas_width_mm, canvas_height_mm, image_bitmap):
width_in_bytes = (img_width_px // 8)
commands_bytearray = bytearray()
commands_list = [
f"SIZE {canvas_width_mm} mm,{canvas_height_mm} mm\r\nCLS\r\n".encode(),
f"BITMAP {x},{y},{width_in_bytes},{img_height_px},1, ".encode(),
image_bitmap,
"\r\nPRINT 1\r\nEND\r\n".encode(),
]
for cmd in commands_list:
commands_bytearray.append(cmd)
return commands_bytearray
@app.route('/write_usb/<int:vendor_id>/<int:product_id>', methods=['POST'])
def write_usb(vendor_id, product_id):
if os.getenv("LIBUSB_PATH", None) is not None:
Expand Down

0 comments on commit 1b490e0

Please sign in to comment.