Exemplo n.º 1
0
/*
 *  ======== Global_getCpuLoad ========
 */
Int Global_getCpuLoad(Void)
{
    return (Load_getCPULoad());
}
/*
 *  ======== consoleTaskFxn ========
 *  Console task
 *
 *  This task listens to the key pressed in the keyboard through USBCDC.
 *  The string ended with return character '\n' will trigger the task
 *  to send this string to the mailbox.
 *  For example, when the user enter "ls\n", this task will scan all the
 *  files in the root of SD card and send the file list to the mailbox to
 *  inform the drawing task to display on the screen.
 *  The up/down arrow can be used to scroll up/down to display more files
 *  in the SD card.
 */
Void consoleTaskFxn (UArg arg0, UArg arg1)
{
    unsigned int count;
    unsigned int cpuLoad;
    char input[128];
    UInt key;
    DrawMessage drawMsg;
    count = 1;

    /* printf goes to the UART com port */
    printf("\f======== Welcome to the Console ========\n");
    printf("Enter a command followed by return.\n"
           "Type help for a list of commands.\n\n");

    printf("%d %% ", count++);
    fflush(stdout);

    /* Loop forever receiving commands */
    while(true) {
        /* Get the user's input */
        scanf("%s", input);
        /* Flush the remaining characters from stdin since they are not used. */
        fflush(stdin);

        if (!strcmp(input, "a")) {
            /* Print the CPU load */
            cpuLoad = Load_getCPULoad();
            printf("CPU Load: %d\n", cpuLoad);
            drawMsg.drawCommand = KeyBoadCOMMAND;


            up_remove_blank(4);
            up(4);


            // copy the data to message
            key = Gate_enterSystem();
            copyFrom2048ArrayToDrawMessage(4,drawMsg.draw2048 , Array2048);
            Gate_leaveSystem(key);

            Mailbox_post(mailboxHandle, &drawMsg, BIOS_WAIT_FOREVER);
        }
        else if (!strcmp(input, "d")) {
            /* Print the CPU load */
            cpuLoad = Load_getCPULoad();
            printf("CPU Load: %d\n", cpuLoad);
            drawMsg.drawCommand = KeyBoadCOMMAND;

            down_remove_blank(4);
            down(4);


            // copy the data to message
            key = Gate_enterSystem();
            copyFrom2048ArrayToDrawMessage(4,drawMsg.draw2048 , Array2048);
            Gate_leaveSystem(key);

            Mailbox_post(mailboxHandle, &drawMsg, BIOS_WAIT_FOREVER);
        } else if (!strcmp(input, "w")) {
            /* Print the CPU load */
            cpuLoad = Load_getCPULoad();
            printf("CPU Load: %d\n", cpuLoad);
            drawMsg.drawCommand = KeyBoadCOMMAND;

            left_remove_blank(4);
            left(4);


            // copy the data to message
            key = Gate_enterSystem();
            copyFrom2048ArrayToDrawMessage(4,drawMsg.draw2048 , Array2048);
            Gate_leaveSystem(key);

            Mailbox_post(mailboxHandle, &drawMsg, BIOS_WAIT_FOREVER);
        } else if (!strcmp(input, "s")) {
            /* Print the CPU load */
            cpuLoad = Load_getCPULoad();
            printf("CPU Load: %d\n", cpuLoad);
            drawMsg.drawCommand = KeyBoadCOMMAND;

            right_remove_blank(4);
            right(4);


            // copy the data to message
            key = Gate_enterSystem();
            copyFrom2048ArrayToDrawMessage(4,drawMsg.draw2048 , Array2048);
            Gate_leaveSystem(key);

            Mailbox_post(mailboxHandle, &drawMsg, BIOS_WAIT_FOREVER);
        }
        else if (!strcmp(input, "exit")) {
            /* Exit the console task */
            printf("Are you sure you want to exit the console? Y/N: ");
            fflush(stdout);
            scanf("%s", input);
            fflush(stdin);
            if ((input[0] == 'y' || input[0] == 'Y') && input[1] == 0x00) {
                printf("Exiting console, goodbye.\n");
                Task_exit();
            }
        }
        else {
            /* Print a list of valid commands. */
            printf("Valid commands:\n"
                   "- w: move up.\n"
                   "- a: move left.\n"
                   "- s: move down.\n"
                   "- a: move right.\n"
                   "- exit: Exit the console task.\n");
        }

        fillBox(4);
//	        printf("%d %% ", count++);
        fflush(stdout);
    }

}