RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
LCD1602.h
Go to the documentation of this file.
1#pragma once
2#include <stdio.h>
3#include <iostream>
4#include <wiringPi.h>
5#include <wiringPiI2C.h>
6#include <string.h>
7#include "BaseComponent.h"
8
9namespace RumPi
10{
17 class LCD1602 : public BaseComponent
18 {
19 public:
20 //Owns the i2c fd when it opened it (ctor 1) and the destructor closes it, so a copy would double-close. Non-copyable.
21 LCD1602(const LCD1602&) = delete;
22 LCD1602& operator=(const LCD1602&) = delete;
23
24 private:
28 int myBLEN;
29
42 void WriteWord(const int word);
43
56 void SendCommand(const int command);
57
70 void SendData(const int data);
71
72 public:
85 LCD1602(const int LCDAddr);
86
100 LCD1602(const int LCDAddr, const int fileDescriptor);
101
116 LCD1602(const int LCDAddr, const int fileDescriptor, const int blen);
117
129 virtual ~LCD1602();
130
141 virtual void TurnOn() override;
142
153 virtual void TurnOff() override;
154
165 virtual void ProcessRawValues() override;
166
179 virtual std::string ToString() const override;
180
191 void ClearScreen();
192
209 void WriteToScreen(int& x, int& y, const char data[]);
210
211 };
212} // namespace RumPi
Abstract base class for every component (sensor, actuator, etc.) the library manages.
Definition: BaseComponent.h:60
Standard 16x2 character LCD screen (LCD1602) driven over I2C.
Definition: LCD1602.h:18
int myBLEN
Backlight enable flag (1 = on).
Definition: LCD1602.h:28
void ClearScreen()
Clears the screen.
Definition: LCD1602.cpp:282
LCD1602(const LCD1602 &)=delete
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
virtual ~LCD1602()
Destroys the screen, turning it off first.
Definition: LCD1602.cpp:97
int myLCDAddress
The LCD's I2C address.
Definition: LCD1602.h:25
virtual void TurnOn() override
Initializes the LCD (8-bit then 4-bit mode, 2 lines, display on without cursor blink) and clears the ...
Definition: LCD1602.cpp:216
LCD1602 & operator=(const LCD1602 &)=delete
int myFileDescriptor
The open i2c device file descriptor.
Definition: LCD1602.h:26
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
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
virtual void ProcessRawValues() override
No-op: the LCD is an output device with no raw values to process.
Definition: LCD1602.cpp:267
bool myOwnsFileDescriptor
True if this component opened (and must close) the fd; false if borrowed.
Definition: LCD1602.h:27
virtual std::string ToString() const override
Serializes the LCD's I2C address, file descriptor, and backlight flag to a string.
Definition: LCD1602.cpp:352
virtual void TurnOff() override
Turns the display off.
Definition: LCD1602.cpp:250
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.
Definition: LCD1602.cpp:304
RumPi is the library's top-level facade.
Definition: AlertManager.h:6