eBoard ๐Ÿ‰  โ‘ โ‘งโ‘จ
Written for SIA 2017/2018
eagle_LCD.h
Go to the documentation of this file.
1 #ifndef EAGLE_EBOARD_HELPLIB_LCD
2 #define EAGLE_EBOARD_HELPLIB_LCD
3 
4  PROGMEM const byte basicFont[][8] = {
5  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
6  {0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00},
7  {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},
8  {0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00},
9  {0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00},
10  {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},
11  {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},
12  {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
13  {0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
14  {0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
15  {0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
16  {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
17  {0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
18  {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
19  {0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
20  {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},
21  {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},
22  {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},
23  {0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
24  {0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
25  {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
26  {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
27  {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
28  {0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
29  {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
30  {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
31  {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
32  {0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
33  {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
34  {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
35  {0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
36  {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
37  {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
38  {0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
39  {0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
40  {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
41  {0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
42  {0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
43  {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
44  {0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
45  {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
46  {0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00},
47  {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
48  {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
49  {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},
50  {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
51  {0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
52  {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},
53  {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},
54  {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
55  {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
56  {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},
57  {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
58  {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},
59  {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
60  {0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00},
61  {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
62  {0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
63  {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
64  {0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
65  {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
66  {0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
67  {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
68  {0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
69  {0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
70  {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
71  {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
72  {0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
73  {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
74  {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
75  {0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
76  {0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
77  {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
78  {0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
79  {0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
80  {0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
81  {0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
82  {0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
83  {0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
84  {0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
85  {0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
86  {0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
87  {0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
88  {0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
89  {0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
90  {0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00},
91  {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
92  {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
93  {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
94  {0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
95  {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
96  {0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
97  {0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
98  {0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
99  {0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
100  {0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
101  };
102 
103  //Definition of OLED Constants
105  #define LCD_COMMAND_MODE 0x80
106  #define LCD_DATA_MODE 0x40
108  #define LCD_COMMAND_DISPLAY_OFF 0xAE
110  #define LCD_COMMAND_DISPLAY_ON 0xAF
112  #define LCD_COMMAND_BLACK_BACKGROUND 0xA6
114  #define LCD_COMMAND_WHITE_BACKGROUND 0xA7
116  #define LCD_COMMAND_SET_BRIGHTNESS 0x81
118  #define LCD_PAGE_ADDRESSING 0x02
120  #define LCD_HORIZONTAL_ADDRESSING 0x00
122  //The regulator
124  #define LCD_COMMAND_CHARGE_PUMP_SETTING 0x8d
125  #define LCD_COMMAND_CHARGE_PUMP_ENABLE 0x14
127 
128  #ifndef LCD_WIDTH
129  #define LCD_WIDTH 128
131  #endif
132  #ifndef LCD_HEIGHT
133  #define LCD_HEIGHT 64
135  #endif
136 
177  struct LCD {
178  #if EBOARD_NANO == 0
179 
187  LCD(SoccerBoard &soccerBoard, optVAL_t id=0x3C);
188  #else
189  LCD(optVAL_t id=0x3C);
190  #endif
191 
205  inline bool changeID(optVAL_t newID = 0x3C);
216  inline bool clear(void);
222  inline void print(const char* data);
228  inline void print(int data);
236  inline void print(optVAL_t line, optVAL_t col, const char* data);
244  inline void print(optVAL_t line, optVAL_t col, int data);
253  inline void lightOn(void);
262  inline void lightOff(void);
273  inline bool reset(void);
274 
275  //added features
288  inline bool init(void);
298  inline void drawBitmap(const unsigned char *bitmap, byte posX, byte posY, byte hiX, byte hiY);
306  inline void changeMode(bool newMode = true);
320  inline bool setCursor(byte posX = 0x0, byte posY = 0x0);
333  inline bool changeBrightness (byte val = 0x64);
343  inline void changeBackground(bool newBackground = false);
346  private:
350  byte pX;
353  byte pY;
355  bool _cI;
356 
363  inline void s2Cmd(optVAL_t o, optVAL_t t);
376  inline bool s1Cmd(optVAL_t o);
382  inline void s1Dat(optVAL_t o);
383 
384  };
385 
387  #if EBOARD_NANO == 0x0
388  LCD::LCD(SoccerBoard &soccerBoard, optVAL_t id) {
389  this->_cI = false;
390  this->ID = id;
391  //this->init();
392  }
393  #else
394  LCD::LCD( optVAL_t id) {
395  this->_cI = false;
396  this->ID = id;
397  //this->init();
398  }
399  #endif
400  inline bool LCD::changeID(optVAL_t newID) {
401  this->ID = newID;
402  return this->init();
403  }
404  inline bool LCD::clear(void) {
405  if(!this->_cI) this->init();
406  for(byte i = 0; i < 8; i++){
407  //maybe *8
408  setCursor(0,i);
409 
410  for (byte j = 0; j < 128; j++)
411  this->s1Dat(0);
412  }
413  return setCursor(0,0);
414  }
415  void LCD::print(optVAL_t line, optVAL_t col, const char *data) {
416  if(!this->_cI) this->init();
417  byte i = 0x0;
418  if(col < ((LCD_WIDTH-1)/8.0) && line < ((LCD_HEIGHT-1)/8.0)) {
419  setCursor(col,line);
420  }
421  while(data[i] && (pX*8) < LCD_WIDTH){
422  //Serial.print(data[i]); Serial.print(" ");
423  //Serial.print(i); Serial.print(" "); Serial.print(pX); Serial.print(" ");
424  //Serial.println(this->pY);
425  if(data[i] == '\n' || this->pX >= LCD_WIDTH) {
426  setCursor(0,(pY+1));
427  } else if (this->pY >= LCD_HEIGHT){
428  setCursor(0,0);
429  }
430  if(data[i] < 32 || data[i] > 127){ i++; continue;}
431  for (byte j = 0; j < 8; j++){
432  this->s1Dat(pgm_read_byte(&basicFont[data[i]-32][j]));
433  }
434  i++;this->pX++;
435  }
436  }
437  void LCD::print(optVAL_t line, optVAL_t col, int data){
438  char buffer[11] = "";
439  itoa(data,buffer,10);
440  this->print(line,col,buffer);
441  }
442  inline void LCD::lightOn(void) {
443  this->changeBrightness(255);
444  }
445  inline void LCD::lightOff(void) {
446  this->changeBrightness(0);
447  }
448  inline bool LCD::reset(void) {
449  return this->clear();
450  }
451  inline void LCD::print(int data) {this->print(255,255,data);}
452  inline void LCD::print(const char* data) {this->print(255,255,data);}
453  inline bool LCD::init() {
454  #ifdef HIGHSPEED
455  TWBR = 0xC;
456  #endif
457  this->_cI = true;
459  this->changeMode(false);
460  this->changeBackground(false);
461  this->changeBrightness(255);
462  this->s2Cmd(0x20,LCD_PAGE_ADDRESSING);
463  this->changeMode(true);
464 
465  //this->print("eBoard \n written by \n EagleoutIce");
466  return this->clear();
467  }
468 
469  inline void LCD::drawBitmap(const unsigned char *bitmap, byte posX, byte posY, byte hiX, byte hiY){
470  if(!this->_cI) this->init();
471  setCursor(posX,posY);
472  byte col = 0x0;
473  for(int i = 0x0; i < (hiX * 8 * hiY); i++){
474  this->s1Dat(pgm_read_byte(&bitmap[i]));
475  if(++col == (hiX * 8)) {
476  col = 0x0;
477  setCursor(posX,++posY);
478  }
479  }
480  }
481  inline void LCD::changeMode(bool newMode) {
482  if(!this->_cI) this->init();
483  if(newMode) this->s1Cmd(LCD_COMMAND_DISPLAY_ON);
484  else this->s1Cmd(LCD_COMMAND_DISPLAY_OFF);
485  }
486  inline bool LCD::setCursor(byte posX, byte posY) {
487  if(!this->_cI) this->init();
488  this->s2Cmd((0x00 + (8 *posX & 0x0F)),(0x10 + ((8 * posX >> 4) & 0x0F))); //lower and higher address
489  this->pX = posX; this->pY = posY;
490  return this->s1Cmd(0xB0 + posY);
491  }
492 
493  inline bool LCD::changeBrightness(byte val) {
494  if(!this->_cI) this->init();
495  this->s2Cmd(0x81,val); //brightness mode
496  Wire.beginTransmission(this->ID);
497  return (Wire.endTransmission() == 0);
498  }
499  inline void LCD::changeBackground(bool newBackground) {
500  if(!this->_cI) this->init();
501  if(newBackground) this->s1Cmd(LCD_COMMAND_WHITE_BACKGROUND);
503  }
504 
505  inline void LCD::s2Cmd(optVAL_t o, optVAL_t t){
506  if(!this->_cI) this->init();
507  this->s1Cmd(o); this->s1Cmd(t);
508  }
509 
510  inline bool LCD::s1Cmd(optVAL_t C) {
511  if(!this->_cI) this->init();
512  Wire.beginTransmission(this->ID);
513  Wire.write(LCD_COMMAND_MODE); Wire.write(C);
514  return (Wire.endTransmission()==0);
515  }
516  inline void LCD::s1Dat(optVAL_t o){
517  if(!this->_cI) this->init();
518  Wire.beginTransmission(this->ID);
519  Wire.write(LCD_DATA_MODE); Wire.write(o);
520  Wire.endTransmission();
521  }
523 #endif
[COPY&PASTE] This is the SoccerBoard ghost struct :D
#define LCD_COMMAND_CHARGE_PUMP_ENABLE
Definition: eagle_LCD.h:126
byte pY
posY
Definition: eagle_LCD.h:353
void s2Cmd(optVAL_t o, optVAL_t t)
this function will execute two cmd sends without starting and without ending the transmission ...
#define LCD_COMMAND_MODE
Definition: eagle_LCD.h:105
bool _cI
called_guard
Definition: eagle_LCD.h:355
bool reset(void)
clears the screen
void changeMode(bool newMode=true)
enable or disable the display
bool init(void)
initializes the Display called by:
#define LCD_COMMAND_DISPLAY_ON
Definition: eagle_LCD.h:111
byte pX
the addressing mode (page/horizontal)
Definition: eagle_LCD.h:351
#define LCD_COMMAND_CHARGE_PUMP_SETTING
Definition: eagle_LCD.h:124
#define LCD_COMMAND_BLACK_BACKGROUND
Definition: eagle_LCD.h:113
bool setCursor(byte posX=0x0, byte posY=0x0)
set the position of the cursor
LCD(SoccerBoard &soccerBoard, optVAL_t id=0x3C)
The constructor.
void changeBackground(bool newBackground=false)
changes the background of the display
optVAL_t ID
ID of the Display.
Definition: eagle_LCD.h:345
#define LCD_WIDTH
Definition: eagle_LCD.h:130
#define LCD_COMMAND_DISPLAY_OFF
Definition: eagle_LCD.h:109
void s1Dat(optVAL_t o)
this function will execute one dat send without starting and without ending the transmission ...
#define LCD_COMMAND_WHITE_BACKGROUND
Definition: eagle_LCD.h:115
void lightOn(void)
enable the backlight
void lightOff(void)
disable the backlight
bool clear(void)
clears the LCD
bool s1Cmd(optVAL_t o)
this function will execute one cmd send without starting and without ending the transmission ...
TwoWire Wire
this is the well-known Arduino Wire Interface, just a little bit &#39;modified&#39; ;P
bool changeBrightness(byte val=0x64)
changes the brightness of the display
bool changeID(optVAL_t newID=0x3C)
changes the address of the LCD display talked to
PROGMEM const byte basicFont[][8]
Definition: eagle_LCD.h:4
int optVAL_t
Definition: eBoard.h:196
void print(const char *data)
prints a string to the display
void drawBitmap(const unsigned char *bitmap, byte posX, byte posY, byte hiX, byte hiY)
draws a bitmap representet as an array of bytes
#define LCD_DATA_MODE
Definition: eagle_LCD.h:107
#define LCD_HEIGHT
Definition: eagle_LCD.h:134
[I2C] [LCD] This is used to add support for OLED displays connected to the &#39;SoccerBoard&#39; ...
Definition: eagle_LCD.h:177
#define LCD_PAGE_ADDRESSING
Definition: eagle_LCD.h:119