/* * G O O D S T A T U S * * Checks the status of the Dunn camera and returns 1 for good status * and 0 for bad status. * */ int goodstatus(void) { ssize_t ret; struct timeval waittime, *timeout; int readval; timeout = &waittime; timeout->tv_sec = 10; timeout->tv_usec = 0; cmd = ';'; /* status request cmd */ ret = write(fd, &cmd, 1); if (ret < 0) perror("write"); FD_ZERO(&readfds); FD_SET(fd, &readfds); select(fd+1, &readfds, (fd_set *)0, (fd_set *)0, timeout); if (FD_ISSET(fd, &readfds) ==0) { printf("\007dunnsnap: status request timed out\n"); return 0; } readval = bu_mread(fd, status, 4); if (readval < 0) { perror("READ ERROR"); } alarm(0); if (status[0]&0x1) printf("No vertical sync\n"); if (status[0]&0x2) printf("8x10 not ready\n"); if (status[0]&0x4) printf("Expose in wrong mode\n"); if (status[0]&0x8) printf("Aux camera out of film\n"); if (status[1]&0x1) printf("B/W mode\n"); if (status[1]&0x2) printf("Separate mode\n"); if (status[2]&0x1) printf("Y-smoothing off\n"); if ((status[0]&0xf) == 0x0 && (status[1]&0x3) == 0x0 && (status[3]&0x7f)== '\r') return 1; /* status is ok */ printf("\007dunnsnap: status error from camera\n"); printf("status[0]= 0x%x [1]= 0x%x [2]= 0x%x [3]= 0x%x\n", status[0]&0x7f, status[1]&0x7f, status[2]&0x7f, status[3]&0x7f); return 0; /* status is bad or request timed out */ }
int main(int argc, char *argv[]) { FILE *fp; register int count; register int tfd; if ( (count = bu_mread(0, buf, sizeof(buf))) < sizeof(buf) ) { if ( count < 0 ) { perror("buffer: mem read"); exit(1); } /* Entire input sequence fit into buf */ if ( write(1, buf, count) != count ) { perror("buffer: stdout write 1"); exit(1); } exit(0); } /* Create temporary file to hold data, get r/w file descriptor */ fp = bu_temp_file(template, 512);
/* * G E T E X P O S U R E * * Get and print the current exposure */ void getexposure(char *title) { struct timeval waittime; int readval; ssize_t ret; waittime.tv_sec = 20; waittime.tv_usec = 0; if (!ready(20)) { bu_exit(60, "dunncolor: (getexposure) camera not ready\n"); } if (polaroid) cmd = '<'; /* req 8x10 exposure values */ else cmd = '='; /* request AUX exposure values */ ret = write(fd, &cmd, 1); if (ret < 0) perror("write"); FD_ZERO(&readfds); FD_SET(fd, &readfds); select(fd+1, &readfds, (fd_set *)0, (fd_set *)0, &waittime); if (FD_ISSET(fd, &readfds)) { bu_exit(40, "dunncolor:\007 %s request exposure value cmd: timed out\n", title); } readval = bu_mread(fd, values, 20); if (readval < 0) { perror("READ ERROR"); } values[20] = '\0'; printf("dunncolor: %s = %s\n", title, values); }
int main(int argc, char *argv[]) { char _template[512] = {0}; char buf[SIZE] = {0}; FILE *fp = NULL; long count = 0; int tfd = 0; int ret = 0; if ((BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?")) && argc == 2) { bu_log("Usage: %s (takes no arguments)\n",argv[0]); exit(1); } if (argc > 1) { bu_log("%s: unrecognized argument(s)\n", argv[0]); bu_log(" Program continues running:\n", argv[0]); } if ((count = bu_mread(0, buf, sizeof(buf))) < (long)sizeof(buf)) { if (count < 0) { perror("buffer: mem read"); exit(1); } /* Entire input sequence fit into buf */ if (write(1, buf, count) != count) { perror("buffer: stdout write 1"); exit(1); } exit(0); } /* Create temporary file to hold data, get r/w file descriptor */ fp = bu_temp_file(_template, 512); if (fp == NULL || (tfd = fileno(fp)) < 0) { perror(_template); goto err; } /* Stash away first buffer full */ if (write(tfd, buf, count) != count) { perror("buffer: tmp write1"); goto err; } /* Continue reading and writing additional buffer loads to temp file */ while ((count = bu_mread(0, buf, sizeof(buf))) > 0) { if (write(tfd, buf, count) != count) { perror("buffer: tmp write2"); goto err; } } if (count < 0) { perror("buffer: read"); goto err; } /* All input read, regurgitate it all on stdout */ if (lseek(tfd, 0, 0) < 0) { perror("buffer: lseek"); goto err; } while ((count = bu_mread(tfd, buf, sizeof(buf))) > 0) { if (write(1, buf, count) != count) { perror("buffer: stdout write 2"); goto err; } } if (count < 0) { perror("buffer: tmp read"); goto err; } ret = 0; goto clean; err: ret = 1; clean: /* clean up */ if (fp) { fclose(fp); fp = NULL; } bu_file_delete(_template); return ret; }
int main(int argc, char **argv) { int y; FBIO *fbp; int xout, yout, n, m, xstart, xskip; if (!get_args(argc, argv)) { (void)fputs(usage, stderr); bu_exit(1, NULL); } /* autosize input? */ if (fileinput && autosize) { size_t w, h; if (fb_common_file_size(&w, &h, file_name, 3)) { file_width = w; file_height = h; } else { fprintf(stderr, "pix-fb: unable to autosize\n"); } } /* If screen size was not set, track the file size */ if (scr_width == 0) scr_width = file_width; if (scr_height == 0) scr_height = file_height; if ((fbp = fb_open(framebuffer, scr_width, scr_height)) == NULL) { bu_exit(12, NULL); } /* Get the screen size we were given */ scr_width = fb_getwidth(fbp); scr_height = fb_getheight(fbp); /* compute number of pixels to be output to screen */ if (scr_xoff < 0) { xout = scr_width + scr_xoff; xskip = (-scr_xoff); xstart = 0; } else { xout = scr_width - scr_xoff; xskip = 0; xstart = scr_xoff; } if (xout < 0) bu_exit(0, NULL); /* off screen */ if ((size_t)xout > (file_width-file_xoff)) xout = (file_width-file_xoff); scanpix = xout; /* # pixels on scanline */ if (inverse) scr_yoff = (-scr_yoff); yout = scr_height - scr_yoff; if (yout < 0) bu_exit(0, NULL); /* off screen */ if ((size_t)yout > (file_height-file_yoff)) yout = (file_height-file_yoff); /* Only in the simplest case use multi-line writes */ if (!one_line_only && multiple_lines > 0 && !inverse && !zoom && (size_t)xout == file_width && file_width <= (size_t)scr_width) { scanpix *= multiple_lines; } scanbytes = scanpix * sizeof(RGBpixel); if ((scanline = (unsigned char *)malloc(scanbytes)) == RGBPIXEL_NULL) { fprintf(stderr, "pix-fb: malloc(%d) failure for scanline buffer\n", scanbytes); bu_exit(2, NULL); } if (clear) { fb_clear(fbp, PIXEL_NULL); } if (zoom) { /* Zoom in, and center the display. Use square zoom. */ int zoomit; zoomit = scr_width/xout; if (scr_height/yout < zoomit) zoomit = scr_height/yout; if (inverse) { fb_view(fbp, scr_xoff+xout/2, scr_height-1-(scr_yoff+yout/2), zoomit, zoomit); } else { fb_view(fbp, scr_xoff+xout/2, scr_yoff+yout/2, zoomit, zoomit); } } if (file_yoff != 0) skipbytes(infd, (off_t)file_yoff*(off_t)file_width*sizeof(RGBpixel)); if (multiple_lines) { /* Bottom to top with multi-line reads & writes */ unsigned long height; for (y = scr_yoff; y < scr_yoff + yout; y += multiple_lines) { n = bu_mread(infd, (char *)scanline, scanbytes); if (n <= 0) break; height = multiple_lines; if (n != scanbytes) { height = (n/sizeof(RGBpixel)+xout-1)/xout; if (height <= 0) break; } /* Don't over-write */ if ((size_t)(y + height) > (size_t)(scr_yoff + yout)) height = scr_yoff + yout - y; if (height <= 0) break; m = fb_writerect(fbp, scr_xoff, y, file_width, height, scanline); if ((size_t)m != file_width*height) { fprintf(stderr, "pix-fb: fb_writerect(x=%d, y=%d, w=%lu, h=%lu) failure, ret=%d, s/b=%d\n", scr_xoff, y, (unsigned long)file_width, height, m, scanbytes); } } } else if (!inverse) { /* Normal way -- bottom to top */ for (y = scr_yoff; y < scr_yoff + yout; y++) { if (y < 0 || y > scr_height) { skipbytes(infd, (off_t)file_width*sizeof(RGBpixel)); continue; } if (file_xoff+xskip != 0) skipbytes(infd, (off_t)(file_xoff+xskip)*sizeof(RGBpixel)); n = bu_mread(infd, (char *)scanline, scanbytes); if (n <= 0) break; m = fb_write(fbp, xstart, y, scanline, xout); if (m != xout) { fprintf(stderr, "pix-fb: fb_write(x=%d, y=%d, npix=%d) ret=%d, s/b=%d\n", scr_xoff, y, xout, m, xout); } /* slop at the end of the line? */ if ((size_t)file_xoff+xskip+scanpix < file_width) skipbytes(infd, (off_t)(file_width-file_xoff-xskip-scanpix)*sizeof(RGBpixel)); } } else { /* Inverse -- top to bottom */ for (y = scr_height-1-scr_yoff; y >= scr_height-scr_yoff-yout; y--) { if (y < 0 || y >= scr_height) { skipbytes(infd, (off_t)file_width*sizeof(RGBpixel)); continue; } if (file_xoff+xskip != 0) skipbytes(infd, (off_t)(file_xoff+xskip)*sizeof(RGBpixel)); n = bu_mread(infd, (char *)scanline, scanbytes); if (n <= 0) break; m = fb_write(fbp, xstart, y, scanline, xout); if (m != xout) { fprintf(stderr, "pix-fb: fb_write(x=%d, y=%d, npix=%d) ret=%d, s/b=%d\n", scr_xoff, y, xout, m, xout); } /* slop at the end of the line? */ if ((size_t)file_xoff+xskip+scanpix < file_width) skipbytes(infd, (off_t)(file_width-file_xoff-xskip-scanpix)*sizeof(RGBpixel)); } } sleep(pause_sec); if (fb_close(fbp) < 0) { fprintf(stderr, "pix-fb: Warning: fb_close() error\n"); } return 0; }