Skip to content

Commit

Permalink
Change wire Interface so that you can user different Wire objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Haefele Frank (XC-AS/EDP5) committed Sep 4, 2024
1 parent 32cfb67 commit 71bbe2e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "LCD-I2C",
"version": "0.3.0",
"version": "1.0.0",
"repository":
{
"type": "git",
Expand Down
25 changes: 12 additions & 13 deletions src/LCD-I2C.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#include "LCD-I2C.h"
#include "Wire.h"
#include <LCD_Constants.h>

/**
* @brief function begin
*
* @param beginWire if true start I²C wire
*/
void LCD_I2C::begin(bool beginWire) {
if (beginWire)
Wire.begin();

// Clear i2c adapter
I2C_Write(0b00000000);
// Wait more than 40 ms after powerOn
delay(50);
InitializeLCD();
void LCD_I2C::begin(Twowire &wire) {
_wire = wire;

// Clear i2c adapter
I2C_Write(0b00000000);
// Wait more than 40 ms after powerOn
delay(50);
InitializeLCD();
}

/**
Expand Down Expand Up @@ -370,9 +369,9 @@ void LCD_I2C::writeCharCode(uint8_t code) {
* @param output data to write
*/
void LCD_I2C::I2C_Write(uint8_t output) {
Wire.beginTransmission(_address);
Wire.write(output);
Wire.endTransmission();
_wire.beginTransmission(_address);
_wire.write(output);
_wire.endTransmission();
}

/**
Expand Down
23 changes: 12 additions & 11 deletions src/LCD-I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _LCD_I2C_H_

#include "Arduino.h"
#include <LCD_Constants.h>
#include "Wire.h"

/*
This struct helps us constructing the I2C output based on data and control outputs.
Expand Down Expand Up @@ -46,7 +46,7 @@ class LCD_I2C : public Print {
LCD_I2C(uint8_t address, uint8_t columns = 16, uint8_t rows = 2)
: _address(address), _columnMax(--columns), _rowMax(--rows) {}

void begin(bool beginWire = true);
void begin(TwoWire &wire);
void backlight();
void backlightOff();

Expand All @@ -72,16 +72,17 @@ class LCD_I2C : public Print {


private:
uint8_t _address;
uint8_t _columnMax;
uint8_t _rowMax;
OutputState _output;
uint8_t _displayState = 0x00;
uint8_t _entryState = 0x00;
TwoWire &_wire;
uint8_t _address;
uint8_t _columnMax;
uint8_t _rowMax;
OutputState _output;
uint8_t _displayState = 0x00;
uint8_t _entryState = 0x00;

void InitializeLCD();
void I2C_Write(uint8_t output);
void LCD_Write(uint8_t output, bool initialization = false);
void InitializeLCD();
void I2C_Write(uint8_t output);
void LCD_Write(uint8_t output, bool initialization = false);
};

#endif

0 comments on commit 71bbe2e

Please sign in to comment.