usbtmc_sendscpi (sc, ":TIM:OFFSET 0", NULL, 0);
}
-void do_get_screen(struct usb_dev_handle *sc)
+static unsigned char* get_lcd(struct usb_dev_handle *sc, int *imglen)
{
unsigned char screen[320*234];
- time_t lt;
- char filename[256];
unsigned char *png;
- int imglen;
- int ret;
int l;
- int fd;
- pid_t display;
/* Hide "RMT" from screen */
l = usbtmc_sendscpi(sc, ":KEY:LOCK DISABLE", NULL, 0);
printf ("hmm. didnt' get %d bytes, but %d\n\n", sizeof(screen), l);
}
- png = lcd2png(screen, &imglen);
+ png = lcd2png(screen, imglen);
+
+ return png;
+}
+
+void do_get_screen(struct usb_dev_handle *sc)
+{
+ time_t lt;
+ char filename[256];
+ unsigned char *png;
+ int imglen;
+ int ret;
+ int fd;
+ pid_t display;
+
+ png = get_lcd(sc, &imglen);
+ if (png == NULL) {
+ perror("get_lcd");
+ return;
+ }
lt = time(NULL);
strftime(filename, sizeof(filename), "screen_%Y%m%d-%H%M%S.png", localtime(<));
fd=open(filename, O_CREAT|O_WRONLY, 0644);
if (fd == -1) {
perror("open");
- exit(EXIT_FAILURE);
+ return;
}
while(imglen > 0) {
ret = write(fd, png, imglen);
if (ret == -1) {
perror("write");
- exit(EXIT_FAILURE);
+ return;
}
imglen -= ret;
}
}
}
+void do_display_screen(struct usb_dev_handle *sc)
+{
+ unsigned char *png;
+ int imglen;
+ int ret;
+ int pipefd[2];
+ pid_t display;
+
+ png = get_lcd(sc, &imglen);
+ if (png == NULL) {
+ perror("get_lcd");
+ return;
+ }
+
+ if (pipe(pipefd) == -1) {
+ perror("pipe");
+ return;
+ }
+
+ display = fork();
+ switch(display) {
+ case 0:
+ close(pipefd[1]);
+ close(STDIN_FILENO);
+ dup2(pipefd[0], STDIN_FILENO);
+ execlp("display", "display", "-", NULL);
+ exit(0);
+ break;
+ case -1:
+ perror("fork");
+ break;
+ default:
+ close(pipefd[0]);
+ while(imglen > 0) {
+ ret = write(pipefd[1], png, imglen);
+ if (ret == -1) {
+ perror("write");
+ exit(EXIT_FAILURE);
+ }
+ imglen -= ret;
+ }
+ close(pipefd[1]);
+ break;
+ }
+}
+
continue;
}
if (strncmp (scpi, "databuf", 7) == 0) {
- do_get_buf (sc);
+ do_get_buf(sc);
continue;
}
if (strncmp (scpi, "screen", 6) == 0) {
- do_get_screen (sc);
+ do_get_screen(sc);
+ continue;
+ }
+ if (strncmp (scpi, "display", 7) == 0) {
+ do_display_screen(sc);
continue;
}