TEAMUSB_SLAVE

Dependencies:   USBHost mbed

Fork of USBHostKeyboard_HelloWorld by TEAMUSB

main.cpp

Committer:
armdran
Date:
2015-03-27
Revision:
8:f8122ca2f58f
Parent:
7:be82ac3c4821
Child:
9:8bcd70b26084

File content as of revision 8:f8122ca2f58f:

#include "mbed.h"
#include "USBHostKeyboard.h"
#include "rtos.h"

DigitalOut led(LED1);

void onKey(uint8_t key) {
    printf("Key: %c\r\n", key);
}

void onKeyMod(uint8_t key, uint8_t modifier) {
    printf("Key: %c\r\n", key);
}


void keyboard_task(void const *) {
    
    USBHostKeyboard keyboard;
    
    while(1) {
        
        printf("trying to connect\r\n");
        
        // try to connect a USB keyboard
        while(!keyboard.connect()) {
            Thread::wait(500);
        }

        printf("connected\r\n");

    
        // when connected, attach handler called on keyboard event
        keyboard.attach(onKey);
        keyboard.attach(onKeyMod);
        
        printf("eventhandler attached\r\n");
        
        // wait until the keyboard is disconnected
        while(keyboard.connected()) {
            USBHost::poll();
        }
            
        printf("disconnected\r\n");
        
    }
}

int main() {
    Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4);
    
    while(1) {
        led=!led;
        Thread::wait(2000); 
    }
}