added VFD::write(), VFD destructor, and driver code

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

14
VFD.cc
View File

@ -23,6 +23,12 @@ VFD::VFD()
m_ppfd = -1; m_ppfd = -1;
} }
VFD::~VFD()
{
if (m_ppfd >= 0)
disconnect();
}
bool VFD::connect(const std::string & parport) bool VFD::connect(const std::string & parport)
{ {
const int mode = IEEE1284_MODE_BYTE; const int mode = IEEE1284_MODE_BYTE;
@ -152,3 +158,11 @@ void VFD::writeData(unsigned char data)
{ {
sendByte(1, data); sendByte(1, data);
} }
void VFD::write(const std::string & str)
{
for (const char * chr = str.c_str(); *chr; chr++)
{
writeData(*chr);
}
}

4
VFD.h
View File

@ -38,8 +38,11 @@ class VFD
static const unsigned char RIGHT = 1; static const unsigned char RIGHT = 1;
static const unsigned char OFF = 0; static const unsigned char OFF = 0;
static const unsigned char ON = 1; static const unsigned char ON = 1;
static const unsigned char ADDRESS_LINE1 = 0x80;
static const unsigned char ADDRESS_LINE2 = 0xC0;
VFD(); VFD();
~VFD();
bool connect(const std::string & parport = "/dev/parport0"); bool connect(const std::string & parport = "/dev/parport0");
void disconnect(); void disconnect();
@ -55,6 +58,7 @@ class VFD
void setCGAddress(unsigned char address); void setCGAddress(unsigned char address);
void setAddress(unsigned char address); void setAddress(unsigned char address);
void writeData(unsigned char data); void writeData(unsigned char data);
void write(const std::string & str);
protected: protected:
static const unsigned char RW_WRITE = 0; static const unsigned char RW_WRITE = 0;

View File

@ -8,5 +8,13 @@ int main(int argc, char ** argv)
{ {
cout << "Working on VFD module" << endl; cout << "Working on VFD module" << endl;
VFD vfd;
vfd.connect();
vfd.setDisplay(1, 0, 0);
vfd.setAddress(VFD::ADDRESS_LINE1);
vfd.write("Hi there!");
vfd.disconnect();
return 0; return 0;
} }