// SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: 2023 SASANO Takayoshi #include #include #include #include #include #include #include #include #include "conv.h" #define BUFSIZE 4096 #define CRLF "\x0d\x0a" #if 1 #define X_SIZE 160 #define Y_SIZE 128 #else #define X_SIZE 320 #define Y_SIZE 240 #endif #define DELAY 250000 #define FONTSIZE 16 static void tx_test(int fd, char *text) { uint8_t buf[BUFSIZE]; sprintf(buf, "RESET;" CRLF); write(fd, buf, strlen(buf)); usleep(250000); sprintf(buf, "CLR(0);DIR(%d);SBC(0);" CRLF, X_SIZE > Y_SIZE); write(fd, buf, strlen(buf)); usleep(250000); sprintf(buf, "DCV%d(%d,%d,'%s',%d)" CRLF, FONTSIZE, 0, 0, text, 15); write(fd, buf, strlen(buf)); usleep(DELAY); } static int setup_serial(int fd) { struct termios t; memset(&t, 0, sizeof(t)); cfsetospeed(&t, 115200); cfsetispeed(&t, 115200); t.c_cflag = CREAD | CLOCAL | CS8; t.c_iflag = INPCK; t.c_oflag = 0; t.c_lflag = 0; t.c_cc[VTIME] = 0; t.c_cc[VMIN] = 1; tcflush(fd, TCIFLUSH); if (tcsetattr(fd, TCSANOW, &t) < 0) goto fail; return 0; fail: return -1; } int main(int argc, char *argv[]) { int fd; wchar_t *wcs; uint8_t *euc; ssize_t n; if (argc < 3) { printf("usage: %s [device] [text]\n", argv[0]); goto fin0; } setlocale(LC_ALL, "ja_JP.UTF-8"); fd = open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY); if (fd < 0) { printf("device open error\n"); goto fin0; } if (setup_serial(fd) < 0) { printf("serial parameter error\n"); goto fin1; } if ((n = mbstowcs(NULL, argv[2], 0)) < 0 || (wcs = calloc(n + 1, sizeof(*wcs))) == NULL) goto fin1; mbstowcs(wcs, argv[2], n + 1); if ((n = convert_euc(NULL, wcs)) < 1 || (euc = calloc(n, sizeof(*euc))) == NULL) goto fin2; convert_euc(euc, wcs); tx_test(fd, euc); free(euc); fin2: free(wcs); fin1: close(fd); fin0: return 0; }