add cut bitmask option and debug dump support
Replace auto-cut toggle with --cut bit flags (default 011), wire flags through C/Ruby APIs, and document the new cut/debug-dump behavior in both READMEs. Made-with: Cursor
This commit is contained in:
@@ -27,6 +27,9 @@ static void usage(const char *argv0)
|
||||
" -n, --dry-run 読み込みと check_raster のみ(USB なし)\n"
|
||||
" -v, --verbose 印刷前情報と印刷後ステータスを標準出力\n"
|
||||
" -p, --pid HEX USB 製品 ID(既定: P900W の 0x2085)。例: P750W 0x2062、P710BT 0x20af\n"
|
||||
" --cut BITS 3bit 指定: [auto-cut][half-cut][chain-print] (例: 010)\n"
|
||||
" 既定: 011(オートカットしない、ハーフカットする、つなげて印刷する)\n"
|
||||
" --debug-dump PATH デバッグ: USB に送った印字データをファイルへ保存(1 印刷ごとに上書き)\n"
|
||||
" -S, --status ステータスを表示して終了\n"
|
||||
" -V, --version バージョンを表示して終了\n"
|
||||
" -h, --help このヘルプ\n"
|
||||
@@ -103,6 +106,25 @@ static int read_file(const char *path, uint8_t **out, size_t *out_len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_cut_bits(const char *s, uint8_t *out_flags)
|
||||
{
|
||||
if (!s || strlen(s) != 3u)
|
||||
return -1;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (s[i] != '0' && s[i] != '1')
|
||||
return -1;
|
||||
}
|
||||
uint8_t flags = 0u;
|
||||
if (s[0] == '1')
|
||||
flags |= LIBPTOUCH_RASTER_FLAG_AUTO_CUT;
|
||||
if (s[1] == '1')
|
||||
flags |= LIBPTOUCH_RASTER_FLAG_HALF_CUT;
|
||||
if (s[2] == '1')
|
||||
flags |= LIBPTOUCH_RASTER_FLAG_CHAIN_PRINT;
|
||||
*out_flags = flags;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void verbose_print_pre_print_info(libptouch_ctx *ctx,
|
||||
const libptouch_raster_params_t *params,
|
||||
size_t data_len)
|
||||
@@ -115,6 +137,11 @@ static void verbose_print_pre_print_info(libptouch_ctx *ctx,
|
||||
printf("raster size: %ux%u dots (length x width)\n",
|
||||
(unsigned)params->width_dots, (unsigned)params->height_dots);
|
||||
printf("margin_mm: %u\n", (unsigned)params->margin_mm);
|
||||
printf("raster flags: 0x%02X (auto-cut %s, half-cut %s, chain-print %s)\n",
|
||||
(unsigned)params->flags,
|
||||
(params->flags & LIBPTOUCH_RASTER_FLAG_AUTO_CUT) ? "on" : "off",
|
||||
(params->flags & LIBPTOUCH_RASTER_FLAG_HALF_CUT) ? "on" : "off",
|
||||
(params->flags & LIBPTOUCH_RASTER_FLAG_CHAIN_PRINT) ? "on" : "off");
|
||||
|
||||
libptouch_media_info_t mi;
|
||||
if (libptouch_get_current_media_info(ctx, &mi) == LIBPTOUCH_OK) {
|
||||
@@ -183,6 +210,8 @@ int main(int argc, char **argv)
|
||||
unsigned trim_right_dots = 0;
|
||||
int has_threshold = 0;
|
||||
int want_status = 0;
|
||||
uint8_t cut_flags = LIBPTOUCH_RASTER_FLAGS_DEFAULT;
|
||||
const char *debug_dump_path = NULL;
|
||||
static struct option longopts[] = {
|
||||
{ "width", required_argument, NULL, 'w' },
|
||||
{ "height", required_argument, NULL, 'H' },
|
||||
@@ -195,6 +224,8 @@ int main(int argc, char **argv)
|
||||
{ "status", no_argument, NULL, 'S' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "cut", required_argument, NULL, 1000 },
|
||||
{ "debug-dump", required_argument, NULL, 1001 },
|
||||
{ NULL, 0, NULL, 0 },
|
||||
};
|
||||
|
||||
@@ -246,6 +277,16 @@ int main(int argc, char **argv)
|
||||
return 2;
|
||||
}
|
||||
break;
|
||||
case 1000:
|
||||
if (parse_cut_bits(optarg, &cut_flags) != 0) {
|
||||
fprintf(stderr,
|
||||
"--cut must be 3 bits (e.g. 010: auto/half/chain)\n");
|
||||
return 2;
|
||||
}
|
||||
break;
|
||||
case 1001:
|
||||
debug_dump_path = optarg;
|
||||
break;
|
||||
case 'S':
|
||||
want_status = 1;
|
||||
break;
|
||||
@@ -329,10 +370,12 @@ int main(int argc, char **argv)
|
||||
fprintf(stderr, "libptouch_create failed\n");
|
||||
return 1;
|
||||
}
|
||||
if (debug_dump_path)
|
||||
libptouch_set_debug_dump_path(ctx, debug_dump_path);
|
||||
|
||||
uint8_t *data = NULL;
|
||||
size_t data_len = 0;
|
||||
libptouch_raster_params_t params = { 0, 0, 0 };
|
||||
libptouch_raster_params_t params = { 0 };
|
||||
libptouch_err_t e;
|
||||
int usb_opened = 0;
|
||||
int data_from_lib = 0;
|
||||
@@ -406,7 +449,7 @@ int main(int argc, char **argv)
|
||||
|
||||
uint8_t *trimmed = NULL;
|
||||
size_t trimmed_len = 0;
|
||||
libptouch_raster_params_t trimmed_params = { 0, 0, 0 };
|
||||
libptouch_raster_params_t trimmed_params = { 0 };
|
||||
e = libptouch_trim_right_blank_columns(
|
||||
ctx, data, data_len, ¶ms, pad, &trimmed, &trimmed_len,
|
||||
&trimmed_params);
|
||||
@@ -430,6 +473,10 @@ int main(int argc, char **argv)
|
||||
data_from_lib = 1;
|
||||
}
|
||||
|
||||
params.flags = cut_flags;
|
||||
params._reserved[0] = 0u;
|
||||
params._reserved[1] = 0u;
|
||||
|
||||
e = libptouch_check_raster(ctx, data, data_len, ¶ms);
|
||||
if (e != LIBPTOUCH_OK) {
|
||||
fprintf(stderr, "check_raster: %s\n",
|
||||
|
||||
Reference in New Issue
Block a user