summaryrefslogtreecommitdiffstats
path: root/usr.sbin/qcamcontrol
diff options
context:
space:
mode:
authorpst <pst@FreeBSD.org>1996-02-04 09:33:52 +0000
committerpst <pst@FreeBSD.org>1996-02-04 09:33:52 +0000
commit9ee94e26ab491a43c2438708d4afc3b46dcd53e1 (patch)
tree8729a7a02cd4acaa8294f3ac54ca15a83a28aada /usr.sbin/qcamcontrol
downloadFreeBSD-src-9ee94e26ab491a43c2438708d4afc3b46dcd53e1.zip
FreeBSD-src-9ee94e26ab491a43c2438708d4afc3b46dcd53e1.tar.gz
Import very basic demo/control program for qcam driver.
Manual to follow real-soon-now(tm).
Diffstat (limited to 'usr.sbin/qcamcontrol')
-rw-r--r--usr.sbin/qcamcontrol/Makefile6
-rw-r--r--usr.sbin/qcamcontrol/qcamcontrol.c184
2 files changed, 190 insertions, 0 deletions
diff --git a/usr.sbin/qcamcontrol/Makefile b/usr.sbin/qcamcontrol/Makefile
new file mode 100644
index 0000000..f4fcc96
--- /dev/null
+++ b/usr.sbin/qcamcontrol/Makefile
@@ -0,0 +1,6 @@
+PROG= qcamcontrol
+
+# soon... very soon... I promise (pst 3-Feb-1996)
+NOMAN=
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/qcamcontrol/qcamcontrol.c b/usr.sbin/qcamcontrol/qcamcontrol.c
new file mode 100644
index 0000000..263d336
--- /dev/null
+++ b/usr.sbin/qcamcontrol/qcamcontrol.c
@@ -0,0 +1,184 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/fcntl.h>
+#include <sys/ioctl.h>
+#include <machine/qcam.h>
+
+void print_data(struct qcam *data)
+{
+ fprintf(stderr, "version=%d, (%d,%d) at (%d,%d) @%dbpp,"
+ "zoom=%d, b/w/c=%d/%d/%d\n",
+ data->qc_version,
+ data->qc_xsize, data->qc_ysize,
+ data->qc_xorigin, data->qc_yorigin,
+ data->qc_bpp,
+ data->qc_zoom,
+ data->qc_brightness,
+ data->qc_whitebalance,
+ data->qc_contrast);
+}
+
+main(int argc, char **argv)
+{
+ struct qcam info;
+ int fd, len;
+ size_t bytes;
+ char opt;
+
+ static char buffer[QC_MAX_XSIZE*QC_MAX_YSIZE];
+
+ char *port = "/dev/qcam0";
+ int x_size, y_size, zoom, depth, brightness, whitebalance, contrast;
+
+ /*
+ * Default everything to unset.
+ */
+ x_size = y_size = zoom = depth = brightness = whitebalance =
+ contrast = -1;
+
+ while ((opt = getopt(argc, argv, "p:x:y:z:d:b;w:c:")) != EOF) {
+ switch (opt) {
+ case 'p':
+ port = optarg;
+ break;
+
+ case 'x':
+ x_size = atoi(optarg);
+ if (x_size > QC_MAX_XSIZE) {
+ fprintf(stderr, "x size too large (max %d)\n",
+ QC_MAX_XSIZE);
+ exit(2);
+ }
+ break;
+
+ case 'y':
+ y_size = atoi(optarg);
+ if (y_size > QC_MAX_YSIZE) {
+ fprintf(stderr, "x size too large (max %d)\n",
+ QC_MAX_YSIZE);
+ exit(2);
+ }
+ break;
+
+ case 'z':
+ zoom = atoi(optarg);
+ if (zoom > QC_ZOOM_200) {
+ fprintf(stderr, "zoom too large (max %d)\n", QC_ZOOM_200);
+ exit(2);
+ }
+ break;
+
+ case 'd':
+ depth = atoi(optarg);
+ if (depth != 4 && depth != 6) {
+ fprintf(stderr, "invalid depth (4 or 6)\n");
+ exit(2);
+ }
+ break;
+
+ case 'b':
+ brightness = atoi(optarg);
+ if (brightness > 255) {
+ fprintf(stderr, "bad brightness (max 255)\n");
+ exit(2);
+ }
+ break;
+
+ case 'w':
+ whitebalance = atoi(optarg);
+ if (whitebalance > 255) {
+ fprintf(stderr, "bad white balance (max 255)\n");
+ exit(2);
+ }
+ break;
+
+ case 'c':
+ contrast = atoi(optarg);
+ if (contrast > 255) {
+ fprintf(stderr, "bad contrast (max 255)\n");
+ exit(2);
+ }
+ break;
+ }
+ argc--;
+ argv++;
+ }
+
+ /* open device */
+ if ((fd = open(port, O_RDONLY)) < 0) {
+ perror("open");
+ exit(1);
+ }
+
+
+
+ if (ioctl(fd, QC_GET, &info) < 0) { /* read in default info */
+ perror("ioctl(QC_GET)");
+ exit(1);
+ }
+
+ if (x_size > -1)
+ info.qc_xsize = x_size;
+ if (y_size > -1)
+ info.qc_ysize = y_size;
+ if (depth > -1)
+ info.qc_bpp = depth;
+ if (zoom > -1)
+ info.qc_zoom = zoom;
+ if (brightness > -1)
+ info.qc_brightness = brightness;
+ if (whitebalance > -1)
+ info.qc_whitebalance = whitebalance;
+ if (contrast > -1)
+ info.qc_contrast = contrast;
+
+ /*
+ * make sure we're in sync with the kernel version of the driver
+ * ioctl structure
+ */
+ info.qc_version = QC_IOCTL_VERSION;
+
+ if (ioctl(fd, QC_SET, &info) < 0) {
+ perror("ioctl(QC_SET)");
+ exit(1);
+ }
+
+ /*
+ * Tell us what the kernel thinks we're asking for
+ */
+ if (ioctl(fd, QC_GET, &info) < 0) {
+ perror("ioctl(QC_SET)");
+ exit(1);
+ }
+
+ print_data(&info);
+
+ /*
+ * Grab a frame -- a single read will always work, but give a
+ * particularly paranoid example.
+ */
+ len = info.qc_xsize * info.qc_ysize;
+ while (len) {
+ bytes = read(fd, buffer, len);
+ if (bytes < 0) {
+ perror("read");
+ exit(1);
+ }
+ len -= bytes;
+
+ if (bytes == 0)
+ exit(0);
+ }
+
+ /*
+ * Write the frame to stdout as a PGM image.
+ */
+ fprintf(stdout, "P5\n%d %d\n%d\n",
+ info.qc_xsize, info.qc_ysize, (1<<info.qc_bpp) - 1);
+ fflush(stdout);
+
+ if (write(1, buffer, info.qc_xsize * info.qc_ysize) < 0) {
+ perror("write");
+ exit(1);
+ }
+}
OpenPOWER on IntegriCloud