Library for EarthLCD ezLCD3xx line of products

Dependents:   ezLCDTest

/media/uploads/codeman/front.jpg /media/uploads/codeman/all.jpg /media/uploads/codeman/arlcd.jpg /media/uploads/codeman/side.jpg

ezLCDLib.cpp

Committer:
codeman
Date:
2013-04-22
Revision:
0:65606abcae36
Child:
1:c7659c8af0d3

File content as of revision 0:65606abcae36:

#include "mbed.h"
#include "ezLCDLib.h"

#define XSIZE 6
#define YSIZE 9
#define BUFF_LEN 10
ezLCD3::ezLCD3(PinName tx, PinName rx) : Stream("ezLCD3") , _ser(tx, rx)
{
    _ser.baud(115200);               // default baud rate
}


/* itoa:  convert n to characters in s */
void ezLCD3::itoa(int value, char *sp, int radix)
{
    char tmp[16];// be careful with the length of the buffer
    char *tp = tmp;
    int i;
    unsigned v;
    int sign;

    sign = (radix == 10 && value < 0);
    if (sign)   v = -value;
    else    v = (unsigned)value;

    while (v || tp == tmp) {
        i = v % radix;
        v /= radix; // v/=radix uses less CPU clocks than v=v/radix does
        if (i < 10)
            *tp++ = i+'0';
        else
            *tp++ = i + 'a' - 10;
    }

    if (sign)
        *sp++ = '-';
    while (tp > tmp)
        *sp++ = *--tp;
}
void ezLCD3::sendInt( int i )
{
    char value[5]= {0, 0, 0, 0, 0};
    itoa(i, value, 10);
    if(value[0]) putc(value[0]);
    if(value[1]) putc(value[1]);
    if(value[2]) putc(value[2]);
    if(value[3]) putc(value[3]);
    if(value[4]) putc(value[4]);
}
/*
int ezLCD3::getInt( char *str )
{
    return atoi(str);
}
void ezLCD3::getString( char *str )
{
    char value[5]= {0, 0, 0, 0, 0};
    int counter;
    
}
*/
bool ezLCD3::waitForCR( void )
{
    while(! _ser.readable());
    if(_ser.getc() == '\r')
        return true;
    else
        return false;
}

void ezLCD3::cls()
{
    sendInt(Clr_Screen);
    _ser.putc('\r');
    waitForCR();
}

void ezLCD3::cls(int bColor)
{
    sendInt(Clr_Screen);
    _ser.putc(' ');
    sendInt(bColor);
    _ser.putc('\r');
    waitForCR();
}

void ezLCD3::cls(int bColor, int fColor)
{
    sendInt(Clr_Screen);
    _ser.putc(' ');
    sendInt(bColor);
    _ser.putc(' ');
    sendInt(fColor);
    _ser.putc('\r');
    waitForCR();
}
void ezLCD3::color(int fColor)
{
    sendInt(Color);
    _ser.putc(' ');
    sendInt(fColor);
    _ser.putc('\r');
    waitForCR();
}

void ezLCD3::pos(int col, int row)
{
    //posXY(XSIZE*col, (YSIZE*row));
}

void ezLCD3::xy(int x, int y)
{
    sendInt(XY);
    _ser.putc(' ');
    sendInt(x);
    _ser.putc(' ');
    sendInt(y);
    _ser.putc('\r');
}

void ezLCD3::plot( void )
{
    sendInt(Plot);
    _ser.putc('\r');
    waitForCR();
}

void ezLCD3::plot( int x, int y )
{
    sendInt(Plot);
    _ser.putc(' ');
    sendInt(x);
    _ser.putc(' ');
    sendInt(y);
    _ser.putc('\r');
    waitForCR();
}
void ezLCD3::line(int x, int y )
{
    sendInt(Line);
    _ser.putc(' ');
    sendInt(x);
    _ser.putc(' ');
    sendInt(y);
    _ser.putc('\r');
    waitForCR();

}

void ezLCD3::circle(int radius, bool filled)
{
    sendInt(Circle);
    _ser.putc(' ');
    sendInt(radius);
    if(filled) {
        _ser.putc(' ');
        _ser.putc('f');
    }
    _ser.putc('\r');
    waitForCR();
}

void ezLCD3::box(int x, int y, bool filled)
{
    sendInt(Box);
    _ser.putc(' ');
    sendInt(x);
    _ser.putc(' ');
    sendInt(y);
    if(filled) {
        _ser.putc(' ');
        _ser.putc('f');
    }
    _ser.putc('\r');
    waitForCR();
}

void ezLCD3::light(int i)
{
    if (i >= 0 && i <= 100) {
        sendInt(Light);
        putc(' ');
        sendInt( i );
        putc('\r');
        waitForCR();
    }
}
/*
int ezLCD3::getMaxX( void )
{
    sendInt(Xmax);
    putc('\r');
    waitForCR();

}
int ezLCD3::getMaxY( void )
{
    sendInt(Ymax);
    putc('\r');
    waitForCR();
}

void ezLCD3::string( int ID ) {

}

void ezLCD3::string( int ID , char *str) {

}
*/
void ezLCD3::reverseMode()
{
    putc(0x7c);
    putc(0x12);
}

void ezLCD3::resolution(int type)
{
    switch (type) {
        case LCD_128x64 :
            resolution(128, 64);
            break;
        case LCD_160x128 :
            resolution(160, 128);
            break;
    }
}

void ezLCD3::print( char *str )
{
    unsigned char c;
    sendInt(Print);
    _ser.putc(' ');
    _ser.putc('\"');
    while( (c = *str++) )
        _ser.putc(c);
    _ser.putc('\"');
    _ser.putc('\r');
    waitForCR();
}

void ezLCD3::resolution(int x, int y)
{
    _xMax = x;
    _yMax = y;
}

int ezLCD3::_putc( int c)
{
    _ser.putc('2');
    _ser.putc('5');
    _ser.putc(' ');
    _ser.putc('\"');
    _ser.putc(c);
    _ser.putc('\"');
    _ser.putc('\r');
    waitForCR();
    return (c);
}

int ezLCD3::_getc(void)
{
    char r = 0;
    return(r);
}

int ezLCD3::putc ( int c )
{
    return(_ser.putc(c));
}

int ezLCD3::getc (void)
{
    return(_ser.getc());
}

void ezLCD3::lcdbaud(int b)
{
    if (b > 0 && b < 7) {
        putc(0x7c);
        putc(0x07);
        putc(b+'0');
    }
}