RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi::LCD1602 Class Reference

Standard 16x2 character LCD screen (LCD1602) driven over I2C. More...

#include <LCD1602.h>

Inheritance diagram for RumPi::LCD1602:
[legend]
Collaboration diagram for RumPi::LCD1602:
[legend]

Public Member Functions

 LCD1602 (const LCD1602 &)=delete
 
LCD1602operator= (const LCD1602 &)=delete
 
 LCD1602 (const int LCDAddr)
 Builds an LCD1602 at the given I2C address, opening the i2c device and enabling the backlight. More...
 
 LCD1602 (const int LCDAddr, const int fileDescriptor)
 Builds an LCD1602 at the given I2C address using an already-open file descriptor. More...
 
 LCD1602 (const int LCDAddr, const int fileDescriptor, const int blen)
 Builds an LCD1602 at the given I2C address using an already-open file descriptor and explicit backlight setting. More...
 
virtual ~LCD1602 ()
 Destroys the screen, turning it off first. More...
 
virtual void TurnOn () override
 Initializes the LCD (8-bit then 4-bit mode, 2 lines, display on without cursor blink) and clears the screen. More...
 
virtual void TurnOff () override
 Turns the display off. More...
 
virtual void ProcessRawValues () override
 No-op: the LCD is an output device with no raw values to process. More...
 
virtual std::string ToString () const override
 Serializes the LCD's I2C address, file descriptor, and backlight flag to a string. More...
 
void ClearScreen ()
 Clears the screen. More...
 
void WriteToScreen (int &x, int &y, const char data[])
 Writes a string starting at the given cursor position, clamping x to 0-15 and y to 0-1. More...
 
- Public Member Functions inherited from RumPi::BaseComponent
 BaseComponent ()
 Builds a base component with an unknown type and an empty name. More...
 
virtual ~BaseComponent ()
 Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More...
 
virtual void TurnOn ()=0
 Turns the component on (e.g. More...
 
virtual void TurnOff ()=0
 Turns the component off. More...
 
virtual std::string ToString () const =0
 Serializes the component's current readings to a string (usually JSON). More...
 
virtual void ProcessRawValues ()=0
 Reads and processes the component's latest raw values (called once per poll). More...
 
virtual EComponentType GetComponentType () const
 Gets the component's type. More...
 
const std::string & GetName () const
 Gets the component's unique per-instance name. More...
 
void SetName (const std::string &name)
 Sets the component's unique per-instance name. More...
 

Private Member Functions

void WriteWord (const int word)
 Writes a raw word to the LCD over I2C, setting or clearing the backlight bit according to the backlight flag. More...
 
void SendCommand (const int command)
 Sends a command byte to the LCD in two 4-bit nibbles, toggling the enable line for each. More...
 
void SendData (const int data)
 Sends a data byte to the LCD in two 4-bit nibbles, toggling the enable line for each. More...
 

Private Attributes

int myLCDAddress
 The LCD's I2C address. More...
 
int myFileDescriptor
 The open i2c device file descriptor. More...
 
bool myOwnsFileDescriptor
 True if this component opened (and must close) the fd; false if borrowed. More...
 
int myBLEN
 Backlight enable flag (1 = on). More...
 

Additional Inherited Members

- Static Public Member Functions inherited from RumPi::BaseComponent
static std::string ComponentTypeToString (const EComponentType theComponentTypeToConvert)
 Maps an EComponentType to its string name. More...
 
static EComponentType StringToComponentType (const std::string &theComponentTypeName)
 Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More...
 
- Protected Attributes inherited from RumPi::BaseComponent
EComponentType myComponentType
 The kind of component this is (set by each concrete subclass). More...
 
std::string myName
 A unique per-instance name, assigned when the component is added to the manager. More...
 

Detailed Description

Standard 16x2 character LCD screen (LCD1602) driven over I2C.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ LCD1602() [1/4]

RumPi::LCD1602::LCD1602 ( const LCD1602 )
delete

◆ LCD1602() [2/4]

RumPi::LCD1602::LCD1602 ( const int  LCDAddr)

Builds an LCD1602 at the given I2C address, opening the i2c device and enabling the backlight.

Author
Eddie O'Hagan
Date
8/13/2026
LCD1602 screen(0x27);
LCD1602(const LCD1602 &)=delete
Parameters
[in]LCDAddrThe LCD's I2C address.

◆ LCD1602() [3/4]

RumPi::LCD1602::LCD1602 ( const int  LCDAddr,
const int  fileDescriptor 
)

Builds an LCD1602 at the given I2C address using an already-open file descriptor.

Author
Eddie O'Hagan
Date
8/13/2026
LCD1602 screen(0x27, existingFd);
Parameters
[in]LCDAddrThe LCD's I2C address.
[in]fileDescriptorAn already-open i2c device file descriptor.

◆ LCD1602() [4/4]

RumPi::LCD1602::LCD1602 ( const int  LCDAddr,
const int  fileDescriptor,
const int  blen 
)

Builds an LCD1602 at the given I2C address using an already-open file descriptor and explicit backlight setting.

Author
Eddie O'Hagan
Date
8/13/2026
LCD1602 screen(0x27, existingFd, 1);
Parameters
[in]LCDAddrThe LCD's I2C address.
[in]fileDescriptorAn already-open i2c device file descriptor.
[in]blenThe backlight enable flag (1 = on).

◆ ~LCD1602()

RumPi::LCD1602::~LCD1602 ( )
virtual

Destroys the screen, turning it off first.

Author
Eddie O'Hagan
Date
8/13/2026
LCD1602* screen = new LCD1602(0x27);
delete screen;

Member Function Documentation

◆ ClearScreen()

void RumPi::LCD1602::ClearScreen ( )

Clears the screen.

Author
Eddie O'Hagan
Date
8/13/2026
screen.ClearScreen();

◆ operator=()

LCD1602 & RumPi::LCD1602::operator= ( const LCD1602 )
delete

◆ ProcessRawValues()

void RumPi::LCD1602::ProcessRawValues ( )
overridevirtual

No-op: the LCD is an output device with no raw values to process.

Author
Eddie O'Hagan
Date
8/13/2026
screen.ProcessRawValues();

Implements RumPi::BaseComponent.

◆ SendCommand()

void RumPi::LCD1602::SendCommand ( const int  command)
private

Sends a command byte to the LCD in two 4-bit nibbles, toggling the enable line for each.

Author
Eddie O'Hagan
Date
8/13/2026
void SendCommand(const int command)
Sends a command byte to the LCD in two 4-bit nibbles, toggling the enable line for each.
Definition: LCD1602.cpp:148
Parameters
[in]commandThe command byte to send.

◆ SendData()

void RumPi::LCD1602::SendData ( const int  data)
private

Sends a data byte to the LCD in two 4-bit nibbles, toggling the enable line for each.

Author
Eddie O'Hagan
Date
8/13/2026
SendData('A');
void SendData(const int data)
Sends a data byte to the LCD in two 4-bit nibbles, toggling the enable line for each.
Definition: LCD1602.cpp:183
Parameters
[in]dataThe data byte to send.

◆ ToString()

std::string RumPi::LCD1602::ToString ( ) const
overridevirtual

Serializes the LCD's I2C address, file descriptor, and backlight flag to a string.

Author
Eddie O'Hagan
Date
8/13/2026
std::string data = screen.ToString();
Returns
A string describing the LCD.

Implements RumPi::BaseComponent.

◆ TurnOff()

void RumPi::LCD1602::TurnOff ( )
overridevirtual

Turns the display off.

Author
Eddie O'Hagan
Date
8/13/2026
screen.TurnOff();

Implements RumPi::BaseComponent.

◆ TurnOn()

void RumPi::LCD1602::TurnOn ( )
overridevirtual

Initializes the LCD (8-bit then 4-bit mode, 2 lines, display on without cursor blink) and clears the screen.

Author
Eddie O'Hagan
Date
8/13/2026
screen.TurnOn();

Implements RumPi::BaseComponent.

◆ WriteToScreen()

void RumPi::LCD1602::WriteToScreen ( int &  x,
int &  y,
const char  data[] 
)

Writes a string starting at the given cursor position, clamping x to 0-15 and y to 0-1.

Author
Eddie O'Hagan
Date
8/13/2026
int x = 0;
int y = 0;
screen.WriteToScreen(x, y, "Hello");
Parameters
[in,out]xThe column (clamped to 0-15).
[in,out]yThe row (clamped to 0-1).
[in]dataThe null-terminated string to write.

◆ WriteWord()

void RumPi::LCD1602::WriteWord ( const int  word)
private

Writes a raw word to the LCD over I2C, setting or clearing the backlight bit according to the backlight flag.

Author
Eddie O'Hagan
Date
8/13/2026
WriteWord(0x08);
void WriteWord(const int word)
Writes a raw word to the LCD over I2C, setting or clearing the backlight bit according to the backlig...
Definition: LCD1602.cpp:120
Parameters
[in]wordThe word to write.

Member Data Documentation

◆ myBLEN

int RumPi::LCD1602::myBLEN
private

Backlight enable flag (1 = on).

◆ myFileDescriptor

int RumPi::LCD1602::myFileDescriptor
private

The open i2c device file descriptor.

◆ myLCDAddress

int RumPi::LCD1602::myLCDAddress
private

The LCD's I2C address.

◆ myOwnsFileDescriptor

bool RumPi::LCD1602::myOwnsFileDescriptor
private

True if this component opened (and must close) the fd; false if borrowed.


The documentation for this class was generated from the following files: