// code by SASANO Takayoshi, CC BY-SA #include #include #include #include #include #include #include #define BUFSIZE 256 #define CRLF "\x0d\x0a" #if 1 #define FONTSIZE 16 #define X_SIZE 160 #define Y_SIZE 128 #define DELAY 540000 #else #define FONTSIZE 24 #define X_SIZE 320 #define Y_SIZE 240 #define DELAY 2600000 #endif static void tx_test(int fd) { unsigned int i, n; uint8_t buf[BUFSIZE], tmp[BUFSIZE]; sprintf(buf, "RESET;" CRLF); write(fd, buf, strlen(buf)); usleep(250000); sprintf(buf, "CLR(0);DIR(1);" CRLF); write(fd, buf, strlen(buf)); usleep(250000); memset(tmp, ' ', sizeof(tmp)); tmp[X_SIZE / (FONTSIZE / 2)] = '\0'; for (n = 0;; n++) { sprintf(buf, "SBC(%d);", n & 3); write(fd, buf, strlen(buf)); for (i = 0; i < Y_SIZE; i += FONTSIZE) { tmp[0] = ((n % 100) / 10) + '0'; tmp[1] = (n % 10) + '0'; sprintf(buf, "DCV%d(0,%d,'%s',15);", FONTSIZE, i, tmp); write(fd, buf, strlen(buf)); } sprintf(buf, CRLF); 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; if (argc < 2) { printf("%s [device]\n", argv[0]); goto fin0; } fd = open(argv[1], O_RDWR | O_NOCTTY); if (fd < 0) { printf("device open error\n"); goto fin0; } if (setup_serial(fd) < 0) { printf("serial parameter error\n"); goto fin1; } tx_test(fd); fin1: close(fd); fin0: return 0; }