//YWROBOT
#ifndef LiquidCrystal_I2C_h
#define LiquidCrystal_I2C_h

#include <inttypes.h>
#include "Print.h" 
#include <Wire.h>

// commands
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCDFDisplayControl 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80

// flags for display entry mode
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00

// flags for display on/off control
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00

// flags for display/cursor shift
#define LCD_DISPLAYMOVE 0x08
#define LCD_CURSORMOVE 0x00
#define LCD_MOVERIGHT 0x04
#define LCD_MOVELEFT 0x00

// flags for function set
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00

// flags for backlight control
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00

#define En B00000100  // Enable bit
#define Rw B00000010  // Read/Write bit
#define Rs B00000001  // Register select bit

class CLCDisplay2004 : public Print {
  private:
  void init_priv();
  void send(uint8_t, uint8_t);
  void write4bits(uint8_t);
  void expanderWrite(uint8_t);
  void pulseEnable(uint8_t);
  uint8_t FAddress;
  uint8_t FDisplayFunction;
  uint8_t FDisplayControl;
  uint8_t FDisplayMode;
  uint8_t FLineCount;
  bool _oled = false;
  uint8_t FColCount;
  uint8_t FRowCount;
  uint8_t _backlightval;
  //
  public:
  CLCDisplay2004(uint8_t lcdFAddress, uint8_t lcdFColCount, uint8_t lcdFRowCount);
  void Open(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS );
  void Clear();
  void DisplayOff();
  void DisplayOn();
  void BlinkOff();
  void BlinkOn();
  void CursorHome();
  void CursorOff();
  void CursorOn();
  void ScrollDisplayLeft();
  void ScrollDisplayRight();
  void PrintLeft();
  void PrintRight();
  void LeftToRight();
  void RightToLeft();
  void ShiftIncrement();
  void ShiftDecrement();
  void BacklightOff();
  void BacklightOn();
  void AutoscrollOn();
  void AutoscrollOff(); 
  void CreateChar(uint8_t, uint8_t[]);
  void CreateChar(uint8_t location, const char *charmap);
  // Example: 	const char bell[8] PROGMEM = {B00100,B01110,B01110,B01110,B11111,B00000,B00100,B00000};  
  void SetCursor(uint8_t, uint8_t); 
#if defined(ARDUINO) && ARDUINO >= 100
  virtual size_t write(uint8_t);
#else
  virtual void write(uint8_t);
#endif
  void Command(uint8_t);
  void Init();
  void OledInit();
//
};

#endif
