2 #include <MutilaDebug.h> 3 #include "CbOledDisplay.h" 4 #include "CheeseboardConfig.h" 9 U8G2_SSD1306_128X64_NONAME_F_SW_I2C(rotation, clock, data, reset)
15 CBOLED_CLASS::begin();
24 return CbOledDisplay.getStrWidth(buf);
29 return drawStr(x-getStrWidth(s), y, s);
34 _DB(F(
"CbOledDisplay::drawText: "));
40 setFont(CBOLED_MESSAGE_FONT);
42 const uint8_t maxLines = getDisplayHeight() / (CBOLED_MESSAGE_FONT_HEIGHT+CBOLED_MESSAGE_FONT_VSEP);
43 String lineText[maxLines];
45 int8_t lastSpace = -1;
46 for (uint8_t i=0; text[i]!=0; i++) {
47 if (text[i] ==
'\r' || text[i] ==
'\n' || text[i] ==
'|') {
49 if (lines >= maxLines-1) {
58 }
else if (getStrWidth(lineText[lines].c_str()) +
getCharWidth(text[i]) >= getDisplayWidth()) {
60 if (lines >= maxLines-1) {
66 lineText[lines+1] = lineText[lines].substring(lastSpace+1);
68 lineText[lines].remove(lastSpace);
74 lineText[lines] += text[i];
76 lastSpace = lineText[lines].length() - 1;
81 uint8_t blockHeight = (CBOLED_MESSAGE_FONT_HEIGHT+CBOLED_MESSAGE_FONT_VSEP)*lines;
85 vOffset = (getDisplayHeight() - blockHeight) / 2;
88 vOffset = getDisplayHeight() - blockHeight;
93 for (uint8_t i=0; i<lines; i++) {
94 uint8_t ypos = vOffset + CBOLED_MESSAGE_FONT_HEIGHT + ((CBOLED_MESSAGE_FONT_HEIGHT+CBOLED_MESSAGE_FONT_VSEP)*i);
98 xpos = (getDisplayWidth() - getStrWidth(lineText[i].c_str())) / 2;
101 xpos = getDisplayWidth() - getStrWidth(lineText[i].c_str());
104 drawStr(xpos, ypos, lineText[i].c_str());
u8g2_uint_t drawStrR(u8g2_uint_t x, u8g2_uint_t y, const char *s)
u8g2_uint_t getCharWidth(char c)
CbOledDisplayClass(const u8g2_cb_t *rotation, uint8_t clock, uint8_t data, uint8_t reset=U8X8_PIN_NONE)
void drawText(const char *text, char hAlign='L', char vAlign='M')