diff --git a/src/dt.c b/src/dt.c index ddec4f7f9..b3f9e22d0 100644 --- a/src/dt.c +++ b/src/dt.c @@ -30,161 +30,167 @@ int main(int argc, char **argv) { - int x, b, f; - int fd; - char s[1024]; - time_t t; - struct tm *tmp; - unsigned int timer; + int x, b, f; + int fd; + char s[1024]; + time_t t; + struct tm *tmp; + unsigned int timer; - if (argc > 1) - { - fd = open("/dev/display", O_RDONLY); - if (fd < 0) + if (argc > 1) { - perror("/dev/display"); - return -fd; + fd = open("/dev/display", O_RDONLY); + if (fd < 0) + { + perror("/dev/display"); + return -fd; + } + + memset(s, 0, 1024); + + for (x = 1; x < argc; x++) + { + if (argv[x][0] == '-') + { + if (sscanf(argv[x], "-b%d", &b) == 1) + { + if ((b < 16) && (b >= 0)) + { + if (ioctl(fd, IOC_FP_SET_BRIGHT, (unsigned char) b)) + perror("IOC_FP_SET_BRIGHT"); + } + else + printf("Error: brightness is out of range (0 ... 16)\n\n"); + } + else if (sscanf(argv[x], "-s%X:%X:%X", &b, &f, &timer) == 3) + { + if ((b < 16) && (b >= 0)) + { + fp_standby_data_t standby; + char h[3], m[3]; + + t = time(NULL); + tmp = localtime(&t); + if (tmp == NULL) + { + perror("localtime"); + } + if (strftime(h, sizeof(h), "%_H", tmp) == 0) + { + fprintf(stderr, "strftime returned 0\n"); + } + if (strftime(m, sizeof(m), "%_M", tmp) == 0) + { + fprintf(stderr, "strftime returned 0\n"); + } + + standby.brightness = b; + standby.flags = f & 0xFF; + standby.current_hour = atoi(h); + standby.current_minute = atoi(m); + standby.timer_minutes_hi = timer >> 8; + standby.timer_minutes_lo = timer & 0xFF; + printf("brightness %d\n", standby.brightness); + printf("flags %02X\n", standby.flags); + printf("current_hour %d\n", standby.current_hour); + printf("current_minute %d\n", standby.current_minute); + printf("timer_minutes_hi %d\n", standby.timer_minutes_hi); + printf("timer_minutes_lo %d\n", standby.timer_minutes_lo); + + if (ioctl(fd, IOC_FP_STANDBY, (fp_standby_data_t *) &standby)) + perror("IOC_FP_STANDBY"); + } + else + printf("Error: brightness is out of range (0 ... 16)\n\n"); + } + else if (sscanf(argv[x], "-is%X", &b) == 1) + { + if (ioctl(fd, IOC_FP_SET_ICON, (unsigned int) b)) + perror("IOC_FP_SET_ICON"); + } + else if (sscanf(argv[x], "-ic%X", &b) == 1) + { + if (ioctl(fd, IOC_FP_CLEAR_ICON, (unsigned int) b)) + perror("IOC_FP_CLEAR_ICON"); + } + + else if (sscanf(argv[x], "-ps%X", &b) == 1) + { + if (ioctl(fd, IOC_FP_SET_OUTPUT, (unsigned char) b)) + perror("IOC_FP_SET_OUTPUT"); + } + else if (sscanf(argv[x], "-pc%X", &b) == 1) + { + if (ioctl(fd, IOC_FP_CLEAR_OUTPUT, (unsigned char) b)) + perror("IOC_FP_CLEAR_OUTPUT"); + } + + else if (sscanf(argv[x], "-t%[^\n]", s) == 1) + { + if (ioctl(fd, IOC_FP_SET_TEXT, s)) + perror("IOC_FP_SET_TEXT"); + } + else if (sscanf(argv[x], "-ls%X", &b) == 1) + { + if ((b > 0) && (b <= 8)) + { + if (ioctl(fd, IOC_FP_LED_CTRL, b | 0x80)) + perror("IOC_FP_LED_CTRL"); + } + } + else if (sscanf(argv[x], "-lc%X", &b) == 1) + { + if ((b > 0) && (b <= 8)) + { + if (ioctl(fd, IOC_FP_LED_CTRL, b)) + perror("IOC_FP_LED_CTRL"); + } + } + else if (sscanf(argv[x], "-st%X", &b) == 1) + { + fp_standby_cmd_data_t pwr; + pwr.addr = 0; + pwr.cmd = b; + printf("standby command: %x\n", pwr.cmd); + fflush(stdout); + + if (ioctl(fd, IOC_FP_STANDBY_CMD, &pwr)) + perror("IOC_FP_STANDBY_CMD"); + } + + else if (argv[x][1] == 'c') + { + if (strlen(argv[x]) == 2) + { + if (ioctl(fd, IOC_FP_CLEAR_ALL, NULL)) + perror("IOC_FP_CLEAR_ALL"); + } + else + { + if (ioctl(fd, IOC_FP_SET_TEXT, NULL)) + perror("IOC_FP_SET_TEXT"); + } + } + } + } + close(fd); } - - memset(s, 0, 1024); - - for (x = 1; x < argc; x++) + else { - if (argv[x][0] == '-') - { - if (sscanf(argv[x], "-b%d", &b) == 1) - { - if ((b < 16) && (b >= 0)) - { - if (ioctl(fd, IOC_FP_SET_BRIGHT, (unsigned char) b)) - perror("IOC_FP_SET_BRIGHT"); - } - else - printf("Error: brightness is out of range (0 ... 16)\n\n"); - } - else if (sscanf(argv[x], "-s%X:%X:%X", &b, &f, &timer) == 3) - { - if ((b < 16) && (b >= 0)) - { - fp_standby_data_t standby; - char h[3], m[3]; - - t = time(NULL); - tmp = localtime(&t); - if (tmp == NULL) { - perror("localtime"); - } - if (strftime(h, sizeof(h), "%_H", tmp) == 0) { - fprintf(stderr, "strftime returned 0\n"); - } - if (strftime(m, sizeof(m), "%_M", tmp) == 0) { - fprintf(stderr, "strftime returned 0\n"); - } - - standby.brightness = b; - standby.flags = f & 0xFF; - standby.current_hour = atoi(h); - standby.current_minute = atoi(m); - standby.timer_minutes_hi = timer >> 8; - standby.timer_minutes_lo = timer & 0xFF; - printf("brightness %d\n", standby.brightness); - printf("flags %02X\n", standby.flags); - printf("current_hour %d\n", standby.current_hour); - printf("current_minute %d\n", standby.current_minute); - printf("timer_minutes_hi %d\n", standby.timer_minutes_hi); - printf("timer_minutes_lo %d\n", standby.timer_minutes_lo); - - if (ioctl(fd, IOC_FP_STANDBY, (fp_standby_data_t *) &standby)) - perror("IOC_FP_STANDBY"); - } - else - printf("Error: brightness is out of range (0 ... 16)\n\n"); - } - else if (sscanf(argv[x], "-is%X", &b) == 1) - { - if (ioctl(fd, IOC_FP_SET_ICON, (unsigned int) b)) - perror("IOC_FP_SET_ICON"); - } - else if (sscanf(argv[x], "-ic%X", &b) == 1) - { - if (ioctl(fd, IOC_FP_CLEAR_ICON, (unsigned int) b)) - perror("IOC_FP_CLEAR_ICON"); - } - - else if (sscanf(argv[x], "-ps%X", &b) == 1) - { - if (ioctl(fd, IOC_FP_SET_OUTPUT, (unsigned char) b)) - perror("IOC_FP_SET_OUTPUT"); - } - else if (sscanf(argv[x], "-pc%X", &b) == 1) - { - if (ioctl(fd, IOC_FP_CLEAR_OUTPUT, (unsigned char) b)) - perror("IOC_FP_CLEAR_OUTPUT"); - } - - else if (sscanf(argv[x], "-t%[^\n]", s) == 1) - { - if (ioctl(fd, IOC_FP_SET_TEXT, s)) - perror("IOC_FP_SET_TEXT"); - } - else if (sscanf(argv[x], "-ls%X", &b) == 1) - { - if ((b > 0) && (b <= 8)) { - if (ioctl(fd, IOC_FP_LED_CTRL, b | 0x80)) - perror("IOC_FP_LED_CTRL"); - } - } - else if (sscanf(argv[x], "-lc%X", &b) == 1) - { - if ((b > 0) && (b <= 8)) { - if (ioctl(fd, IOC_FP_LED_CTRL, b)) - perror("IOC_FP_LED_CTRL"); - } - } - else if (sscanf(argv[x], "-st%X", &b) == 1) - { - fp_standby_cmd_data_t pwr; - pwr.addr = 0; - pwr.cmd = b; - printf("standby command: %x\n", pwr.cmd);fflush(stdout); - - if (ioctl(fd, IOC_FP_STANDBY_CMD, &pwr)) - perror("IOC_FP_STANDBY_CMD"); - } - - else if (argv[x][1] == 'c') - { - if (strlen(argv[x]) == 2) - { - if (ioctl(fd, IOC_FP_CLEAR_ALL, NULL)) - perror("IOC_FP_CLEAR_ALL"); - } - else - { - if (ioctl(fd, IOC_FP_SET_TEXT, NULL)) - perror("IOC_FP_SET_TEXT"); - } - } - } + printf("%s\n", argv[0]); + printf("dt - displaytest usage:\n" + " -b set display brightness between 0 and 15\n" + " -t write a UTF-8 text to the display\n" + " -c clear entire display\n" + " -ct clear text on the display\n" + " -is set icon\n" + " -ic clear icon\n" + " -ps set port\n" + " -pc clear port\n" + " -ls led n on\n" + " -lc led n off\n" + " -s:: sets the box into standby (brightness, flags, timer)\n" + "\n"); } - close(fd); - } - else - { - printf("%s\n", argv[0]); - printf("dt - displaytest usage:\n" - " -b set display brightness between 0 and 15\n" - " -t write a UTF-8 text to the display\n" - " -c clear entire display\n" - " -ct clear text on the display\n" - " -is set icon\n" - " -ic clear icon\n" - " -ps set port\n" - " -pc clear port\n" - " -ls led n on\n" - " -lc led n off\n" - " -s:: sets the box into standby (brightness, flags, timer)\n" - "\n"); - } - return 0; + return 0; }