Ejemplo n.º 1
0
	void
	V4LFrameSource::open() {
		if (isOpen()) return;

		if (m_deviceName.length() < 1) throw IOException("V4LFrameSource device not set");
		if (m_width < 0 || m_height < 0) throw IOException("V4LFrameSource width or height invalid");
		
		bool wasReset = usbReset();
		
		for (int i = 0; i < 5 && m_fd < 0; i++) {
			//m_fd = ::open(m_deviceName.c_str(), O_RDWR | O_NONBLOCK, 0);
			m_fd = ::open(m_deviceName.c_str(), O_RDWR, 0);
			if (m_fd < 0 && wasReset) {
				sleep(1);
			}
		}
		
		if (m_fd < 0) {
			throw IOException("Failed to open v4l camera");
		}

		checkCapabilities();
		updateCropping();
		updateVideoFormat();
		updateExposureTime(m_exposureTime);
		updateStreamParameters(m_frameRate);

		mmapBuffers();
	}
Ejemplo n.º 2
0
// ==============================================================================
// - main
// ------------------------------------------------------------------------------
int main(void)
{
    // ------------------------- Initialize Hardware
    //PORTB: LEDs

    DDRB = 0x0f;
    PORTB = 0x00;

    // PORTC: Buttons
    DDRC 	= 0x00;		// set all pins to input
    PORTC 	= 0x0f;		// pullups

    // PORTD: 4066 control, interrupt, rx/tx, USB
    DDRD = 0xf2;


    // init UART
    UCSR0B = ( 1 << UCSZ02);
    UCSR0C = /*( 1 << UPM1) | */( 1 << UCSZ01) | ( 1 << UCSZ00 );		// Even Parity, 9 bit, 1 stop bit
    UBRR0H = 0;
    UBRR0L = 249; 												// 5000 baud (F_CPU/16/BAUD - 1)

    // enable Pinchange Interrupt on PC5 -> PCINT13
    PCICR = (1 << PCIE1);
    PCMSK1 = (1 << PCINT13);


    usbDeviceConnect();
    usbReset();
    usbInit();

    wdt_enable(WDTO_1S);	// enable watchdog timer

    sei();

    tx_state = idle_tx;

    UCSR0B |= (1 << TXEN0); // turn on uart

    select_cam(0);

    unsigned long tt;
    unsigned char idx;

    // ------------------------- Main Loop
    while(1) {
        wdt_reset();
        usbPoll();			// see if there's something going on on the usb bus
        check_uart();
    }
    return 0;
}
Ejemplo n.º 3
0
// ==============================================================================
// - main
// ------------------------------------------------------------------------------
int main(void)
{

	// ------------------------- Initialize Hardware
	//PORTB: LEDs
	
	DDRB = 0x0f;
	PORTB = 0x00;

	// PORTC: Buttons
	DDRC 	= 0x00;		// set all pins to input
	PORTC 	= 0x0f;		// pullups
		
	// PORTD: 4066 control, interrupt, rx/tx, USB
	DDRD = 0xf2;
	
	// timer 0	-> millisecond clock
	ticks 	= 0;
	TCCR0A 	= (1 << WGM01);									// CTC
	TCCR0B 	= (0 << CS02) | (1 << CS01) | (0 << CS00);		// 8 prescaler @ 20Mhz -> 2'500'000 Hz
	TIMSK0 	= (1 << OCIE0A);								// enable interrupt
	OCR0A	= 249;											// 10000 Hz -> 10 ticks / Millisecond

	// init UART
	UCSR0B = ( 1 << UCSZ02); 						
	UCSR0C = /*( 1 << UPM1) | */( 1 << UCSZ01) | ( 1 << UCSZ00 );		// Even Parity, 9 bit, 1 stop bit
	UBRR0H = 0;
	UBRR0L = 249; 												// 5000 baud (F_CPU/16/BAUD - 1)

	// enable Pinchange Interrupt on PC5 -> PCINT13
	PCICR = (1 << PCIE1);
    PCMSK1 = (1 << PCINT13);
	

	usbDeviceConnect();
	usbReset();
    usbInit();

	wdt_enable(WDTO_1S);	// enable watchdog timer

	sei();
	
	tx_state = idle_tx;
	
	UCSR0B |= (1 << TXEN0); // turn on uart
	
	select_cam(0);
	
	unsigned long tt;
	unsigned char idx;
	
	// ------------------------- Main Loop
	while(1) {
        wdt_reset();
		usbPoll();			// see if there's something going on on the usb bus
        check_uart();	
        
        if (millis()-lastTime >= 80) {
        	 check_buttons();
        }
	}
	return 0;
}
Ejemplo n.º 4
0
int main(void)
{
	char just_detected = 1;
	Gamepad *pad = NULL;

	hardwareInit();
	gcn64protocol_hwinit();

#ifdef WAIT_FOR_PAD
	do {
		pad = tryDetectController();
	} while (pad == NULL);
	curGamepad = pad;
#else
	char i = 60;
	do {
		pad = tryDetectController();
		if (pad) {
			curGamepad = pad;
			break;
		}
		_delay_ms(16);
	} while (--i);
#endif

reconnect:
	cli();

#ifdef SNES_MODE
	if (curGamepad && curGamepad->reportDescriptor) {
		rt_usbHidReportDescriptor = curGamepad->reportDescriptor;
		rt_usbHidReportDescriptorSize = curGamepad->reportDescriptorSize;
	} else {
		rt_usbHidReportDescriptor = (void*)gcn64_usbHidReportDescriptor;
		rt_usbHidReportDescriptorSize = getUsbHidReportDescriptor_size();
	}
#else
	rt_usbHidReportDescriptor = (void*)gcn64_usbHidReportDescriptor;
	rt_usbHidReportDescriptorSize = getUsbHidReportDescriptor_size();
#endif

	if (curGamepad && curGamepad->deviceDescriptor) {
		rt_usbDeviceDescriptor = curGamepad->deviceDescriptor;
		rt_usbDeviceDescriptorSize = curGamepad->deviceDescriptorSize;
	} else {
		rt_usbDeviceDescriptor = (void*)usbDescrDevice;
		rt_usbDeviceDescriptorSize = getUsbDescrDevice_size();
	}

	// patch the config descriptor with the HID report descriptor size
	my_usbDescriptorConfiguration[25] = rt_usbHidReportDescriptorSize;
	my_usbDescriptorConfiguration[26] = rt_usbHidReportDescriptorSize >> 8;

	// Do hardwareInit again. It causes a USB reset.

	wdt_enable(WDTO_2S);
	usbInit();
	usbReset();
	sei();
	while (1)
	{
		usbPoll();
		wdt_reset();

		if ((curGamepad == NULL ))
		{
			//either no controller detected or we changed mode... lets try to redetect controller !
			pad = tryDetectController();
			if (pad) {
				curGamepad = pad;
				just_detected = 1;

				/*if (pad->reportDescriptor != rt_usbHidReportDescriptor) {
					goto reconnect;
				}*/
			}
			else
			{
				curGamepad = NULL;
			}
		}
		
		if (curGamepad != NULL) {
			controller_present_doTasks(just_detected);
			just_detected = 0;
		}
	}
	return 0;
}