libptouch の更新に追従

This commit is contained in:
knb
2026-04-13 11:39:31 +09:00
parent ae67a8b288
commit f26a1186a3
17 changed files with 399 additions and 140 deletions

View File

@@ -23,6 +23,7 @@ static void usage(const char *argv0)
" -H, --height DOTS 1bit ラスター時: 高さ(ドット)\n"
" -t, --threshold N PNG 二値化しきい値 0255既定 %u、PNG のみ)\n"
" -n, --dry-run 読み込みと check_raster のみUSB なし)\n"
" -p, --pid HEX USB 製品 ID既定: P900W の 0x2085。例: P750W 0x2062、P710BT 0x20af\n"
" -S, --status USB 接続プリンタのステータス(テープ種・幅・色等)を表示して終了\n"
" -V, --version バージョンを表示して終了\n"
" -h, --help このヘルプ\n"
@@ -95,6 +96,7 @@ int main(int argc, char **argv)
const char *file = NULL;
unsigned width = 0, height = 0;
unsigned threshold = LIBPTOUCH_PNG_DEFAULT_THRESHOLD;
unsigned usb_pid_arg = 0;
int dry_run = 0;
int has_threshold = 0;
int want_status = 0;
@@ -104,6 +106,7 @@ int main(int argc, char **argv)
{ "file", required_argument, NULL, 'f' },
{ "threshold", required_argument, NULL, 't' },
{ "dry-run", no_argument, NULL, 'n' },
{ "pid", required_argument, NULL, 'p' },
{ "status", no_argument, NULL, 'S' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
@@ -111,7 +114,7 @@ int main(int argc, char **argv)
};
int c;
while ((c = getopt_long(argc, argv, "w:H:f:t:nhSV", longopts, NULL)) !=
while ((c = getopt_long(argc, argv, "w:H:f:t:p:nhSV", longopts, NULL)) !=
-1) {
switch (c) {
case 'w':
@@ -134,6 +137,13 @@ int main(int argc, char **argv)
case 'n':
dry_run = 1;
break;
case 'p':
usb_pid_arg = (unsigned)strtoul(optarg, NULL, 0);
if (usb_pid_arg == 0u || usb_pid_arg > 0xFFFFu) {
fprintf(stderr, "-p/--pid must be 1..0xFFFF\n");
return 2;
}
break;
case 'S':
want_status = 1;
break;
@@ -159,7 +169,12 @@ int main(int argc, char **argv)
fprintf(stderr, "libptouch_create failed\n");
return 1;
}
libptouch_err_t se = libptouch_open_usb(sctx);
libptouch_err_t se =
usb_pid_arg != 0
? libptouch_open_usb_vid_pid(
sctx, LIBPTOUCH_USB_VID_BROTHER,
(uint16_t)usb_pid_arg)
: libptouch_open_usb(sctx);
if (se != LIBPTOUCH_OK) {
fprintf(stderr, "open_usb: %s\n", libptouch_strerror(sctx));
libptouch_destroy(sctx);
@@ -258,7 +273,10 @@ int main(int argc, char **argv)
return 0;
}
e = libptouch_open_usb(ctx);
e = usb_pid_arg != 0
? libptouch_open_usb_vid_pid(ctx, LIBPTOUCH_USB_VID_BROTHER,
(uint16_t)usb_pid_arg)
: libptouch_open_usb(ctx);
if (e != LIBPTOUCH_OK) {
fprintf(stderr, "open_usb: %s\n", libptouch_strerror(ctx));
libptouch_destroy(ctx);