Exemplo n.º 1
0
int main(void)
{
	int8_t x, y, *p;
	uint8_t i;

	// set for 16 MHz clock
	CPU_PRESCALE(0);
	LED_CONFIG;
	LED_OFF;

	// Initialize the USB, and then wait for the host to set configuration.
	// If the Teensy is powered without a PC connected to the USB port,
	// this will wait forever.
	usb_init();
	while (!usb_configured()) /* wait */ ;

	// Wait an extra second for the PC's operating system to load drivers
	// and do whatever it does to actually be ready for input
	_delay_ms(1000);

	while (1) {
		// This sequence creates a left click
		usb_mouse_buttons(1, 0, 0);
		_delay_ms(10);
		usb_mouse_buttons(0, 0, 0);
	}
}
Exemplo n.º 2
0
void move_mouse(void) {

    /* don't move the mouse unless we already took 2 readings */
    if (!initalized) {
        initalized = 1;
    } else {
        // ignore least significant bit, as it's probably noise
        currentX = currentX >> 1; 
        currentY = currentY >> 1;

        deltaX = previousX - currentX;
        deltaY = previousY - currentY;
    
        if (((deltaX < THRESHOLD) &&  (deltaX > -THRESHOLD))
            && (deltaY < THRESHOLD && (deltaY > -THRESHOLD))) {
        
#ifdef DEBUG
            if (deltaX != 0 || deltaY != 0) {
              print("x="); phex(deltaX); print("\t");
              print("y="); phex(deltaY); print("\n");
            }
#endif
            usb_mouse_move(deltaX, deltaY, 0);
            currButtonState = PIND & 0x01;  // Care about D0 only
            // button pressed
            if (!currButtonState) {
                usb_mouse_buttons(1, 0, 0);
            } else { // released
                usb_mouse_buttons(0, 0, 0);
            }
        }
    }
            
    previousX = currentX;
    previousY = currentY;
}