Exemple #1
0
Fichier : x11.c Projet : 7max/glc
void x11_event(Display *dpy, XEvent *event)
{
	if (!event)
		return;

	if (event->type == KeyPress) {
		if (event->xkey.time == x11.last_event_time)
			return; /* handle duplicates */
	
		if (x11_match_key(dpy, event, x11.capture_key, x11.capture_key_mask)) {
			if (lib.flags & LIB_CAPTURING) /* stop */
				stop_capture();
			else /* start */
				start_capture();
		} else if (x11_match_key(dpy, event, x11.reload_key, x11.reload_key_mask)) {
			if (lib.flags & LIB_CAPTURING) /* just stop */
				stop_capture();
			else { /* reload and start */
				increment_capture();
				reload_stream();
				start_capture();
			}
		}

		x11.last_event_time = event->xkey.time;
	}
}
Exemple #2
0
static const lua_WChar *match (MatchState *ms, const lua_WChar *s, const lua_WChar *p) {
  init: /* using goto's to optimize tail recursion */
  switch (*p) {
    case '(':  /* start capture */
      if (*(p+1) == ')')  /* position capture? */
        return start_capture(ms, s, p+2, CAP_POSITION);
      else
        return start_capture(ms, s, p+1, CAP_UNFINISHED);
    case ')':  /* end capture */
      return end_capture(ms, s, p+1);
    case ESC:  /* may be %[0-9] or %b */
      if (iswdigit(*(p+1))) {  /* capture? */
        s = match_capture(ms, s, *(p+1));
        if (s == NULL) return NULL;
        p+=2; goto init;  /* else return match(ms, s, p+2) */
      }
      else if (*(p+1) == 'b') {  /* balanced string? */
        s = matchbalance(ms, s, p+2);
        if (s == NULL) return NULL;
        p+=4; goto init;  /* else return match(ms, s, p+4); */
      }
      else goto dflt;  /* case default */
    case '\0':  /* end of pattern */
      return s;  /* match succeeded */
    case '$':
      if (*(p+1) == '\0')  /* is the `$' the last char in pattern? */
        return (s == ms->src_end) ? s : NULL;  /* check end of string */
      else goto dflt;
    default: dflt: {  /* it is a pattern item */
      const lua_WChar *ep = luaI_classend(ms, p);  /* points to what is next */
      int m = s<ms->src_end && luaI_singlematch(*s, p, ep);
      switch (*ep) {
        case '?': {  /* optional */
          const lua_WChar *res;
          if (m && ((res=match(ms, s+1, ep+1)) != NULL))
            return res;
          p=ep+1; goto init;  /* else return match(ms, s, ep+1); */
        }
        case '*':  /* 0 or more repetitions */
          return max_expand(ms, s, p, ep);
        case '+':  /* 1 or more repetitions */
          return (m ? max_expand(ms, s+1, p, ep) : NULL);
        case '-':  /* 0 or more repetitions (minimum) */
          return min_expand(ms, s, p, ep);
        default:
          if (!m) return NULL;
          s++; p=ep; goto init;  /* else return match(ms, s+1, ep); */
      }
    }
  }
}
Exemple #3
0
static void finger_det_data_cb(struct libusb_transfer *transfer)
{
	struct fp_img_dev *dev = transfer->user_data;
	struct upektc_dev *upekdev = dev->priv;
	unsigned char *data = transfer->buffer;

	if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
		fp_dbg("data transfer status %d\n", transfer->status);
		fpi_imgdev_session_error(dev, -EIO);
		goto out;
	} else if (transfer->length != transfer->actual_length) {
		fp_dbg("expected %d, got %d bytes", transfer->length,
			transfer->actual_length);
		fpi_imgdev_session_error(dev, -EPROTO);
	}

	if (finger_present(data, IMAGE_SIZE, upekdev->sum_threshold)) {
		/* finger present, start capturing */
		fpi_imgdev_report_finger_status(dev, TRUE);
		start_capture(dev);
	} else {
		/* no finger, poll for a new histogram */
		start_finger_detection(dev);
	}

out:
	g_free(data);
	libusb_free_transfer(transfer);
}
Exemple #4
0
int main(int argc, char *argv[])
{
	struct interface_list *itfc_list;
	char iface[100];

	pd = NULL;

	gui_register_exit(&exit_fun);
	gui_register_stop(&stop_fun);

	itfc_list = get_interface_list();
	gui_set_interface_list(itfc_list);

	guipid = gui_pthread_start(&argc, &argv);

	cappid = pthread_self();

	signal(SIGUSR1, idle_sig);
	while (gui_wait_capture(iface) == 0) {
		start_capture(iface);
	}

	printf("exit\n");
	pcap_freealldevs(if_list);
	return 0;
}
/*
 * camif_read()
 */
static ssize_t camif_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
{
	int i;
	struct s3c2440camif_fh * fh;
	struct s3c2440camif_dev * pdev;

	fh = file->private_data;
	pdev = fh->dev;


	if (start_capture(pdev, 0) != 0)
	{
		return -ERESTARTSYS;
	}

	disable_irq(IRQ_S3C2440_CAM_C);
	disable_irq(IRQ_S3C2440_CAM_P);
	for (i = 0; i < 4; i++)
	{
		if (img_buff[i].state != CAMIF_BUFF_INVALID)
		{
			copy_to_user(data, (void *)img_buff[i].virt_base, count);
			img_buff[i].state = CAMIF_BUFF_INVALID;
		}
	}
	enable_irq(IRQ_S3C2440_CAM_P);
	enable_irq(IRQ_S3C2440_CAM_C);


	return count;
}
Exemple #6
0
static int heartbeat(gpointer data)
{
    refresh_state_info();
    /* check watchdog */
    if (ctrl_shm->watchdog < 10) {
	ctrl_shm->watchdog++;
    } else {
	handle_watchdog_timeout();
    }
    if (ctrl_usr->pending_restart && ctrl_shm->state == IDLE) {
        ctrl_usr->pending_restart = 0;
        ctrl_usr->run_mode = ctrl_usr->old_run_mode;
        if(ctrl_usr->run_mode != STOP) {
            start_capture();
        }
    }
    if (ctrl_usr->display_refresh_timer > 0) {
	/* decrement timer, did it time out? */
	if (--ctrl_usr->display_refresh_timer == 0) {
	    /* yes, refresh the display */
	    refresh_display();
	}
    }
    if (ctrl_shm->state == DONE) {
        if(!gtk_window_is_active(GTK_WINDOW(ctrl_usr->main_win)))
            gtk_window_set_urgency_hint(GTK_WINDOW(ctrl_usr->main_win), TRUE);
	capture_complete();
    } else if (ctrl_usr->run_mode == ROLL) capture_cont();
    return 1;
}
static void et_read_poll_cb(struct libusb_transfer* transfer)
{
 int len;
 char* br;
 int r;
 
 struct poll_data* adata=transfer->user_data;
 struct fpi_img_dev* dev=adata->dev;
 if(transfer->status!=LIBUSB_TRANSFER_COMPLETED)
 {
  /*WORKAROUND NEEDED, SOMETIME ALL FREEZES, RESET DEVICE AND REACTIVATE???*/
  libusb_free_transfer(transfer);
  fp_dbg("ERROR");
  fpi_imgdev_session_error(dev,-EIO);
  //return;
  goto _st;
 }
 len=transfer->actual_length-13;
 if(len!=512)
 {
  fp_dbg("Invalid return buffer, length: %d",transfer->actual_length);
  libusb_free_transfer(transfer);
  fpi_imgdev_session_error(dev,-EPROTO);
  return;
 }
 libusb_free_transfer(transfer);
 //Check poll cmd result
 br=(char*)&ret_buf[len];
 r=et_verify_result(br);
 if(r)
 {
  fp_dbg("Invalid result: %s",print_buf(br));
  fpi_imgdev_session_error(dev,-EPROTO);
  return;
 }
 //fp_dbg("0x%02hhX,0x%02hhX",ret_buf[0],ret_buf[1]);
 if((unsigned char)ret_buf[0]==0x82)
 {
  if(adata->init->rstage<20) 
  {
  /*VERY UGLY workaround below, but I don't know how to deal with it.
  Sometime ret_buf[0] equals 0x82 at the first poll rounds, but
  really no finger on the scanner
  */ 
   fp_dbg("POLL WORKAROUND");
   goto _st;
  }
  //Finger detected
  //fp_dbg("FINGER DETECTED!");
  //fp_dbg("BUF: %s",print_buf(ret_buf));
  fpi_imgdev_report_finger_status(dev,TRUE);
  start_capture(dev);
  return;
 }
 //No finger detected
_st:
 adata->init->rstage++; 
 start_finger_detection(dev,adata);
}
Exemple #8
0
  void	connectAll() {
    CaptureHandler::connect(filters_window, SIGNAL(refresh()),
			    this, SLOT(displayPacketList()));
    CaptureHandler::connect(filters, SIGNAL(clicked()), this, SLOT(exec()));
    CaptureHandler::connect(open, SIGNAL(clicked()), this, SLOT(display_file()));
    CaptureHandler::connect(start, SIGNAL(clicked()), this, SLOT(start_capture()));
    CaptureHandler::connect(stop, SIGNAL(clicked()), this, SLOT(stop_capture()));
    CaptureHandler::connect(modify, SIGNAL(clicked()),
			    forge, SLOT(setPacketToModify()));
  }
static const char *match (lua_State *L, const char *s, const char *p,
                          struct Capture *cap) {
init: /* using goto's to optimize tail recursion */
    switch (*p) {
    case '(':  /* start capture */
        return start_capture(L, s, p, cap);
    case ')':  /* end capture */
        return end_capture(L, s, p, cap);
    case ESC:  /* may be %[0-9] or %b */
        if (isdigit((unsigned char)(*(p+1)))) {  /* capture? */
            s = match_capture(L, s, *(p+1), cap);
            if (s == NULL) return NULL;
            p+=2;
            goto init;  /* else return match(L, s, p+2, cap) */
        }
        else if (*(p+1) == 'b') {  /* balanced string? */
            s = matchbalance(L, s, p+2, cap);
            if (s == NULL) return NULL;
            p+=4;
            goto init;  /* else return match(L, s, p+4, cap); */
        }
        else goto dflt;  /* case default */
    case '\0':  /* end of pattern */
        return s;  /* match succeeded */
    case '$':
        if (*(p+1) == '\0')  /* is the '$' the last char in pattern? */
            return (s == cap->src_end) ? s : NULL;  /* check end of string */
        else goto dflt;
    default:
dflt: {  /* it is a pattern item */
            const char *ep = luaI_classend(L, p);  /* points to what is next */
            int m = s<cap->src_end && luaI_singlematch((unsigned char)*s, p, ep);
            switch (*ep) {
            case '?': {  /* optional */
                const char *res;
                if (m && ((res=match(L, s+1, ep+1, cap)) != NULL))
                    return res;
                p=ep+1;
                goto init;  /* else return match(L, s, ep+1, cap); */
            }
            case '*':  /* 0 or more repetitions */
                return max_expand(L, s, p, ep, cap);
            case '+':  /* 1 or more repetitions */
                return (m ? max_expand(L, s+1, p, ep, cap) : NULL);
            case '-':  /* 0 or more repetitions (minimum) */
                return min_expand(L, s, p, ep, cap);
            default:
                if (!m) return NULL;
                s++;
                p=ep;
                goto init;  /* else return match(L, s+1, ep, cap); */
            }
        }
    }
}
Exemple #10
0
/*
initcamdev();
initscrdev();

while(!stop){
	cnfig = getcnfg()
	data = getapic(cnfg);

	data1 = decode(data);

	show(data1,pos)
}

closedev();
*/ 
int main()
{
    int fd;
    fd = open_camera_device();
    init_camera_device(fd);
    start_capture(fd);
    mainloop(fd);
    stop_capture(fd);
    close_camera_device(fd);
    return 0;
}
Exemple #11
0
static void rm_roll_button_clicked(GtkWidget * widget, gpointer * gdata)
{
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)) != TRUE) {
	/* not pressed, ignore it */
	return;
    }
    ctrl_usr->run_mode = ROLL;
    if (ctrl_shm->state == IDLE) {
	start_capture();
    }
}
Exemple #12
0
void BBEyesNode::toggle()
{
    if(!_active)
    {
        start_capture();
        _active = true;
        return;
    }
    stop_capture();
    _active = false;
}
void parseBinaryNetLinkMessage(struct nlmsghdr *nlh)
{
	int len = nlh->nlmsg_len - sizeof(*nlh);
	struct ifinfomsg *ifi;

	if(sizeof(*ifi) > (size_t)len){
		printf("Got a short message\n");
		return ;
	}

	ifi = (struct  ifinfomsg*)NLMSG_DATA(nlh);
	if((ifi->ifi_flags & IFF_LOOPBACK) != 0){
		return ;
	}

	struct rtattr *rta = (struct rtattr*)
		((char*)ifi + NLMSG_ALIGN(sizeof(*ifi)));
	len = NLMSG_PAYLOAD(nlh,sizeof(*ifi));

	while(RTA_OK(rta,len)){
		switch(rta->rta_type){
			case IFLA_IFNAME:
			{
				char ifname[IFNAMSIZ];
				int  up;
				int id;
				snprintf(ifname,sizeof(ifname),"%s",
					(char*)RTA_DATA(rta));
				up = (ifi->ifi_flags & IFF_RUNNING)? 1 : 0;
				if (up && ((ifname[0] == 'p')&&(ifname[1] == 'p')&&
					(ifname[2] == 'p'))){
					printf("msg from:%s",ifname);
					sscanf(ifname+3,"%d",&id);
					if(nic_bitmap[id])
						break;
					start_capture(ifname);
					nic_bitmap[id] = 1;	
					printf("%s  %d\n",ifname,up);
				} 
				if (!up && ((ifname[0] == 'p')&&(ifname[1] == 'p')&&
                                        (ifname[2] == 'p'))){
					sscanf(ifname+3,"%d",(int*)&id);
					nic_bitmap[id] = 0;
					printf("%s %d\n",ifname,up);
				}
			}
		}

		rta = RTA_NEXT(rta,len);
	}

}
Exemple #14
0
static void omap1_videobuf_queue(struct videobuf_queue *vq,
						struct videobuf_buffer *vb)
{
	struct soc_camera_device *icd = vq->priv_data;
	struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
	struct omap1_cam_dev *pcdev = ici->priv;
	struct omap1_cam_buf *buf;
	u32 mode;

	list_add_tail(&vb->queue, &pcdev->capture);
	vb->state = VIDEOBUF_QUEUED;

	if (pcdev->active) {
		/*
		 * Capture in progress, so don't touch pcdev->ready even if
		 * empty. Since the transfer of the DMA programming register set
		 * content to the DMA working register set is done automatically
		 * by the DMA hardware, this can pretty well happen while we
		 * are keeping the lock here. Leave fetching it from the queue
		 * to be done when a next DMA interrupt occures instead.
		 */
		return;
	}

	WARN_ON(pcdev->ready);

	buf = prepare_next_vb(pcdev);
	if (WARN_ON(!buf))
		return;

	pcdev->active = buf;
	pcdev->ready = NULL;

	dev_dbg(icd->dev.parent,
		"%s: capture not active, setup FIFO, start DMA\n", __func__);
	mode = CAM_READ_CACHE(pcdev, MODE) & ~THRESHOLD_MASK;
	mode |= THRESHOLD_LEVEL(pcdev->vb_mode) << THRESHOLD_SHIFT;
	CAM_WRITE(pcdev, MODE, mode | EN_FIFO_FULL | DMA);

	if (pcdev->vb_mode == OMAP1_CAM_DMA_SG) {
		/*
		 * In SG mode, the above prepare_next_vb() didn't actually
		 * put anything into the DMA programming register set,
		 * so we have to do it now, before activating DMA.
		 */
		try_next_sgbuf(pcdev->dma_ch, buf);
	}

	start_capture(pcdev);
}
Exemple #15
0
int main(void)
{
  uint8_t frames_num = 0;
  uint8_t i;
  
  
  RCC_ClocksTypeDef RCC_Clocks;
  
  /* Initialize LEDs and User_Button on STM32F4-Discovery --------------------*/
  STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI); 
  
  STM_EVAL_LEDInit(LED4);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED5);
  STM_EVAL_LEDInit(LED6);

  //init_clk();
  RCC_GetClocksFreq(&RCC_Clocks);
  
  ADC_DeInit();
  init_tim2();
  adc_init();
  init_adc3();
  
  STM_EVAL_LEDOff(LED6);
  Delay_ms(10);
    
  //while(frames_num<50)
  while(1) //endless - no image process
  {
    asm("nop");
    if (capture_enabled == 0)
    {       
        Delay_ms(10);
        start_capture();
        frames_num++;
    }
  }
  
  Delay_ms(50);
  
  for (i=0;i<lines_captured;i++)
  {
    process_line(i);
  }
  
  
  while(1){}
  
}
Exemple #16
0
/*
 * camif_open()
 */
static int camif_open(struct file *file)
{
	struct video_device *vdev = video_devdata(file);
	s3c2440camif_dev *pcam = (s3c2440camif_dev *)video_get_drvdata(vdev);
	
	int ret;

	if (!has_ov9650) {
		return -ENODEV;
	}

  file->private_data = vdev;

  pcam->state = CAMIF_STATE_READY;

	init_camif_config(pcam);
	
  
  pcam->last_frame=-1;
  
  if((ret=request_irq(IRQ_S3C2440_CAM_C, on_camif_irq_c, IRQF_DISABLED, "CAM_C", pcam))<0)	// setup ISRs
    goto error2;

  if((ret=request_irq(IRQ_S3C2440_CAM_P, on_camif_irq_p, IRQF_DISABLED, "CAM_P", pcam))<0)
    goto error3;

  clk_enable(pcam->clk);		// and enable camif clock.

  //soft_reset_camif();
	//update_camif_config(pcam, 0);
	//make sure frames are up-to date
	if((ret=s3c2410camif_set_format(pcam, pcam->v2f.fmt.pix.pixelformat, pcam->v2f.fmt.pix.width, pcam->v2f.fmt.pix.height))<0)
		goto error1;
	

  //start streaming
  if (start_capture(pcam, 1) != 0)
    goto error3;
  
	return 0;

error3:
	free_irq(IRQ_S3C2440_CAM_C, pcam);
error2:
	s3c2440camif_deallocate_frame_buf(pcam,S3C2440_FRAME_NUM);
error1:
	return ret;
}
Exemple #17
0
//?
void Capture::openCapture()
{
    //??
    //capture = cvCaptureFromCAM(0);
    //capture = cvCreateCameraCapture();
    /*if( ! capture )
    {
        qDebug("Could not initialize capture!");
        return ;
    }*/
    open_cam_flag=1;
    if(this->first_open_cam_flag == 0)
    {
    if(cam_init())
        {
        qDebug("camera init!");
        start_capture();
        timer->start(100);
        this->first_open_cam_flag = 1;
        ui->take_photo_pushButton->setDisabled(false);
        ui->open_pushButton->setDisabled(true);
        ui->close_pushButton->setDisabled(false);
    }
    else
    {
        qDebug("camera init error!");
        QMessageBox::information(this,tr("Waring!"),tr("Can't Open Camera!"),QMessageBox::Yes);
        ui->open_pushButton->setDisabled(false);
        ui->close_pushButton->setDisabled(true);
    }
   // start_capture();
    //timer->start(100);
    //this->first_open_cam_flag = 1;
    }
    else
    {
        timer->start(100);
        ui->open_pushButton->setDisabled(true);
        ui->close_pushButton->setDisabled(false);
    }



    //timer->start(32);  //ü?????
    //ui->close_pushButton->setDisabled(false);
    //ui->open_pushButton->setDisabled(true);

}
Exemple #18
0
static T_BOOL cam_ov3640_set_to_cap(T_U32 srcWidth, T_U32 srcHeight)
{
    T_CAMERA_MODE Cammode;

    if ((srcWidth <= 160) && (srcHeight <= 120))
    {
        Cammode = CAMERA_MODE_QQVGA;
    }
    else if ((srcWidth <= 176) && (srcHeight <= 144))
    {
        Cammode = CAMERA_MODE_QCIF;
    }
    else if ((srcWidth <= 320) && (srcHeight <= 240))
    {
        Cammode = CAMERA_MODE_QVGA;
    }
    else if ((srcWidth <= 352) && (srcHeight <= 288))
    {
        Cammode = CAMERA_MODE_CIF;
    }
    else if ((srcWidth <= 640) && (srcHeight <= 480))
    {
        Cammode = CAMERA_MODE_VGA;
    }
    else if ((srcWidth <= 1280) && (srcHeight <= 1024))
    {
        Cammode = CAMERA_MODE_SXGA;
    }
    else if ((srcWidth <= 1600) && (srcHeight <= 1200))
    {
        Cammode = CAMERA_MODE_UXGA;
    }
    else if ((srcWidth == 2048) && (srcHeight == 1536))
    {
        Cammode = CAMERA_MODE_QXGA_JPEG;
    }
    else
    {
        return AK_FALSE;
    }
    start_capture(Cammode);    
    cam_ov3640_set_digital_zoom(srcWidth, srcHeight);
    delay_ms(300);
    return AK_TRUE;
}
Exemple #19
0
bool StreamingDevice::processMessage(ClientConn& client, string& cmd, JSONNode& n){
	if (cmd == "listen"){
		cancelListen(findListener(&client, jsonIntProp(n, "id")));
		addListener(makeStreamListener(this, &client, n));
	
	}else if (cmd == "cancelListen"){
		cancelListen(findListener(&client, jsonIntProp(n, "id")));
	
	}else if (cmd == "configure"){
		int      mode =       jsonIntProp(n,   "mode");
		unsigned samples =    jsonIntProp(n,   "samples");
		double    sampleTime = jsonFloatProp(n, "sampleTime");
		bool     continuous = jsonBoolProp(n,  "continuous", false);
		bool     raw =        jsonBoolProp(n,  "raw", false);
		configure(mode, sampleTime, samples, continuous, raw);
	
	}else if (cmd == "startCapture"){
		start_capture();
	
	}else if (cmd == "pauseCapture"){
		pause_capture();
	
	}else if (cmd == "set"){
		Channel *channel = channelById(jsonStringProp(n, "channel"));
		if (!channel) throw ErrorStringException("Channel not found");
		setOutput(channel, makeSource(n));
		
	}else if (cmd == "setGain"){
		Channel *channel = channelById(jsonStringProp(n, "channel"));
		if (!channel) throw ErrorStringException("Channel not found");
		Stream *stream = findStream(
				jsonStringProp(n, "channel"),
				jsonStringProp(n, "stream"));

		double gain = jsonFloatProp(n, "gain", 1);
		
		setGain(channel, stream, gain);
	}else if (cmd == "setCurrentLimit"){
		unsigned limit = jsonFloatProp(n, "currentLimit");
		setCurrentLimit(limit);
	}else{
		return false;
	}
	return true;
}
Exemple #20
0
//--------- Begin of function Nation::think_capture_new_enemy_town --------//
//
// <Town*> capturerTown - our town to capture enemy towns.
// [int]   useAllCamp   - whether use troops in all camps to attack the enemy town
//								  (default: 0)
//
int Nation::think_capture_new_enemy_town(Town* capturerTown, int useAllCamp)
{
	if( ai_camp_count==0 )		// this can happen when a new nation has just emerged
		return 0;

	if( ai_capture_enemy_town_recno )		// no new action if we are still trying to capture a town
		return 0;

	//---- only attack when we have enough money to support the war ----//

	if( cash < 1000 + 2000 * pref_cash_reserve / 100 )		// if the cash is really too low now
		return 0;

	//--------------------------------------//

	Town* targetTown = think_capture_enemy_town_target(capturerTown);

	if( !targetTown )
		return 0;

	//---- attack enemy's defending forces on the target town ----//

	int rc = attack_enemy_town_defense(targetTown, useAllCamp);

	if( rc==0 ) 		// 0 means we don't have enough troop to attack the enemy
		return 0;

	else if( rc == 1 )		// 1 means a troop has been sent to attack the town
	{
		ai_capture_enemy_town_recno = targetTown->town_recno;		// this nation is currently trying to capture this town
		ai_capture_enemy_town_plan_date = info.game_date;
		ai_capture_enemy_town_start_attack_date = 0;
		ai_capture_enemy_town_use_all_camp = useAllCamp;

		return 1;
	}

	else if( rc == -1 )		// -1 means no defense on the target town, no attacking is needed.
	{
		return start_capture( targetTown->town_recno );		// call AI functions in OAI_CAPT.CPP to capture the town
	}

	return 0;
}
Exemple #21
0
static void finger_det_sm_complete(struct fpi_ssm *ssm)
{
	struct fp_img_dev *dev = ssm->priv;
	struct aesX660_dev *aesdev = dev->priv;
	int err = ssm->error;

	fp_dbg("Finger detection completed");
	fpi_imgdev_report_finger_status(dev, TRUE);
	fpi_ssm_free(ssm);

	if (aesdev->deactivating)
		complete_deactivation(dev);
	else if (err)
		fpi_imgdev_session_error(dev, err);
	else {
		fpi_imgdev_report_finger_status(dev, TRUE);
		start_capture(dev);
	}
}
int main(int argc, char **argv) {
    ros::init(argc, argv, "raspicam_raw_node");

    //ros::NodeHandle pn("~");
    ros::NodeHandle n;

    camera_info_manager::CameraInfoManager c_info_man(n, "camera", "package://raspicam/calibrations/camera.yaml");
    get_status(&state_srv);

    //TODO: replace this with raspicamcontrol_parse_cmdline()?
    //    pn.param<bool>("hflip", hflip, 0);
    //    ROS_INFO("hflip: %d\n", hflip);
    //    pn.param<bool>("vflip", vflip, 0);
    //    ROS_INFO("vflip: %d\n", vflip);
    //    state_srv.camera_parameters.hflip = hflip;
    //    state_srv.camera_parameters.vflip = vflip;

    ROS_INFO("hflip: %d\n", hflip);
    ROS_INFO("vflip: %d\n", vflip);
    ROS_INFO("start: %d\n", auto_start);

    if (!c_info_man.loadCameraInfo("package://raspicam/calibrations/camera.yaml")) {
        ROS_INFO("Calibration file missing. Camera not calibrated");
    } else {
        c_info = c_info_man.getCameraInfo();
        ROS_INFO("Camera successfully calibrated");
    }
    image_pub = n.advertise<sensor_msgs::Image>("image", 1);
    camera_info_pub = n.advertise<sensor_msgs::CameraInfo>("camera_info", 1);
    ros::ServiceServer start_cam = n.advertiseService("start_capture", serv_start_cap);
    ros::ServiceServer stop_cam = n.advertiseService("stop_capture", serv_stop_cap);

    if (auto_start) {
        start_capture(&state_srv);
    }

    ros::spin();
    close_cam(&state_srv);
    return 0;
}
Exemple #23
0
        DeckLinkInputAdapter(unsigned int card_index = 0,
                unsigned int norm_ = 0, unsigned int input_ = 0,
                RawFrame::PixelFormat pf_ = RawFrame::CbYCrY8422,
                bool enable_audio = false) 
                : deckLink(NULL), out_pipe(IN_PIPE_SIZE) {

            audio_pipe = NULL;

            pf = pf_;
            bpf = convert_pf(pf_);

            deckLink = find_card(card_index);
            select_input_connection(input_);
            open_input(norm_);

            if (enable_audio) {
                n_channels = 2;
                select_audio_input_connection( );
                open_audio_input( );
            }

            start_capture( );
        }
Exemple #24
0
        DeckLinkInputAdapter(unsigned int card_index = 0,
                unsigned int norm_ = 0, unsigned int input_ = 0,
                RawFrame::PixelFormat pf_ = RawFrame::CbYCrY8422,
                bool enable_audio = false, unsigned int n_channels = 2,
                bool enable_video = true)
                : deckLink(NULL), out_pipe(IN_PIPE_SIZE) {

            audio_pipe = NULL;
            started = false;
            signal_lost = false;
            rotate = false;
            this->enable_video = enable_video;

            n_frames = 0;
            start_time = 0;
            avsync = 0;
            drop_audio = 0;

            pf = pf_;
            bpf = convert_pf(pf_);

            deckLink = find_card(card_index);
            select_input_connection(input_);
            open_input(norm_);

            if (enable_audio) {
                audio_pipe = new Pipe<IOAudioPacket *>(IN_PIPE_SIZE);
            }

            this->n_channels = n_channels;
            select_audio_input_connection( );
            open_audio_input( );


            start_capture( );

        }
Exemple #25
0
void capture_complete(void)
{
    capture_copy_data();
    ctrl_shm->state = IDLE;
    switch (ctrl_usr->run_mode) {
    case STOP:
	break;
    case NORMAL:
    case ROLL:
	start_capture();
	break;
    case SINGLE:
	/* 'push' the stop button */
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ctrl_usr->
		rm_stop_button), TRUE);
	break;
    default:
	break;
    }
	
	//uncomment me to write log files
	//write_log_file("scope.log");
    refresh_display();
}
//this is for handling query commands that need a response.
void handle_query(byte cmd)
{
  //which one did we get?
  switch (cmd)
  {
    //WORKS
    case HOST_CMD_VERSION:
      //get our host version
      host_version = hostPacket.get_16(1);

      //send our version back.
      hostPacket.add_16(FIRMWARE_VERSION);
      break;

    //WORKS
    case HOST_CMD_INIT:
      //just initialize
      initialize();
      break;

    case HOST_CMD_GET_BUFFER_SIZE:
      //send our remaining buffer size.
      hostPacket.add_16(commandBuffer.remainingCapacity());
      break;

    case HOST_CMD_CLEAR_BUFFER:
      //just clear it.
      commandBuffer.clear();
      break;

    case HOST_CMD_GET_POSITION:
      //send our position
      {
	const LongPoint& c = get_position();
	hostPacket.add_32(c.x);
	hostPacket.add_32(c.y);
	hostPacket.add_32(c.z);
      }
      hostPacket.add_8(get_endstop_states());
      break;

    case HOST_CMD_GET_RANGE:
      //get our range
      {
	const LongPoint& range = get_range();
	hostPacket.add_32(range.x);
	hostPacket.add_32(range.y);
	hostPacket.add_32(range.z);
      }
      break;

    case HOST_CMD_SET_RANGE:
      //set our range to what the host tells us
      set_range(LongPoint(
			  (long)hostPacket.get_32(1),
			  (long)hostPacket.get_32(5),
			  (long)hostPacket.get_32(9)));
      break;

    case HOST_CMD_ABORT:
      //support a microcontrollers right to choice.
      abort_print();
      break;

    case HOST_CMD_PAUSE:
      if (is_machine_paused)
      {
        //unpause our machine.
        is_machine_paused = false;

        //unpause our tools
        set_tool_pause_state(false);

        //resume stepping.
	resume_stepping();
      }
      else
      {
        //pause our activity.
        is_machine_paused = true;

        //pause our tools
        set_tool_pause_state(true);

        //pause stepping
	pause_stepping();
      }
      break;

    case HOST_CMD_PROBE:
      //we dont support this yet.
      hostPacket.unsupported();
      break;

    //WORKS
    case HOST_CMD_TOOL_QUERY:
      send_tool_query(hostPacket);
      break;

  case HOST_CMD_IS_FINISHED:
    {
      bool finished = is_point_buffer_empty() && at_target() && commandBuffer.size() == 0;
      hostPacket.add_8(finished?1:0);
      break;
    }

  case HOST_CMD_READ_EEPROM:
    {
      const uint16_t offset = hostPacket.get_16(1);
      const uint8_t count = hostPacket.get_8(3);
      if (count > 16) {
	hostPacket.overflow();
      } else {
	for (uint8_t i = 0; i < count; i++) {
	  hostPacket.add_8(EEPROM.read(offset+i));
	}
      }
    }
    break;
  case HOST_CMD_WRITE_EEPROM:
    {
      uint16_t offset = hostPacket.get_16(1);
      uint8_t count = hostPacket.get_8(3);
      if (count > 16) {
	hostPacket.overflow();
      } else {
	for (uint8_t i = 0; i < count; i++) {
	  EEPROM.write(offset+i,hostPacket.get_8(4+i));
	}
	hostPacket.add_8(count);
      }
    }
    break;
  case HOST_CMD_CAPTURE_TO_FILE:
    {
      char filename[17];
      int i = 0;
      while (i < 16) {
	uint8_t c = hostPacket.get_8(i+1);
	if (c == 0) break;
	filename[i++] = c;
      }
      filename[i] = 0;
      hostPacket.add_8(start_capture(filename));
    }
    break;
  case HOST_CMD_END_CAPTURE:
    hostPacket.add_32(finish_capture());
    break;
  case HOST_CMD_PLAYBACK_CAPTURE:
    {
      char filename[17];
      int i = 0;
      while (i < 16) {
	uint8_t c = hostPacket.get_8(i+1);
	if (c == 0) break;
	filename[i++] = c;
      }
      filename[i] = 0;
      hostPacket.add_8(start_playback(filename));
    }
    break;
  case HOST_CMD_RESET:
    {
      wdt_enable(WDTO_500MS);
    }
    break;
  case HOST_CMD_NEXT_FILENAME:
    {
      uint8_t resetFlag = hostPacket.get_8(1);
      uint8_t rspCode = 0;
      if (resetFlag != 0) {
	rspCode = sd_scan_reset();
	if (rspCode != 0) {
	  hostPacket.add_8(rspCode);
	  hostPacket.add_8(0);
	  break;
	}
      }
      char fnbuf[16];
      rspCode = sd_scan_next(fnbuf,16);
      hostPacket.add_8(rspCode);
      uint8_t idx;
      for (idx = 0; (idx < 16) && (fnbuf[idx] != 0); idx++) {
	hostPacket.add_8(fnbuf[idx]);
      }
      hostPacket.add_8(0);
    }
    break;
  default:
      hostPacket.unsupported();
  }
}
Exemple #27
0
static const char *match (MatchState *ms, const char *s, const char *p) {
  init: /* using goto's to optimize tail recursion */
  switch (*p) {
    case '(': {  /* start capture */
      if (*(p+1) == ')')  /* position capture? */
        return start_capture(ms, s, p+2, CAP_POSITION);
      else
        return start_capture(ms, s, p+1, CAP_UNFINISHED);
    }
    case ')': {  /* end capture */
      return end_capture(ms, s, p+1);
    }
    case L_ESC: {
      switch (*(p+1)) {
        case 'b': {  /* balanced string? */
          s = matchbalance(ms, s, p+2);
          if (s == NULL) return NULL;
          p+=4; goto init;  /* else return match(ms, s, p+4); */
        }
        case 'f': {  /* frontier? */
          const char *ep; char previous;
          p += 2;
          if (*p != '[')
            luaL_error(ms->L, "missing " LUA_QL("[") " after "
                               LUA_QL("%%f") " in pattern");
          ep = classend(ms, p);  /* points to what is next */
          previous = (s == ms->src_init) ? '\0' : *(s-1);
          if (matchbracketclass(uchar(previous), p, ep-1) ||
             !matchbracketclass(uchar(*s), p, ep-1)) return NULL;
          p=ep; goto init;  /* else return match(ms, s, ep); */
        }
        default: {
          if (isdigit(uchar(*(p+1)))) {  /* capture results (%0-%9)? */
            s = match_capture(ms, s, uchar(*(p+1)));
            if (s == NULL) return NULL;
            p+=2; goto init;  /* else return match(ms, s, p+2) */
          }
          goto dflt;  /* case default */
        }
      }
    }
    case '\0': {  /* end of pattern */
      return s;  /* match succeeded */
    }
    case '$': {
      if (*(p+1) == '\0')  /* is the `$' the last char in pattern? */
        return (s == ms->src_end) ? s : NULL;  /* check end of string */
      else goto dflt;
    }
    default: dflt: {  /* it is a pattern item */
      const char *ep = classend(ms, p);  /* points to what is next */
      int m = s<ms->src_end && singlematch(uchar(*s), p, ep);
      switch (*ep) {
        case '?': {  /* optional */
          const char *res;
          if (m && ((res=match(ms, s+1, ep+1)) != NULL))
            return res;
          p=ep+1; goto init;  /* else return match(ms, s, ep+1); */
        }
        case '*': {  /* 0 or more repetitions */
          return max_expand(ms, s, p, ep);
        }
        case '+': {  /* 1 or more repetitions */
          return (m ? max_expand(ms, s+1, p, ep) : NULL);
        }
        case '-': {  /* 0 or more repetitions (minimum) */
          return min_expand(ms, s, p, ep);
        }
        default: {
          if (!m) return NULL;
          s++; p=ep; goto init;  /* else return match(ms, s+1, ep); */
        }
      }
    }
  }
}
Exemple #28
0
//--------- Begin of function Nation::think_capture_independent --------//
//
// Think about capturing independent towns.
//
int Nation::think_capture_independent()
{
	//------- Capture target choices -------//

	std::priority_queue<CaptureTown> captureTownQueue;

	//--- find the town that makes most sense to capture ---//

	int 	townRecno;
	Town* townPtr;

	for(townRecno=town_array.size(); townRecno>0; townRecno--)
	{
		if(town_array.is_deleted(townRecno))
			continue;

		townPtr = town_array[townRecno];

		if( townPtr->nation_recno )		// only capture independent towns
			continue;

		if( townPtr->no_neighbor_space )		// if there is no space in the neighbor area for building a new firm.
			continue;

		if( townPtr->rebel_recno )			// towns controlled by rebels will not drop in resistance even if a command base is present
			continue;

		//------ only if we have a presence/a base town in this region -----//

		if( !has_base_town_in_region(townPtr->region_id) )
			continue;

		//---- check if there are already camps linked to this town ----//

		int i;
		for( i=townPtr->linked_firm_count-1 ; i>=0 ; i-- )
		{
			Firm* firmPtr = firm_array[ townPtr->linked_firm_array[i] ];

			if( firmPtr->firm_id != FIRM_CAMP )
				continue;

			//------ if we already have a camp linked to this town -----//

			if( firmPtr->nation_recno == nation_recno )
				break;

			//--- if there is an overseer with high leadership and right race in the opponent's camp, don't bother to compete with him ---//

			if( firmPtr->overseer_recno )
			{
				Unit* unitPtr = unit_array[firmPtr->overseer_recno];

				if( unitPtr->skill.skill_level >= 70 &&
					 unitPtr->race_id == townPtr->majority_race() )
				{
					break;
				}
			}
		}

		if( i>=0 )			// there is already a camp linked to this town and we don't want to get involved with its capturing plan
			continue;

		//------ no linked camps interfering with potential capture ------//

		int captureUnitRecno;
		int targetResistance  = capture_expected_resistance(townRecno, &captureUnitRecno);
		int averageResistance = townPtr->average_resistance(nation_recno);
		int minResistance 	 = MIN( averageResistance, targetResistance );

		if( minResistance < 50 - pref_peacefulness/5 )		// 30 to 50 depending on
		{
			captureTownQueue.push({townRecno, minResistance, captureUnitRecno});
		}
	}

	//------- try to capture the town in their resistance order ----//

	const bool needToCheckDistance = !config.explore_whole_map && info.game_date-info.game_start_date >
					MAX(MAX_WORLD_X_LOC, MAX_WORLD_Y_LOC) * (5-config.ai_aggressiveness) / 5;    // 3 to 5 / 5

	while( captureTownQueue.size() > 0 )
	{
		int captureRecno = captureTownQueue.top().town_recno;
		int captureUnitRecno = captureTownQueue.top().capture_unit_recno;
		captureTownQueue.pop();

		err_when( town_array.is_deleted(captureRecno) );

		//-------------------------------------------//
		// If the map is set to unexplored, wait for a
		// reasonable amount of time before moving out
		// to build the camp.
		//-------------------------------------------//

		if( needToCheckDistance )
		{
			Town* targetTown = town_array[ captureRecno ];

			int j;
			for( j=0 ; j<ai_town_count ; j++ )
			{
				Town* ownTown = town_array[ ai_town_array[j] ];

				int townDistance = misc.points_distance(targetTown->center_x, targetTown->center_y,
										 ownTown->center_x, ownTown->center_y);

				if( info.game_date-info.game_start_date >
					 townDistance * (5-config.ai_aggressiveness) / 5 )		// 3 to 5 / 5
				{
					break;
				}
			}

			if( j==ai_town_count )
				continue;
		}

		if( start_capture( captureRecno, captureUnitRecno ) )
			return 1;
	}

	return 0;
}
void CameraController::set_capture_mode(const capture_mode_t &the_mode)
{
    m_impl->m_capture_mode = the_mode;
    if(is_capturing()){ start_capture(); }
}
Exemple #30
0
//--------- Begin of function Nation::think_capture_independent --------//
//
// Think about capturing independent towns.
//
int Nation::think_capture_independent()
{
	//------- Capture target choices -------//

	#define MAX_CAPTURE_TOWN	30

	CaptureTown capture_town_array[MAX_CAPTURE_TOWN];
	short 		capture_town_count=0;

	//--- find the town that makes most sense to capture ---//

	int 	townRecno;
	Town* townPtr;

	for(townRecno=town_array.size(); townRecno>0; townRecno--)
	{
		if(town_array.is_deleted(townRecno))
			continue;

		townPtr = town_array[townRecno];

		if( townPtr->nation_recno )		// only capture independent towns
			continue;

		if( townPtr->no_neighbor_space )		// if there is no space in the neighbor area for building a new firm.
			continue;

		if( townPtr->rebel_recno )			// towns controlled by rebels will not drop in resistance even if a command base is present
			continue;

		//------ only if we have a presence/a base town in this region -----//

		if( !has_base_town_in_region(townPtr->region_id) )
			continue;

		//---- check if there are already camps linked to this town ----//

		int i;
		for( i=townPtr->linked_firm_count-1 ; i>=0 ; i-- )
		{
			Firm* firmPtr = firm_array[ townPtr->linked_firm_array[i] ];

			if( firmPtr->firm_id != FIRM_CAMP )
				continue;

			//------ if we already have a camp linked to this town -----//

			if( firmPtr->nation_recno == nation_recno )
				break;

			//--- if there is an overseer with high leadership and right race in the opponent's camp, do bother to compete with him ---//

			if( firmPtr->overseer_recno )
			{
				Unit* unitPtr = unit_array[firmPtr->overseer_recno];

				if( unitPtr->skill.skill_level >= 70 &&
					 unitPtr->race_id == townPtr->majority_race() )
				{
					break;
				}
			}
		}

		if( i>=0 )			// there is already a camp linked to this town and we don't want to get involved with its capturing plan
			continue;

		//-- if the town has linked military camps of the same nation --//

		int targetResistance  = capture_expected_resistance(townRecno);
		int averageResistance = townPtr->average_resistance(nation_recno);
		int minResistance 	 = MIN( averageResistance, targetResistance );

		if( minResistance < 50 - pref_peacefulness/5 )		// 30 to 50 depending on
		{
			capture_town_array[capture_town_count].town_recno 	   = townRecno;
			capture_town_array[capture_town_count].min_resistance = minResistance;

			capture_town_count++;
		}
	}

	//------ sort the capture target choices by min_resistance ----//

	qsort( &capture_town_array, capture_town_count, sizeof(capture_town_array[0]), sort_capture_town_function );

	//------- try to capture the town in their resistance order ----//

	for( int i=0 ; i<capture_town_count ; i++ )
	{
		err_when( town_array.is_deleted(capture_town_array[i].town_recno) );

		//-------------------------------------------//
		// If the map is set to unexplored, wait for a
		// reasonable amount of time before moving out
		// to build the mine.
		//-------------------------------------------//

		if( !config.explore_whole_map )
		{
			Town* targetTown = town_array[ capture_town_array[i].town_recno ];

			int j;
			for( j=0 ; j<ai_town_count ; j++ )
			{
				Town* ownTown = town_array[ ai_town_array[j] ];

				int townDistance = m.points_distance(targetTown->center_x, targetTown->center_y, 
										 ownTown->center_x, ownTown->center_y);

				if( info.game_date-info.game_start_date >
					 townDistance * (5-config.ai_aggressiveness) / 5 )		// 3 to 5 / 5
				{
					break;
				}
			}

			if( j==ai_town_count )
				continue;
		}

		if( start_capture( capture_town_array[i].town_recno ) )
			return 1;
	}

	return 0;
}