// code by SASANO Takayoshi, CC BY-SA #include #include #include #include #include #include #include #define BUFSIZE 256 #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 static void tx_test(int fd, int fontsize, int xsize, int ysize) { unsigned int i; uint8_t buf[BUFSIZE], str[BUFSIZE]; static char num[] = "1234567890"; printf("* testing %d x %d, fontsize %d\n", xsize, ysize, fontsize); for (i = 0; i < xsize / (fontsize / 2); i++) str[i] = num[i % 10]; str[i] = '\0'; sprintf(buf, "RESET;" CRLF); write(fd, buf, strlen(buf)); usleep(250000); sprintf(buf, "CLR(0);DIR(%d);SBC(0);" CRLF, xsize > ysize); write(fd, buf, strlen(buf)); usleep(250000); for (i = 0; i < ysize / fontsize; i++) { str[0] = num[i % 10]; sprintf(buf, "DCV%d(%d,%d,'%s',%d)" CRLF, fontsize, 0, fontsize * i, str, 15); write(fd, buf, strlen(buf)); usleep(DELAY); } printf("hit enter to continue...\n"); getchar(); } 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 | O_NDELAY); 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, 16, X_SIZE, Y_SIZE); tx_test(fd, 24, X_SIZE, Y_SIZE); tx_test(fd, 32, X_SIZE, Y_SIZE); tx_test(fd, 16, Y_SIZE, X_SIZE); tx_test(fd, 24, Y_SIZE, X_SIZE); tx_test(fd, 32, Y_SIZE, X_SIZE); fin1: close(fd); fin0: return 0; }