예제 #1
0
void VideoGrabber::Main()
{
	if ( !channel ) return ;

	PTRACE( 1, "Going to grab from video device" );
	while ( run ) {
		mutex.Wait();
		State s = state;
		mutex.Signal();

		// prepare for the state...
		closeDevices();
		switch( s ) {
			case SPreview:
				if( !openDevices() ) {
					stopPreview();
					ancaInfo->setInt( VG_STATE, VG_IDLE );
				}
				break;
			case SCall:
				openReader();
				break;
			case SSleep:
				break;
		}
		preparing = false;

		// do
		switch( s ) {
			case SSleep:
			case SCall:
				goSleep();
				break;
			case SPreview:
				while ( state == SPreview && run && !reconfigure ) {
					channel->Read( buffer, bufferSize );
					channel->Write( buffer, bufferSize );

					Sleep( 50 );
				}
		}
	}
}
예제 #2
0
void main(void) {
    PHY_init_t phy_params;
    LINK_init_t link_params;       

    WDTCONbits.SWDTEN = 0; 
    
    LOG_init();                
    D_G printf("Main started\n");    
    
    phy_params.bitrate = DATA_RATE_66;
    phy_params.band = BAND_863;
    phy_params.channel = 28;
    phy_params.power = TX_POWER_13_DB;
    phy_params.cca_noise_treshold = 30;
    PHY_init(phy_params);
    D_G printf("PHY inicialized\n");
    
    link_params.tx_max_retries = 0;
    link_params.rx_data_commit_timeout = 64; 
    LINK_init(link_params);

    ds_prepare();
    for (uint8_t i = 0; i < 12; i++) {
        LED0 = ~LED0;
        delay_ms(50);
    }
    
    fitp_init(); 
    
    /*
    GLOBAL_STORAGE.edid[0] = 0xED; //E
    GLOBAL_STORAGE.edid[1] = 0x00; //d
    GLOBAL_STORAGE.edid[2] = 0x00; //i
    GLOBAL_STORAGE.edid[3] = 0x01; //d
    
    GLOBAL_STORAGE.nid[0]=0x4e;  //N
    GLOBAL_STORAGE.nid[1]=0x69; //i
    GLOBAL_STORAGE.nid[2]=0x64; //d
    GLOBAL_STORAGE.nid[3]=0x3c;  //:
    */
             
    GLOBAL_STORAGE.sleepy_device = true;
    
    euid_load(); // load euid from eeprom
    refresh_load_eeprom();
    
    accel_int = false;
    while (1) {       
        
        if (accel_int) {
            HW_ReInit();      
            if (sendValues()) { 
                D_G printf("Send values success\n");               
                LED1 = 1;
                delay_ms(1000);
                LED1 = 0;            
            }
            else if (fitp_join()){
                D_G printf("Join success\n"); 
                LED1 = 1;
                delay_ms(1000);
                LED1 = 0;
            }
            else {  // cannot send data and even join fails
                D_G printf("Send value and join failed\n");
                LED0 = 1;
                delay_ms(1000);
                LED0 = 0;
            }
            accel_int = false;                                    
        }           
       
        if (fitp_joined()){            
            ds_prepare();
            HW_DeInit();
            StartTimer(2);            
            goSleep();
            if (accel_int) {
                continue;
            }
            //LED1 = 1;
            HW_ReInit();
            sendValues();             
        }   
        
        HW_DeInit();
        if(GLOBAL_STORAGE.refresh_time < 3) {
        	GLOBAL_STORAGE.refresh_time = 3;  // if too short time         
        	save_refresh_eeprom(GLOBAL_STORAGE.refresh_time); //save refresh time on eeprom
        }
        StartTimer(GLOBAL_STORAGE.refresh_time - 2);  // -2 because ds_prepare takes up to 2seconds 
        //LED1 = 0;
        goSleep();
    }
}
예제 #3
0
int main(int argc, char *argv[])
{		
		
	if(argc == 1)
	{
		printf("ERROR: Please specify the location of the event file\n\n");
		exit(1);
	}	
	
	int returned = 0;	
	long lineNumbers = 0;
	
	FILE *file = fopen(argv[1], "r");
	
	if(file)
	{		
		size_t i, j, k, l, m, x;
			
		char buffer[BUFSIZ], *ptr;				
		fgets(buffer, sizeof buffer, file);		
		ptr = buffer;
		lineNumbers = (long)strtol(ptr, &ptr, 10);
		
		printf("\n\nLine Numbers = %lu\n\n", lineNumbers);
		
		// eventType will then match based on whatever is in the sendEvents.txt file

		unsigned short * eventType;
		unsigned short * codeData;
		unsigned short * typeData;
		unsigned long * valueData;
		uint64_t * timeArray;
		
		eventType = (unsigned short *) calloc((lineNumbers*1), sizeof(unsigned short));
		codeData = (unsigned short *) calloc((lineNumbers*1), sizeof(unsigned short));
		typeData = (unsigned short *) calloc((lineNumbers*1), sizeof(unsigned short));		
		valueData = (unsigned long *) calloc((lineNumbers*1), sizeof(unsigned long));
		timeArray = (uint64_t *) calloc((lineNumbers*1), sizeof(uint64_t));
		
	
		if(eventType == NULL)
			printf("eventType failed malloc\n");
		if(codeData == NULL)
			printf("codeData failed malloc\n");
		if(typeData == NULL)
			printf("typeData failed malloc\n");
		if(valueData == NULL)
			printf("valueData failed malloc\n");
		if(timeArray == NULL)
			printf("timeArray failed malloc\n");
	
		
		int everyOther = 0;
	
		for(i = 0, l = 0, m = 0; fgets(buffer, sizeof buffer, file); ++i)
		{
			if(everyOther == 1)
			{
				for(j = 0, ptr = buffer; j < 4; ++j, ++ptr)
				{
					if(j == 0)
						eventType[m] = (unsigned short)strtoul(ptr, &ptr, 10);						
					else if(j == 1)
						codeData[m] = (unsigned short)strtoul(ptr, &ptr, 10);
					else if(j == 2)
						typeData[m] = (unsigned short)strtoul(ptr, &ptr, 10);
					else if(j == 3)
						valueData[m] = (unsigned long)strtoul(ptr, &ptr, 10);					
				}
				
				m++;
				everyOther = 0;					
			}
			else
			{
				ptr = buffer;
				timeArray[l] = (uint64_t)strtoull(ptr, &ptr, 10);		
				everyOther = 1;
				l++;
			}
		}
		fclose(file);

		//========		Start Sending Events		============
				
		char device[] = "/dev/input/event "; 
		//[16] is for the event input number
		
		char* deviceP = device;
		int fd;
		
		j=0,k=0;
		
		// For each of the line numbers get the event, validate it, and then write it
		while(k < lineNumbers)
		{				
			deviceP[16] = eventType[k]+48; //add 48 to get to the ascii char
			fd = open(deviceP, O_RDWR);		

			int ret;
			int version;
		
			// Make sure opening the device opens properly			
			if(fd <= 0) 
			{
				fprintf(stderr, "could not open %s, %s\n", *(&deviceP), strerror(errno));
				return 1;
			}
			
			if (ioctl(fd, EVIOCGVERSION, &version)) 
			{
				fprintf(stderr, "could not get driver version for %s, %s\n", *(&deviceP), strerror(errno));
				return 1;
			}			
			
			struct input_event checkEvent[5];
			int valid = 0;			
					
			if(timeArray[j] == 0)
			{
				// Prep the event for checking, store the type, code, value in checkEvent
				l = 0;
				while((timeArray[j] == 0) && (j < lineNumbers)) //check the next one, but not if at end of array
				{	
					checkEvent[l].type = codeData[k];
					checkEvent[l].code = typeData[k];
					checkEvent[l].value = valueData[k];
					j++;
					k++;
					l++;
					valid++;
				}				
			}
			else
			{		
				// Sleep for time interval calculated in Translate
				printf("%d. ", k);
				goSleep(timeArray[j]);
				checkEvent[0].type = codeData[k];
				checkEvent[0].code = typeData[k];
				checkEvent[0].value = valueData[k];
				j++;
				k++;
				valid = 1;		
			}
			
			struct input_event event[valid];
			memset(&event, 0, sizeof(event));
			
			for(x = 0; x < valid; x++)
			{
				event[x].type = checkEvent[x].type;
				event[x].code = checkEvent[x].code;
				event[x].value = checkEvent[x].value;
			}
					
			// ** Write the event that we just got from checkEvent **
			ret = write(fd, &event, sizeof(event));			
						
			if(ret < sizeof(event)) 
			{
				fprintf(stderr, "write event failed, %s\n", strerror(errno));
				//should exit...				
			}    
			
			close(fd);
		}		
	}
	else // fopen() returned NULL
	{
		//perror(filename);
		perror(argv[1]);
	}
	
	return 0;
}
예제 #4
0
파일: main.c 프로젝트: kqzca/prj
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC_Init();
  MX_DAC_Init();
  MX_I2C1_Init();
  MX_RTC_Init();

  /* USER CODE BEGIN 2 */
				
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
	//int loopCnt = 0;
  while (1)
  {
		Button_Function buttonFunction = checkButtonFunction();
		if (buttonFunction == BTNFUNC_STATECHN)
		{
			wakeupSleepState = (wakeupSleepState == STATE_WAKEUP) ? STATE_SLEEP : STATE_WAKEUP;
		}
		
		if (buttonFunction == BTNFUNC_CAL)
		{
			setSensorDevPwr(DEV_PWR_ON);
			getSnrDrvDacVal();
			setSensorDevPwr(DEV_PWR_OFF);
			wakeupSleepState = STATE_WAKEUP;
		}
				
		if (wakeupSleepState == STATE_WAKEUP)
		{
			uint16_t snrAdcVal = 0;
			
			setBlueToothDevPwr(DEV_PWR_ON);
			setSensorDevPwr(DEV_PWR_ON);
			setSysWakeUpLed(LED_ON);
			setSysStsLed(LED_OFF);
			
			int snrDrvDacVal = readEEPROM32(EEPROM_ADDR_SNRDRVVAL);
			if ((snrDrvDacVal < 1) || (snrDrvDacVal > 0xFFF))
			{
				getSnrDrvDacVal();
			}
			snrAdcVal = (uint16_t)dacOutAdcIn(snrDrvDacVal, ADC_CHANNEL_8);
			if (snrAdcVal > SNR_PASS_THRESHOLD)
			{
				setTestPassLed(LED_ON);
				setTestFailLed(LED_OFF);
			}
			else
			{
				setTestFailLed(LED_ON);
				setTestPassLed(LED_OFF);
			}
			
			if (hi2c1.State == HAL_I2C_STATE_READY)
			{
				setBleSig(BLESIG_HI);
				if (HAL_I2C_Slave_Transmit(&hi2c1, (uint8_t *)&snrAdcVal, 2, 3000) == HAL_OK)
				{
					setSysStsLed(LED_ON);
					HAL_Delay(100);
					setSysStsLed(LED_OFF);
					HAL_Delay(100);
					setSysStsLed(LED_ON);
					HAL_Delay(100);
					setSysStsLed(LED_OFF);
				}
				else
				{
					setSysStsLed(LED_ON);
					HAL_Delay(300);
					setSysStsLed(LED_OFF);
				}
			}
			else
			{
				setSysWakeUpLed(LED_OFF);
				HAL_Delay(100);
				setSysWakeUpLed(LED_ON);
				HAL_Delay(100);
				setSysWakeUpLed(LED_OFF);
				HAL_Delay(100);
				setSysWakeUpLed(LED_ON);
				HAL_Delay(100);
			}
			
			setTestFailLed(LED_OFF);
			setTestPassLed(LED_OFF);
			HAL_Delay(1000);
			setBleSig(BLESIG_LO);
			HAL_Delay(1000);
		}
		else
		{
			goSleep();
		}
		
		/*
		loopCnt++;
		if (loopCnt >= 2)
		{
			loopCnt = 0;
		}
		*/
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}