feat: add dynamic printer configuration manager

Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
This commit is contained in:
dxc
2026-02-11 14:14:59 +08:00
parent 5f3ceef3fd
commit c6fd0aca90
3 changed files with 72 additions and 8 deletions

View File

@ -3,6 +3,7 @@ import base64
import os
from io import BytesIO
from PIL import Image, ImageDraw, ImageFont
from .print_config import PrintConfigManager
# 引入二维码生成库
try:
@ -12,8 +13,7 @@ except ImportError:
class LabelPrintService:
PRINTER_IP = "192.168.9.221"
PRINTER_PORT = 9100
# Printer IP and port now managed by PrintConfigManager
# ================= 1. 尺寸与分辨率配置 (300 DPI) =================
DOTS_PER_MM = 12 # 300 DPI
@ -271,8 +271,9 @@ class LabelPrintService:
@staticmethod
def send_to_printer(data):
ip = LabelPrintService.PRINTER_IP
port = LabelPrintService.PRINTER_PORT
config = PrintConfigManager.get_config('label_printer')
ip = config['ip']
port = config['port']
try:
# 1. 获取 RGB 图像