diff --git a/VFD.cc b/VFD.cc index 1ea06a4..0d0ab29 100644 --- a/VFD.cc +++ b/VFD.cc @@ -69,3 +69,31 @@ void VFD::disconnect() m_ppfd = -1; } } + +void VFD::setPPLines(unsigned char bits) +{ + if (m_ppfd >= 0) + { + ioctl(m_ppfd, PPWDATA, &bits); + } +} + +void VFD::sendNibble(unsigned char rs, unsigned char dat) +{ + setPPLines( (rs << PP_OFFSET_RS) + | (E_DISABLE << PP_OFFSET_E) + | (RW_WRITE << PP_OFFSET_RW) + | ((dat & 0xF) << PP_OFFSET_DATA) ); + usleep(1); + setPPLines( (rs << PP_OFFSET_RS) + | (E_ENABLE << PP_OFFSET_E) + | (RW_WRITE << PP_OFFSET_RW) + | ((dat & 0xF) << PP_OFFSET_DATA) ); + usleep(1); +} + +void VFD::sendByte(unsigned char rs, unsigned char dat) +{ + sendNibble(rs, (dat >> 4) & 0xF); + sendNibble(rs, dat & 0xF); +} diff --git a/VFD.h b/VFD.h index 6cde201..8d15bf4 100644 --- a/VFD.h +++ b/VFD.h @@ -32,17 +32,26 @@ class VFD { public: + VFD(); + bool connect(const std::string & parport = "/dev/parport0"); + void disconnect(); + + protected: static const unsigned char RW_WRITE = 0; static const unsigned char RW_READ = 1; static const unsigned char E_ENABLE = 0; static const unsigned char E_DISABLE = 1; static const unsigned char RS_COMMAND = 0; static const unsigned char RS_DATA = 1; - VFD(); - bool connect(const std::string & parport = "/dev/parport0"); - void disconnect(); + static const unsigned char PP_OFFSET_RS = 0; + static const unsigned char PP_OFFSET_RW = 1; + static const unsigned char PP_OFFSET_E = 2; + static const unsigned char PP_OFFSET_DATA = 3; + + void sendByte(unsigned char rs, unsigned char dat); + void sendNibble(unsigned char rs, unsigned char dat); + void setPPLines(unsigned char bits); - protected: int m_ppfd; /* parallel port file descriptor */ };