Dezibot 4
Display.cpp
Go to the documentation of this file.
1 
11 #include "Display.h"
12 #include "CharTable.h"
13 #include "Wire.h"
14 
15 
16 void Display::begin(void){
17  //set Mux Ratio
19  sendDisplayCMD(0x3f);
21  sendDisplayCMD(0x00);
24  /*which pixels are bright: normal = 1s are bright, inverese= 0s are bright*/
26 
28  sendDisplayCMD(0x80);
29 
31  sendDisplayCMD(0x14);
33  this->clear();
34  return;
35 };
36 
37 void Display::sendDisplayCMD(uint8_t cmd){
38  Wire.beginTransmission(DisplayAdress);
39  Wire.write(cmd_byte);
40  Wire.write(cmd);
41  Wire.endTransmission();
42 };
43 
44 void Display::clear(void){
46  sendDisplayCMD(0x00); //horizontal
48  sendDisplayCMD(0x00);
49  sendDisplayCMD(0x7f);
51  sendDisplayCMD(0x00);
52  sendDisplayCMD(0x07);
53  for (int j=0;j<64;j++){
54  Wire.beginTransmission(DisplayAdress);
55  Wire.write(data_byte);
56  for(int i = 0;i<16;i++){
57  Wire.write(0x00);
58  }
59  Wire.endTransmission();
60  }
61  this -> charsOnCurrLine = 0;
62  this -> currLine = 0;
63  return;
64 };
65 
66 void Display::updateLine(uint charAmount)
67 {
68  if(charAmount+this->charsOnCurrLine>16)
69  {
70  this->currLine = (this->currLine+((charAmount+this->charsOnCurrLine)/16))%8;
71  this->charsOnCurrLine = (charAmount+this->charsOnCurrLine)%17; //there can be 0-16 chars on one line, so the 17th char is on next line
72  }
73  else
74  {
75  this->charsOnCurrLine = charAmount+this->charsOnCurrLine;
76  }
77 };
78 
79 void Display::print(char *value){
80  char *nextchar;
81  /* write data to the buffer */
82  while(value && *value != '\0') //check if pointer is still valid and string is not terminated
83  {
84  //check if next character is a linebreak
85  if(*value=='\n')
86  {
87  //fill the current line with blanks
88  while(this->charsOnCurrLine<16)
89  {
90  updateLine(1);
91  Wire.beginTransmission(DisplayAdress);
92  for(int i = 0;i<9;i++){
93  Wire.write(font8x8_colwise[0][i]);
94  }
95  Wire.endTransmission();
96  }
97  //make the linebreak
98  this->currLine=currLine+1;
99  this->charsOnCurrLine=0;
100  }
101  else
102  {
103  updateLine(1);
104  Wire.beginTransmission(DisplayAdress);
105  //print the character
106  for(int i = 0;i<9;i++){
107  Wire.write(font8x8_colwise[*value][i]);
108  }
109  Wire.endTransmission();
110  }
111  value++;
112  }
113 };
114 
115 char Display::stringToCharArray(String value) {
116  const int len = value.length() + 1; // +1 for the null terminator
117  char msgBuffer[len]; // Create a buffer of the appropriate length
118 
119  value.toCharArray(msgBuffer, len); // Copy the string into the buffer, including the null terminator
120 
121  return *msgBuffer;
122 }
123 
124 void Display::print(String value){
125  const int len = value.length() + 1; // +1 for the null terminator
126  char msgBuffer[len]; // Create a buffer of the appropriate length
127  value.toCharArray(msgBuffer, len);
128 
129  this->print(msgBuffer);
130 };
131 
132 void Display::println(String value){
133  const int len = value.length() + 1; // +1 for the null terminator
134  char msgBuffer[len]; // Create a buffer of the appropriate length
135  value.toCharArray(msgBuffer, len);
136 
137  this->println(msgBuffer);
138 };
139 
140 void Display::print(int value){
141  char cstr[16];
142 
143  this->print(itoa(value, cstr, 10));
144 };
145 
146 void Display::println(int value){
147  char cstr[16];
148 
149  this->println(itoa(value, cstr, 10));
150 };
151 
152 void Display::println(char *value){
153  this ->print(value);
154  this->print("\n");
155 };
156 
158  if(this->orientationFlipped){
161  } else{
164  }
165  this->orientationFlipped = !this->orientationFlipped;
166 };
167 
169  if(this->colorInverted){
171  } else {
173  }
174  this->colorInverted = !this->colorInverted;
175 };
colRange
#define colRange
Definition: DisplayCMDs.h:21
stopCompleteOn
#define stopCompleteOn
Definition: DisplayCMDs.h:13
setSegmentMap
#define setSegmentMap
Definition: DisplayCMDs.h:6
setComDirectionFlipped
#define setComDirectionFlipped
Definition: DisplayCMDs.h:9
setStartLine
#define setStartLine
Definition: DisplayCMDs.h:5
setOscFreq
#define setOscFreq
Definition: DisplayCMDs.h:16
setComDirectionNormal
#define setComDirectionNormal
Definition: DisplayCMDs.h:8
Display::updateLine
void updateLine(uint charAmount)
should be called whenever characters where printed to the display. Updates the data of the class to h...
Definition: Display.cpp:66
pageRange
#define pageRange
Definition: DisplayCMDs.h:22
Display::print
void print(char *value)
prints the passed string right behind the current displaycontent the sequence "\n" can be used to mak...
Definition: Display.cpp:79
setInverseMode
#define setInverseMode
Definition: DisplayCMDs.h:15
setNormalMode
#define setNormalMode
Definition: DisplayCMDs.h:14
Display::currLine
uint8_t currLine
Definition: Display.h:24
Display::clear
void clear(void)
delets all content from the display, resets the linecounter, new print will start at the top left....
Definition: Display.cpp:44
Display::sendDisplayCMD
void sendDisplayCMD(uint8_t cmd)
sends the passed cmd to the display, cmd_byte is added as prefix by the function
Definition: Display.cpp:37
font8x8_colwise
const char font8x8_colwise[128][9]
First index specifies the index, where index equals the ascii encoding unprintable characters are enc...
Definition: CharTable.h:20
Display.h
setOffset
#define setOffset
Definition: DisplayCMDs.h:4
addressingMode
#define addressingMode
Definition: DisplayCMDs.h:20
Display::println
void println(char *value)
same as the print method, but after the string a line break is inserted
Definition: Display.cpp:152
Display::charsOnCurrLine
uint8_t charsOnCurrLine
Definition: Display.h:21
muxRatio
#define muxRatio
Definition: DisplayCMDs.h:3
Display::colorInverted
bool colorInverted
Definition: Display.h:30
Display::stringToCharArray
char stringToCharArray(String value)
string to char
Definition: Display.cpp:115
Display::begin
void begin(void)
initializes the display datastructures and sents the required cmds to start the display....
Definition: Display.cpp:16
Display::flipOrientation
void flipOrientation(void)
flips the horizontal orientation of all content on the display
Definition: Display.cpp:157
Display::orientationFlipped
bool orientationFlipped
Definition: Display.h:27
setChargePump
#define setChargePump
Definition: DisplayCMDs.h:17
CharTable.h
LookUpTable for 8x8 Pixel Characters for an SSD1306 Display.
Display::invertColor
void invertColor(void)
inverts the pixelcolors, so pixels on will be set to off and currently off pixels will be turned off....
Definition: Display.cpp:168
setSegmentReMap
#define setSegmentReMap
Definition: DisplayCMDs.h:7
data_byte
#define data_byte
Definition: DisplayCMDs.h:2
cmd_byte
#define cmd_byte
Definition: DisplayCMDs.h:1
activateDisplay
#define activateDisplay
Definition: DisplayCMDs.h:18