Example #1
0
/*
 * Main loop
 */
int main(void)
{
    /* Initialize all peripherals */
    open_board();

    /* Configure stdout/stderr to be keyboard input to the host */
    open_streams();

    led_set(3, 1, 1);
    for (;;) {
        poll_matrix();
        update_matrix();
            
        // Handle USB HID reporting
        // Generic USB tasks take place in interrupt
        USB_USBTask();
        USB_HIDTask();

        if (GFLAGS & GF_BOOTLOADER)
            break;

        maybe_sleep();
    }

    /* Disable stdout/stderr. We can't use it if usb is down */
    close_streams();

    /* Teardown everything we setup. Nothing can be active before the jump */
    close_board();

    jump_to_bootloader();
}
Example #2
0
int main()
{
    struct termios boardSettings;
    struct termios oldBoardSettings;

    int board;
    int sent;

    printf("INPUT TERMINAL\n\n");

    printf("Trying to connect to the board...");

    board = open_board(&oldBoardSettings, &boardSettings);

    if( board < 0 )
    {
        printf("Error: connection to board failed.");
        return 1;
    }

    char ctty = 0;
    char cboard = 0;

    printf("Connection successful!\n\n");

    while(1)
    {
        printf("user> ");

        packet_t p;
        p.header = 0x0;
        p.command = 0x0;

        ctty = getchar_tty();

        switch(ctty)
        {
            case '1':
                printf("pc> turn on led1.\n");
                p.header = SET_LED;
                p.command = LED1;
                break;
            case '2':
                p.header = SET_LED;
                p.command = LED2;
                break;
            case '3':
                p.header = SET_LED;
                p.command = LED3;
                break;
            case '4':
                p.header = SET_LED;
                p.command = LED4;
                break;
            case 'q':
                break;
            default:
                ctty = 0;
                printf("pc> Command not recognized.\n");
        };

        if(ctty == 'q')
            break;

        if(ctty)
            send_packet(board, p);

        sleep(1); //give time to board to write output

        while( (cboard = getchar_board(board)) )
            printf("%c", cboard);
    }

    printf("\nEnd of communication.\n");

    close_board(board, &oldBoardSettings);

    return 0;
}