1 // sketch_11_04_host_scroll_lock
3 // This sketch is based on the LCDlbd example sketch from the USB_Host_Shield library
10 /* keyboard data taken from configuration descriptor */
14 #define EP_MAXPKTSIZE 8
18 EP_RECORD ep_record[ 2 ]; //endpoint record structure for the keyboard
20 char buf[ 8 ] = { 0 }; //keyboard buffer
21 char old_buf[ 8 ] = { 0 }; //last poll
30 // set up the LCD's number of rows and columns:
32 Serial.println("Start");
40 if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING ) { //wait for addressing state
42 Usb.setUsbTaskState( USB_STATE_RUNNING );
44 if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { //poll the keyboard
49 /* Initialize keyboard */
52 byte rcode = 0; //return code
53 ep_record[ 0 ] = *( Usb.getDevTableEntry( 0,0 )); //copy endpoint 0 parameters
54 ep_record[ 1 ].MaxPktSize = EP_MAXPKTSIZE;
55 ep_record[ 1 ].Interval = EP_POLL;
56 ep_record[ 1 ].sndToggle = bmSNDTOG0;
57 ep_record[ 1 ].rcvToggle = bmRCVTOG0;
58 Usb.setDevTableEntry( 1, ep_record ); //plug kbd.endpoint parameters to devtable
59 /* Configure device */
60 rcode = Usb.setConf( KBD_ADDR, 0, 1 );
62 Serial.print("Error attempting to configure keyboard. Return code :");
63 Serial.println( rcode, HEX );
66 /* Set boot protocol */
67 rcode = Usb.setProto( KBD_ADDR, 0, 0, 0 );
69 Serial.print("Error attempting to configure boot protocol. Return code :");
70 Serial.println( rcode, HEX );
73 Serial.println("Keyboard initialized");
78 void toggleLEDs( void )
86 Usb.setReport( KBD_ADDR, 0, 1, KBD_IF, 0x02, 0, &leds );