added user-visible functions

git-svn-id: svn://anubis/misc/parport-2x20vfd@112 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
josh 2009-05-03 21:23:54 +00:00
parent dcba2c00fe
commit 2fdd2b821b
2 changed files with 76 additions and 0 deletions

55
VFD.cc
View File

@ -49,6 +49,9 @@ bool VFD::connect(const std::string & parport)
} }
else else
{ {
usleep(INIT_DELAY);
sendNibble(0, 0x2); /* set 4-bit mode */
sendByte(1, 0); /* set brightness */
return true; return true;
} }
@ -97,3 +100,55 @@ void VFD::sendByte(unsigned char rs, unsigned char dat)
sendNibble(rs, (dat >> 4) & 0xF); sendNibble(rs, (dat >> 4) & 0xF);
sendNibble(rs, dat & 0xF); sendNibble(rs, dat & 0xF);
} }
void VFD::displayClear()
{
sendByte(0, 0x1);
usleep(INIT_DELAY);
}
void VFD::cursorHome()
{
sendByte(0, 0x2);
}
void VFD::entryModeSet(unsigned char address_direction, /* LEFT|RIGHT */
unsigned char display_shift) /* ON|OFF */
{
sendByte(0, 0x4
| ((address_direction & 0x1) << 1)
| (display_shift & 0x1) );
}
void VFD::setDisplay(unsigned char display, /* ON|OFF */
unsigned char cursor, /* ON|OFF */
unsigned char cursor_blink) /* ON|OFF */
{
sendByte(0, 0x8
| ((display & 0x1) << 2)
| ((cursor & 0x1) << 1)
| (cursor_blink & 0x1) );
}
void VFD::shift(unsigned char shift_display, /* ON|OFF */
unsigned char direction) /* LEFT|RIGHT */
{
sendByte(0, 0x10
| ((shift_display & 0x1) << 3)
| ((direction & 0x1) << 2) );
}
void VFD::setCGAddress(unsigned char address)
{
sendByte(0, 0x40 | (address & 0x3F));
}
void VFD::setAddress(unsigned char address)
{
sendByte(0, 0x80 | (address & 0x7F));
}
void VFD::writeData(unsigned char data)
{
sendByte(1, data);
}

21
VFD.h
View File

@ -32,10 +32,30 @@
class VFD class VFD
{ {
public: public:
static const unsigned char SHIFT_CURSOR = 0;
static const unsigned char SHIFT_DISPLAY = 1;
static const unsigned char LEFT = 0;
static const unsigned char RIGHT = 1;
static const unsigned char OFF = 0;
static const unsigned char ON = 1;
VFD(); VFD();
bool connect(const std::string & parport = "/dev/parport0"); bool connect(const std::string & parport = "/dev/parport0");
void disconnect(); void disconnect();
void displayClear();
void cursorHome();
void entryModeSet(unsigned char address_direction, /* LEFT|RIGHT */
unsigned char display_shift); /* ON|OFF */
void setDisplay(unsigned char display, /* ON|OFF */
unsigned char cursor, /* ON|OFF */
unsigned char cursor_blink); /* ON|OFF */
void shift(unsigned char shift_display, /* ON|OFF */
unsigned char direction); /* LEFT|RIGHT */
void setCGAddress(unsigned char address);
void setAddress(unsigned char address);
void writeData(unsigned char data);
protected: protected:
static const unsigned char RW_WRITE = 0; static const unsigned char RW_WRITE = 0;
static const unsigned char RW_READ = 1; static const unsigned char RW_READ = 1;
@ -47,6 +67,7 @@ class VFD
static const unsigned char PP_OFFSET_RW = 1; static const unsigned char PP_OFFSET_RW = 1;
static const unsigned char PP_OFFSET_E = 2; static const unsigned char PP_OFFSET_E = 2;
static const unsigned char PP_OFFSET_DATA = 3; static const unsigned char PP_OFFSET_DATA = 3;
static const int INIT_DELAY = 2400;
void sendByte(unsigned char rs, unsigned char dat); void sendByte(unsigned char rs, unsigned char dat);
void sendNibble(unsigned char rs, unsigned char dat); void sendNibble(unsigned char rs, unsigned char dat);