Test serial console demonstrating various API functions of WiConnect library.

Dependencies:   WiConnect mbed

ConsoleSerial.h

Committer:
dan_ackme
Date:
2014-08-11
Revision:
0:836c9a6383e0
Child:
1:5137ec8f4c45

File content as of revision 0:836c9a6383e0:

/*
 * Copyright 2014, ACKme Networks
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks;
 * the contents of this file may not be disclosed to third parties, copied
 * or duplicated in any form, in whole or in part, without the prior
 * written permission of ACKme Networks.
 */

#pragma once

#include <stdarg.h>

#include "mbed.h"




class ConsoleSerial : public Serial
{
public:

    ConsoleSerial(PinName tx, PinName rx) : Serial(tx, rx)
    {

    }

    void setBaud(int baud)
    {
        this->baud(baud);
    }

    int read()
    {
        return getc();
    }

    void write(int c)
    {
        putc(c);
    }

    void write(const char *s)
    {
        puts(s);
    }

    void write(char *s)
    {
        puts(s);
    }

    void write(const void *data, int size)
    {
        Serial::write(data, size);
    }

    void printf(const char *fmt, ...)
    {
        va_list va;
        va_start(va, fmt);
        vprintf(fmt, va);
        va_end(va);
    }

    void vprintf(const char *fmt, va_list va)
    {
        char buf[512];
        vsnprintf(buf, sizeof(buf), fmt, va);
        write(buf);
    }

};