Henk Meewis / Mbed 2 deprecated USB_serial_LED_controller

Dependencies:   mbed

Fork of frdm_echo by Henk Meewis

shell.cpp

Committer:
silverpanda
Date:
2014-04-14
Revision:
8:b715912d684b
Parent:
7:19da09fe546b
Child:
9:f9efd3a69c2d

File content as of revision 8:b715912d684b:

#include "mbed.h"
#include "LEDColors.h"
#include "shell.h"

extern LEDColors *ledColors;

// create contructor
Shell::Shell(uint32_t thisBaudRate)
{
    usbSerial = new Serial(USBTX, USBRX);
    usbSerial->baud(115200);
    characterCount = 0;
    characterPointer = 0;
}
//-----------------------------------------------------------------------------

void Shell::sendText(char *thisText)
{
    // this can send any text
    usbSerial->printf(thisText);
}
//-----------------------------------------------------------------------------

void Shell::sendHelloWorld()
{
    // sends the first greeting
    sendText("** Hello World **\n\n> ");
}
//-----------------------------------------------------------------------------

void Shell::scanUSBSerialRx()
{
    // check if there is something to read
    if(usbSerial->readable()) {
        
        // if so ...
        char character = usbSerial->getc();
        
        // see if this is a semi colon or a carriage return
        // if so, give a new line cursor
        if((character == ';') || (character == 13)) {
            usbSerial->printf("\n> ");
            finishCharacterBuffer();
            ledColors->flashWhite(10);
        }
        
        // if not, just print the character
        else {
            usbSerial->printf("%c", character); 
            addCharacterToBuffer(character);       
            ledColors->flashGreen(10);
        }
    }
}
//-----------------------------------------------------------------------------
   
void Shell::addCharacterToBuffer(char newCharacter)
{
    if(characterPointer < ItsInputBufferSize_) {
        inputBuffer[characterPointer++] = newCharacter;
        characterCount = characterPointer;
    }
}
//-----------------------------------------------------------------------------

void Shell::finishCharacterBuffer()
{
    characterPointer = 0;
}
//-----------------------------------------------------------------------------