From c0c55edfecf1ae872f6ced4085f174bb3fe52d24 Mon Sep 17 00:00:00 2001 From: josh Date: Sun, 3 May 2009 23:14:54 +0000 Subject: [PATCH] added VFD::write(), VFD destructor, and driver code git-svn-id: svn://anubis/misc/parport-2x20vfd@113 bd8a9e45-a331-0410-811e-c64571078777 --- VFD.cc | 14 ++++++++++++++ VFD.h | 4 ++++ driver.cc | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/VFD.cc b/VFD.cc index 06d990c..b31355c 100644 --- a/VFD.cc +++ b/VFD.cc @@ -23,6 +23,12 @@ VFD::VFD() m_ppfd = -1; } +VFD::~VFD() +{ + if (m_ppfd >= 0) + disconnect(); +} + bool VFD::connect(const std::string & parport) { const int mode = IEEE1284_MODE_BYTE; @@ -152,3 +158,11 @@ void VFD::writeData(unsigned char data) { sendByte(1, data); } + +void VFD::write(const std::string & str) +{ + for (const char * chr = str.c_str(); *chr; chr++) + { + writeData(*chr); + } +} diff --git a/VFD.h b/VFD.h index 2851f5c..172a63f 100644 --- a/VFD.h +++ b/VFD.h @@ -38,8 +38,11 @@ class VFD static const unsigned char RIGHT = 1; static const unsigned char OFF = 0; static const unsigned char ON = 1; + static const unsigned char ADDRESS_LINE1 = 0x80; + static const unsigned char ADDRESS_LINE2 = 0xC0; VFD(); + ~VFD(); bool connect(const std::string & parport = "/dev/parport0"); void disconnect(); @@ -55,6 +58,7 @@ class VFD void setCGAddress(unsigned char address); void setAddress(unsigned char address); void writeData(unsigned char data); + void write(const std::string & str); protected: static const unsigned char RW_WRITE = 0; diff --git a/driver.cc b/driver.cc index 4c212be..189ed64 100644 --- a/driver.cc +++ b/driver.cc @@ -8,5 +8,13 @@ int main(int argc, char ** argv) { 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; }