home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: OtherApp / OtherApp.zip / wincam.zip / winc_src.zip / private.h < prev    next >
C/C++ Source or Header  |  1997-02-28  |  7KB  |  215 lines

  1. /*
  2.  *
  3.  * Misc stuff for the wincam lib internals.  Clients of the library
  4.  *  should not need to include this.
  5.  *
  6.  * Copyright (C) 1996, Paul G. Fox
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify it
  9.  * under the terms of the GNU General Public License as published by the
  10.  * Free Software Foundation; either version 2 of the License, or (at your
  11.  * option) any later version.
  12.  * 
  13.  * This program is distributed in the hope that it will be useful, but
  14.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * General Public License for more details.
  17.  * 
  18.  * You should have received a copy of the GNU General Public License along
  19.  * with this program; if not, write to the Free Software Foundation, Inc.,
  20.  * 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  * This software was created with the help of proprietary information
  23.  * belonging to StarDot Technologies.
  24.  *
  25.  * $Header: E:/winc/RCS/private.h 1.1 1997/03/01 03:44:14 Derek Exp Derek $
  26.  */
  27.  
  28. #define INCL_DOSFILEMGR
  29. #define INCL_DOSDEVIOCTL
  30. #define INCL_DOSDEVICES
  31.  
  32. #include <os2.h>
  33.  
  34. #include "wincam.h"
  35. #include <unistd.h>
  36. #include <termios.h>
  37. #include <fcntl.h>
  38.  
  39. #define CAMERA_TTY "/dev/ttyCamera"
  40.  
  41. /*
  42.  * it's tempting to move these lines to a separate header, so we don't need
  43.  * to rebuild everything when we bump the version, but that's probably good
  44.  * practice in any case...
  45.  */
  46. #define VERSION     "winc library version 36"
  47. #define DATE        "(released October 16, 1996)"
  48. #define COPYRIGHT   "Copyright 1996 by Paul G. Fox" \
  49.             "\nsome portions (c) Copyright 1996 StarDot Technologies"
  50.  
  51. /*
  52.  * i use this typedef for unsigned char, since it's not usually
  53.  * in system header files, and because "unsigned char" is too much
  54.  * to type.  :-)
  55.  */
  56. typedef unsigned char byte;
  57.  
  58. /*
  59.  * camera firmware version information
  60.  */
  61. struct camera_ver_s {
  62.     byte major;
  63.     byte minor;
  64.     byte chiptype;
  65. };
  66. typedef struct camera_ver_s camera_ver_t;
  67.  
  68. /* we store the camera id as bytes because a) it's more portable,
  69.  * and b) it's really a glom of date information anyway -- see code in
  70.  * winc_find() to interpret it.
  71.  */
  72. struct camera_id_s {
  73.     byte id[4];
  74. };
  75. typedef struct camera_id_s camera_id_t;
  76.  
  77. /*
  78.  * this is everything we store concerning a single camera.  this could
  79.  * be augmented with "last useful exposure", "last zoom factor", or that
  80.  * sort of thing.
  81.  */
  82. struct camera_s {
  83.     char *ttyname;        /* the name of the device, e.g. "/dev/ttyS1" */
  84.     HFILE ifd;            /* the opened file for that device (for input) */
  85.     HFILE ofd;            /* the opened file for that device (for output) */
  86.     struct termios termios; /* the terminal properties for the open device */
  87.     int baud_index;        /* the current baud rate */
  88.     camera_id_t id;        /* the id bytes returned by the camera */
  89.     camera_ver_t version;   /* the version info returned by the camera */
  90.     char *lockfile;        /* the name of the lockfile */
  91.     int lockfd;            /* the descriptor for the above lock file */
  92.     int havelock;        /* do we hold the lock? */
  93. /*    struct flock flock;        for doing camera locking */
  94.     byte *starfield;        /* bitmap for starfield elimination */
  95. }; 
  96.  
  97. /*
  98.  * WinCam.One command definitions 
  99.  *
  100.  * the commands are one-byte commands.    note that all valid commands
  101.  * end in binary 01, which is how the camera autodetects baud rate.
  102.  * some commands are followed by parameters.
  103.  *
  104.  * the fundamental acknowledgement response is one byte of 0x21.  this
  105.  * may be followed by a lot of data in some cases, none in others.
  106.  */
  107.  
  108. #define Resp_Ack        0x21    /* '!' */
  109.  
  110. typedef enum {
  111. /* is it there, and what sort of camera is it? (find.c) */
  112.     Cmd_nop        = 0x1,
  113. /* multi-camera operations */
  114.     Cmd_disable_all    = 0x3d,
  115.     Cmd_enable_camera    = 0x45,
  116. /* probe/status */
  117.     Cmd_at_command    = 0x41,
  118.     Cmd_send_version    = 0x5,
  119.     Cmd_send_id     = 0x35,
  120. /* set some camera parameters */
  121.     Cmd_extra_stop    = 0x25,
  122.     Cmd_set_light    = 0x31,
  123.     Cmd_sync_mode    = 0x39,
  124.  
  125.  
  126. /* is it working properly? (diag.c) */
  127.     Cmd_tx_test     = 0x9,
  128.     Cmd_rx_test     = 0x4d,
  129.     Cmd_test_dram    = 0x0d,
  130.     Cmd_send_black    = 0x1d, /* (used for manual camera calibration) */
  131.  
  132. /* snap a "viewfinder" image, and get it (viewfinder.c) */
  133.     Cmd_snap_view    = 0x21,
  134.     Cmd_download_view    = 0x29,
  135.  
  136. /* snap various image styles, and get image data (images.c) */
  137. /* snap: */
  138.     Cmd_snap_single    = 0x2d,
  139.     Cmd_snap_interlaced = 0x11,
  140.     Cmd_snap_non    = 0x19,
  141. /* get: */
  142.     Cmd_send_image    = 0x49,
  143.     Cmd_send_row    = 0x15,
  144.  
  145.  
  146. } Cmd_byte_t;
  147.  
  148.  
  149. /*
  150.  * protocol level routines: protocol.c
  151.  */
  152. result    winc_send_cmd(cam_t cam, Cmd_byte_t cmd, ...);
  153. result    winc_get_resp(cam_t cam, int nbytes, byte *bp, unsigned long *sump);
  154. result    winc_get_resp_wait(cam_t cam, int nbytes, byte *bp,
  155.             int millisec, unsigned long *sump);
  156. result    winc_reset( cam_t cam );
  157. result    winc_flush(cam_t cam);
  158.  
  159. /*
  160.  * serial-port level routines:  comms.c
  161.  */
  162. result    comms_initialize_port( cam_t cam );
  163. void    comms_close_port( cam_t cam );
  164.  
  165. int    comms_first_baud(void);
  166. int    comms_next_baud(int bindex);
  167. int    comms_index2rate(int bindex);
  168. result    comms_set_baud(cam_t cam, int bindex);
  169.  
  170. result    comms_send_break( cam_t cam, int millisec );
  171.  
  172. int    comms_timed_read( cam_t cam, char *buf, int len, int millisec);
  173. int    comms_write(cam_t cam, char *buf, int n);
  174.  
  175.  
  176.  
  177. /*
  178.  * configuration helpers: config.c and mergeenv.c
  179.  */
  180. int    cfg_number(char *s);
  181. int    cfg_boolean(char *s);
  182.  
  183. /*
  184.  * return "repeats" parameters, given image fraction: image.c
  185.  */
  186. result get_repeats(int fraction, 
  187.     int *startp, int *sendp, int *skipp, int *repeatp,
  188.     int *colsp, int *rowsp);
  189.  
  190.  
  191. /*
  192.  * initialize the winc_lock/winc_unlock module: locks.c
  193.  */
  194. void winc_locks_init( cam_t cam );
  195.  
  196. /*
  197.  * check for presence of modem on port, vs. camera.  OK --> modem.
  198.  */
  199. result winc_check_for_modem( cam_t cam );
  200.  
  201. /*
  202.  * fix up raw data to the camera by averaging out "bad" CCD pixels.  (very
  203.  * low light levels show some CCD bits as bad) these are "starfield"
  204.  * routines because a dark image appears like a starry sky due to the bad
  205.  * white pixels.
  206.  */
  207. void winc_starfield_fix(byte *line, byte *starf_line, int len);
  208.  
  209. /*
  210.  * fetch a line from the starfield reference image.  we return the same
  211.  * pixels the camera does for any given request.
  212.  */
  213. result winc_starfield_line(byte *oline, cam_t cam, int row, int start, int
  214.     send, int skip, int repeat);
  215.