📄 cam_control_cmd.c
字号:
/*----------------------------------------------------------------------------*\| || Copyright (C) 2003, James A. Cureington || tonycu * users_sourceforge_net || || This program is free software; you can redistribute it and/or || modify it under the terms of the GNU General Public License || as published by the Free Software Foundation; either version 2 || of the License, or any later version. || || This program is distributed in the hope that it will be useful, || but WITHOUT ANY WARRANTY; without even the implied warranty of || MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the || GNU General Public License for more details. || || You should have received a copy of the GNU General Public License || along with this program; if not, write to the Free Software || Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. || || || Tony Cureington || December 4, 2002 || || This file is associated with the ezusb2131 Linux downloader project. The || project can be found at http://ezusb2131.sourceforge.net. || || || || :set tabstop=3 || :set softtabstop=3 || :set shiftwidth=3 || :set smarttab || :mkv ~/.vimrc || || X:set expandtab || |\*----------------------------------------------------------------------------*//******************************************************************************* * * $Id: cam_control_cmd.c,v 1.1 2003/02/21 06:50:35 tonycu Exp $ * ******************************************************************************/#include <stdio.h>#include <stdlib.h>#define _GNU_SOURCE /* for getopt */#include <getopt.h>#include "cam_common.h"#include "usblinux.h"#define VERSION "1.0"#define EP1 1#define INTERFACE_NUM 0#define EP_TIMEOUT 5000 /* 5 seconds */#define DONT_MOVE 91 /* don't move servo */char *pname = (char*)0;voidusage(void){ printf("Usage: %s Options\n", pname); printf("Options: \n"); printf(" -x deg move x (horizontal) to deg position (%d to %d)\n", MAX_HORIZONTAL, MIN_HORIZONTAL); printf(" -y deg move y (vertical) to deg position (%d to %d)\n", MAX_VERTICAL, MIN_VERTICAL); printf(" -c bring camera to center position\n"); printf(" -s stop all movement\n"); printf(" -i info about position of servos\n"); printf("\n");}intparse_cmd_line(cc_command *pcmd, int argc, char *argv[]){ int opt; if (argc == 1) { usage(); return(1); } pcmd->command = 0; pcmd->new_horizontal_deg = DONT_MOVE; pcmd->new_vertical_deg = DONT_MOVE; while ((opt = getopt(argc, argv, "x:y:cshi")) != -1) { switch(opt) { case 'x': pcmd->command |= CC_COMMAND_MOVE; pcmd->new_horizontal_deg = (char)atoi(optarg); break; case 'y': pcmd->command |= CC_COMMAND_MOVE; pcmd->new_vertical_deg = (char)atoi(optarg); break; case 'c': /* center camera */ pcmd->command |= CC_COMMAND_MOVE; pcmd->new_horizontal_deg = 0; pcmd->new_vertical_deg = 0; break; case 'i': pcmd->command |= CC_COMMAND_INFO; break; case 's': pcmd->command |= CC_COMMAND_STOP; break; case 'h': case '?': usage(); return(1); /* not reached */ break; } } return(0);}intmain(int argc, char* argv[]){ int ret; struct usbdevice *dev; cc_command cam_command; cc_info cam_info; cc_command *pcommand; cc_info *pinfo; pname = argv[0]; pcommand = &cam_command; pinfo = &cam_info; printf("\nCam Control v%s\n", VERSION); printf("Copyright (c) 2003, Tony Cureington " "<tonycu * users_sourceforge_net>\n\n"); if (parse_cmd_line(pcommand, argc, argv)) { return(1); } dev = usbOpen(VENDOR_ID, PRODUCT_ID); if (dev == NULL) { printf("Cam Control device not found\n"); return(1); } if (usbClaimInterface(dev, INTERFACE_NUM) < 0) { printf("Could not claim Cam Control device\n"); usbClose(dev); return(1); } ret = usbBulkOut(dev, EP1, pcommand, sizeof(cc_command), EP_TIMEOUT); if (ret < 0) { printf("BulkOut failed, err=%d\n", ret); usbReleaseInterface(dev, INTERFACE_NUM); usbClose(dev); return(ret); } if (pcommand->command & CC_COMMAND_INFO) { ret = usbBulkIn(dev, EP1, pinfo, sizeof(cc_info), EP_TIMEOUT); if (ret < 0) { printf("BulkOut failed, err=%d\n", ret); usbReleaseInterface(dev, INTERFACE_NUM); usbClose(dev); return(ret); } printf("X_Coord = %d\n", pinfo->current_hdeg); printf("Y_Coord = %d\n", pinfo->current_vdeg); printf("X_Coord_Final = %d\n", pinfo->final_hdeg); printf("Y_Coord_Final = %d\n", pinfo->final_vdeg); } usbReleaseInterface(dev, INTERFACE_NUM); usbClose(dev); return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -