mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-25 13:41:23 +01:00
Trim unwanted code
This commit is contained in:
parent
c5f81fdb87
commit
1ef22e0aea
@ -19,89 +19,24 @@
|
|||||||
*/
|
*/
|
||||||
#include "SSD1306Ascii.h"
|
#include "SSD1306Ascii.h"
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
uint8_t SSD1306Ascii::charWidth(uint8_t c) const {
|
|
||||||
if (!m_font) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
uint8_t first = readFontByte(m_font + FONT_FIRST_CHAR);
|
|
||||||
uint8_t count = readFontByte(m_font + FONT_CHAR_COUNT);
|
|
||||||
if (c < first || c >= (first + count)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (fontSize() > 1) {
|
|
||||||
// Proportional font.
|
|
||||||
return m_magFactor*readFontByte(m_font + FONT_WIDTH_TABLE + c - first);
|
|
||||||
}
|
|
||||||
// Fixed width font.
|
|
||||||
return m_magFactor*readFontByte(m_font + FONT_WIDTH);
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SSD1306Ascii::clear() {
|
void SSD1306Ascii::clear() {
|
||||||
#if INCLUDE_SCROLLING
|
|
||||||
m_pageOffset = 0;
|
|
||||||
setStartLine(0);
|
|
||||||
#endif // INCLUDE_SCROLLING
|
|
||||||
clear(0, displayWidth() - 1, 0 , displayRows() - 1);
|
clear(0, displayWidth() - 1, 0 , displayRows() - 1);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void SSD1306Ascii::clear(uint8_t c0, uint8_t c1, uint8_t r0, uint8_t r1) {
|
void SSD1306Ascii::clear(uint8_t c0, uint8_t c1, uint8_t r0, uint8_t r1) {
|
||||||
// Cancel skip character pixels.
|
// Ensure only rows on display will be cleared.
|
||||||
m_skip = 0;
|
|
||||||
|
|
||||||
// Insure only rows on display will be cleared.
|
|
||||||
if (r1 >= displayRows()) r1 = displayRows() - 1;
|
if (r1 >= displayRows()) r1 = displayRows() - 1;
|
||||||
|
|
||||||
for (uint8_t r = r0; r <= r1; r++) {
|
for (uint8_t r = r0; r <= r1; r++) {
|
||||||
setCursor(c0, r);
|
setCursor(c0, r);
|
||||||
for (uint8_t c = c0; c <= c1; c++) {
|
for (uint8_t c = c0; c <= c1; c++) {
|
||||||
// Insure clear() writes zero. result is (m_invertMask^m_invertMask).
|
// Ensure clear() writes zero. result is (m_invertMask^m_invertMask).
|
||||||
ssd1306WriteRamBuf(m_invertMask);
|
ssd1306WriteRamBuf(m_invertMask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setCursor(c0, r0);
|
setCursor(c0, r0);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void SSD1306Ascii::clearToEOL() {
|
|
||||||
clear(m_col, displayWidth() -1, m_row, m_row + fontRows() - 1);
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SSD1306Ascii::clearField(uint8_t col, uint8_t row, uint8_t n) {
|
|
||||||
clear(col, col + fieldWidth(n) - 1, row, row + fontRows() - 1);
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SSD1306Ascii::displayRemap(bool mode) {
|
|
||||||
ssd1306WriteCmd(mode ? SSD1306_SEGREMAP : SSD1306_SEGREMAP | 1);
|
|
||||||
ssd1306WriteCmd(mode ? SSD1306_COMSCANINC : SSD1306_COMSCANDEC);
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
size_t SSD1306Ascii::fieldWidth(uint8_t n) {
|
|
||||||
return n*(fontWidth() + letterSpacing());
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
uint8_t SSD1306Ascii::fontCharCount() const {
|
|
||||||
return m_font ? readFontByte(m_font + FONT_CHAR_COUNT) : 0;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
char SSD1306Ascii::fontFirstChar() const {
|
|
||||||
return m_font ? readFontByte(m_font + FONT_FIRST_CHAR) : 0;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
uint8_t SSD1306Ascii::fontHeight() const {
|
|
||||||
return m_font ? m_magFactor*readFontByte(m_font + FONT_HEIGHT) : 0;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
uint8_t SSD1306Ascii::fontRows() const {
|
|
||||||
return m_font ? m_magFactor*((readFontByte(m_font + FONT_HEIGHT) + 7)/8) : 0;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
uint16_t SSD1306Ascii::fontSize() const {
|
|
||||||
return (readFontByte(m_font) << 8) | readFontByte(m_font + 1);
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
uint8_t SSD1306Ascii::fontWidth() const {
|
|
||||||
return m_font ? m_magFactor*readFontByte(m_font + FONT_WIDTH) : 0;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SSD1306Ascii::init(const DevType* dev) {
|
void SSD1306Ascii::init(const DevType* dev) {
|
||||||
m_col = 0;
|
m_col = 0;
|
||||||
m_row = 0;
|
m_row = 0;
|
||||||
@ -120,10 +55,6 @@ void SSD1306Ascii::init(const DevType* dev) {
|
|||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void SSD1306Ascii::invertDisplay(bool invert) {
|
|
||||||
ssd1306WriteCmd(invert ? SSD1306_INVERTDISPLAY : SSD1306_NORMALDISPLAY);
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SSD1306Ascii::setCol(uint8_t col) {
|
void SSD1306Ascii::setCol(uint8_t col) {
|
||||||
if (col < m_displayWidth) {
|
if (col < m_displayWidth) {
|
||||||
m_col = col;
|
m_col = col;
|
||||||
@ -145,35 +76,19 @@ void SSD1306Ascii::setCursor(uint8_t col, uint8_t row) {
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void SSD1306Ascii::setFont(const uint8_t* font) {
|
void SSD1306Ascii::setFont(const uint8_t* font) {
|
||||||
m_font = font;
|
m_font = font;
|
||||||
if (font && fontSize() == 1) {
|
m_letterSpacing = 1;
|
||||||
m_letterSpacing = 0;
|
m_fontFirstChar = readFontByte(m_font + FONT_FIRST_CHAR);
|
||||||
} else {
|
m_fontCharCount = readFontByte(m_font + FONT_CHAR_COUNT);
|
||||||
m_letterSpacing = 1;
|
m_fontHeight = readFontByte(m_font + FONT_HEIGHT);
|
||||||
}
|
m_fontWidth = readFontByte(m_font + FONT_WIDTH);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void SSD1306Ascii::setRow(uint8_t row) {
|
void SSD1306Ascii::setRow(uint8_t row) {
|
||||||
if (row < displayRows()) {
|
if (row < displayRows()) {
|
||||||
m_row = row;
|
m_row = row;
|
||||||
#if INCLUDE_SCROLLING
|
|
||||||
ssd1306WriteCmd(SSD1306_SETSTARTPAGE | ((m_row + m_pageOffset) & 7));
|
|
||||||
#else // INCLUDE_SCROLLING
|
|
||||||
ssd1306WriteCmd(SSD1306_SETSTARTPAGE | m_row);
|
ssd1306WriteCmd(SSD1306_SETSTARTPAGE | m_row);
|
||||||
#endif // INCLUDE_SCROLLING
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if INCLUDE_SCROLLING
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SSD1306Ascii::setPageOffset(uint8_t page) {
|
|
||||||
m_pageOffset = page & 7;
|
|
||||||
setRow(m_row);
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SSD1306Ascii::setStartLine(uint8_t line) {
|
|
||||||
m_startLine = line & 0X3F;
|
|
||||||
ssd1306WriteCmd(SSD1306_SETSTARTLINE | m_startLine);
|
|
||||||
}
|
|
||||||
#endif // INCLUDE_SCROLLING
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void SSD1306Ascii::ssd1306WriteRam(uint8_t c) {
|
void SSD1306Ascii::ssd1306WriteRam(uint8_t c) {
|
||||||
if (m_col < m_displayWidth) {
|
if (m_col < m_displayWidth) {
|
||||||
@ -183,117 +98,12 @@ void SSD1306Ascii::ssd1306WriteRam(uint8_t c) {
|
|||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void SSD1306Ascii::ssd1306WriteRamBuf(uint8_t c) {
|
void SSD1306Ascii::ssd1306WriteRamBuf(uint8_t c) {
|
||||||
if (m_skip) {
|
if (m_col < m_displayWidth) {
|
||||||
m_skip--;
|
|
||||||
} else if (m_col < m_displayWidth) {
|
|
||||||
writeDisplay(c^m_invertMask, SSD1306_MODE_RAM_BUF);
|
writeDisplay(c^m_invertMask, SSD1306_MODE_RAM_BUF);
|
||||||
m_col++;
|
m_col++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
GLCDFONTDECL(scaledNibble) = {
|
|
||||||
0X00, 0X03, 0X0C, 0X0F,
|
|
||||||
0X30, 0X33, 0X3C, 0X3F,
|
|
||||||
0XC0, 0XC3, 0XCC, 0XCF,
|
|
||||||
0XF0, 0XF3, 0XFC, 0XFF
|
|
||||||
};
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
size_t SSD1306Ascii::strWidth(const char* str) const {
|
|
||||||
size_t sw = 0;
|
|
||||||
while (*str) {
|
|
||||||
uint8_t cw = charWidth(*str++);
|
|
||||||
if (cw == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
sw += cw + letterSpacing();
|
|
||||||
}
|
|
||||||
return sw;
|
|
||||||
}
|
|
||||||
// //------------------------------------------------------------------------------
|
|
||||||
// void SSD1306Ascii::tickerInit(TickerState* state, const uint8_t* font,
|
|
||||||
// uint8_t row, bool mag2X, uint8_t bgnCol, uint8_t endCol) {
|
|
||||||
// state->font = font;
|
|
||||||
// state->row = row;
|
|
||||||
// state->mag2X = mag2X;
|
|
||||||
// state->bgnCol = bgnCol;
|
|
||||||
// state->endCol = endCol < m_displayWidth ? endCol : m_displayWidth - 1;
|
|
||||||
// state->nQueue = 0;
|
|
||||||
// }
|
|
||||||
// //------------------------------------------------------------------------------
|
|
||||||
// bool SSD1306Ascii::tickerText(TickerState* state, const char* text) {
|
|
||||||
// if (!text) {
|
|
||||||
// state->nQueue = 0;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// if (state->nQueue >= TICKER_QUEUE_DIM) {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// if (state->nQueue == 0) {
|
|
||||||
// state->init = true;
|
|
||||||
// }
|
|
||||||
// state->queue[state->nQueue++] = text;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// //------------------------------------------------------------------------------
|
|
||||||
// int8_t SSD1306Ascii::tickerTick(TickerState* state) {
|
|
||||||
// if (!state->font) {
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
// if (!state->nQueue) {
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
// setFont(state->font);
|
|
||||||
// m_magFactor = state->mag2X ? 2 : 1;
|
|
||||||
// if (state->init) {
|
|
||||||
// clear(state->bgnCol, state->endCol, state->row, state->row + fontRows() -1);
|
|
||||||
// state->col = state->endCol;
|
|
||||||
// state->skip = 0;
|
|
||||||
// state->init = false;
|
|
||||||
// }
|
|
||||||
// // Adjust display width to truncate pixels after endCol. Find better way?
|
|
||||||
// uint8_t save = m_displayWidth;
|
|
||||||
// m_displayWidth = state->endCol + 1;
|
|
||||||
|
|
||||||
// // Skip pixels before bgnCol.
|
|
||||||
// skipColumns(state->skip);
|
|
||||||
// setCursor(state->col, state->row);
|
|
||||||
// for (uint8_t i = 0; i < state->nQueue; i++) {
|
|
||||||
// const char* str = state->queue[i];
|
|
||||||
// while (*str && m_col <= state->endCol) {
|
|
||||||
// write(*str++);
|
|
||||||
// }
|
|
||||||
// if (m_col > state->endCol) {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if (m_col <= state->endCol) {
|
|
||||||
// clear(m_col, m_col, state->row, state->row + fontRows() - 1);
|
|
||||||
// }
|
|
||||||
// // Restore display width.
|
|
||||||
// m_displayWidth = save;
|
|
||||||
|
|
||||||
// if (state->nQueue == 1 && *state->queue[0] == 0) {
|
|
||||||
// state->nQueue = 0;
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
// if (state->col > state->bgnCol) {
|
|
||||||
// state->col--;
|
|
||||||
// } else {
|
|
||||||
// state->skip++;
|
|
||||||
// if (state->skip >= charSpacing(*state->queue[0])) {
|
|
||||||
// state->skip = 0;
|
|
||||||
// state->queue[0]++;
|
|
||||||
// if (*state->queue[0] == 0 && state->nQueue > 1) {
|
|
||||||
// state->nQueue--;
|
|
||||||
// for (uint8_t i = 0; i < state->nQueue; i++) {
|
|
||||||
// state->queue[i] = state->queue[i + 1];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return state->nQueue;
|
|
||||||
// }
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
size_t SSD1306Ascii::write(uint8_t ch) {
|
size_t SSD1306Ascii::write(uint8_t ch) {
|
||||||
if (!m_font) {
|
if (!m_font) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -305,77 +115,23 @@ size_t SSD1306Ascii::write(uint8_t ch) {
|
|||||||
uint8_t count = readFontByte(m_font + FONT_CHAR_COUNT);
|
uint8_t count = readFontByte(m_font + FONT_CHAR_COUNT);
|
||||||
const uint8_t* base = m_font + FONT_WIDTH_TABLE;
|
const uint8_t* base = m_font + FONT_WIDTH_TABLE;
|
||||||
|
|
||||||
if (ch < first || ch >= (first + count)) {
|
if (ch < first || ch >= (first + count)) return 0;
|
||||||
if (ch == '\r') {
|
|
||||||
setCol(0);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ch == '\n') {
|
|
||||||
setCol(0);
|
|
||||||
uint8_t fr = m_magFactor*nr;
|
|
||||||
#if INCLUDE_SCROLLING
|
|
||||||
uint8_t dr = displayRows();
|
|
||||||
uint8_t tmpRow = m_row + fr;
|
|
||||||
int8_t delta = tmpRow + fr - dr;
|
|
||||||
if (m_scrollMode == SCROLL_MODE_OFF || delta <= 0) {
|
|
||||||
setRow(tmpRow);
|
|
||||||
} else {
|
|
||||||
m_pageOffset = (m_pageOffset + delta) & 7;
|
|
||||||
m_row = dr - fr;
|
|
||||||
// Cursor will be positioned by clearToEOL.
|
|
||||||
clearToEOL();
|
|
||||||
if (m_scrollMode == SCROLL_MODE_AUTO) {
|
|
||||||
setStartLine(8*m_pageOffset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else // INCLUDE_SCROLLING
|
|
||||||
setRow(m_row + fr);
|
|
||||||
#endif // INCLUDE_SCROLLING
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
ch -= first;
|
ch -= first;
|
||||||
uint8_t s = letterSpacing();
|
uint8_t s = letterSpacing();
|
||||||
uint8_t thieleShift = 0;
|
// Fixed width font.
|
||||||
if (fontSize() < 2) {
|
base += nr*w*ch;
|
||||||
// Fixed width font.
|
|
||||||
base += nr*w*ch;
|
|
||||||
} else {
|
|
||||||
if (h & 7) {
|
|
||||||
thieleShift = 8 - (h & 7);
|
|
||||||
}
|
|
||||||
uint16_t index = 0;
|
|
||||||
for (uint8_t i = 0; i < ch; i++) {
|
|
||||||
index += readFontByte(base + i);
|
|
||||||
}
|
|
||||||
w = readFontByte(base + ch);
|
|
||||||
base += nr*index + count;
|
|
||||||
}
|
|
||||||
uint8_t scol = m_col;
|
uint8_t scol = m_col;
|
||||||
uint8_t srow = m_row;
|
uint8_t srow = m_row;
|
||||||
uint8_t skip = m_skip;
|
|
||||||
for (uint8_t r = 0; r < nr; r++) {
|
for (uint8_t r = 0; r < nr; r++) {
|
||||||
for (uint8_t m = 0; m < m_magFactor; m++) {
|
if (r) {
|
||||||
skipColumns(skip);
|
setCursor(scol, m_row + 1);
|
||||||
if (r || m) {
|
}
|
||||||
setCursor(scol, m_row + 1);
|
for (uint8_t c = 0; c < w; c++) {
|
||||||
}
|
uint8_t b = readFontByte(base + c + r*w);
|
||||||
for (uint8_t c = 0; c < w; c++) {
|
ssd1306WriteRamBuf(b);
|
||||||
uint8_t b = readFontByte(base + c + r*w);
|
}
|
||||||
if (thieleShift && (r + 1) == nr) {
|
for (uint8_t i = 0; i < s; i++) {
|
||||||
b >>= thieleShift;
|
ssd1306WriteRamBuf(0);
|
||||||
}
|
|
||||||
if (m_magFactor == 2) {
|
|
||||||
b = m ? b >> 4 : b & 0XF;
|
|
||||||
b = readFontByte(scaledNibble + b);
|
|
||||||
ssd1306WriteRamBuf(b);
|
|
||||||
}
|
|
||||||
ssd1306WriteRamBuf(b);
|
|
||||||
}
|
|
||||||
for (uint8_t i = 0; i < s; i++) {
|
|
||||||
ssd1306WriteRamBuf(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setRow(srow);
|
setRow(srow);
|
||||||
|
@ -31,46 +31,13 @@
|
|||||||
#define SDD1306_ASCII_VERSION 1.3.0
|
#define SDD1306_ASCII_VERSION 1.3.0
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Configuration options.
|
// Configuration options.
|
||||||
/** Set Scrolling mode for newline.
|
|
||||||
*
|
|
||||||
* If INCLUDE_SCROLLING is defined to be zero, newline will not scroll
|
|
||||||
* the display and code for scrolling will not be included. This option
|
|
||||||
* will save some code space and three bytes of RAM.
|
|
||||||
*
|
|
||||||
* If INCLUDE_SCROLLING is nonzero, the scroll feature will included.
|
|
||||||
*/
|
|
||||||
#define INCLUDE_SCROLLING 1
|
|
||||||
|
|
||||||
/** Initial scroll mode, SCROLL_MODE_OFF,
|
|
||||||
SCROLL_MODE_AUTO, or SCROLL_MODE_APP. */
|
|
||||||
#define INITIAL_SCROLL_MODE SCROLL_MODE_OFF
|
|
||||||
|
|
||||||
/** Dimension of TickerState pointer queue */
|
|
||||||
#define TICKER_QUEUE_DIM 6
|
|
||||||
|
|
||||||
/** Use larger faster I2C code. */
|
/** Use larger faster I2C code. */
|
||||||
#define OPTIMIZE_I2C 1
|
#define OPTIMIZE_I2C 1
|
||||||
|
|
||||||
/** If MULTIPLE_I2C_PORTS is nonzero,
|
|
||||||
define a constructor with port selection. */
|
|
||||||
#ifdef __AVR__
|
|
||||||
// Save memory on AVR. Set nonzero to use alternate I2C or software I2c on AVR.
|
|
||||||
#define MULTIPLE_I2C_PORTS 0
|
|
||||||
#else // __AVR__
|
|
||||||
#define MULTIPLE_I2C_PORTS 1
|
|
||||||
#endif // __AVR__
|
|
||||||
|
|
||||||
/** AvrI2c uses 400 kHz fast mode if AVRI2C_FASTMODE is nonzero else 100 kHz. */
|
/** AvrI2c uses 400 kHz fast mode if AVRI2C_FASTMODE is nonzero else 100 kHz. */
|
||||||
#define AVRI2C_FASTMODE 1
|
#define AVRI2C_FASTMODE 1
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Values for setScrolMode(uint8_t mode)
|
|
||||||
/** Newline will not scroll the display or RAM window. */
|
|
||||||
#define SCROLL_MODE_OFF 0
|
|
||||||
/** Newline will scroll both the display and RAM windows. */
|
|
||||||
#define SCROLL_MODE_AUTO 1
|
|
||||||
/** Newline scrolls the RAM window. The app scrolls the display window. */
|
|
||||||
#define SCROLL_MODE_APP 2
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Values for writeDisplay() mode parameter.
|
// Values for writeDisplay() mode parameter.
|
||||||
/** Write to Command register. */
|
/** Write to Command register. */
|
||||||
#define SSD1306_MODE_CMD 0
|
#define SSD1306_MODE_CMD 0
|
||||||
@ -92,27 +59,6 @@ inline void oledReset(uint8_t rst) {
|
|||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/**
|
|
||||||
* @struct TickerState
|
|
||||||
* @brief ticker status
|
|
||||||
*/
|
|
||||||
struct TickerState {
|
|
||||||
const char* queue[TICKER_QUEUE_DIM]; ///< Queue of text pointers.
|
|
||||||
uint8_t nQueue = 0; ///< Count of pointers in queue.
|
|
||||||
const uint8_t* font = nullptr; ///< Font for ticker.
|
|
||||||
bool mag2X; ///< Use mag2X if true.
|
|
||||||
uint8_t row; ///< Row for ticker
|
|
||||||
uint8_t bgnCol; ///< Begin column of ticker.
|
|
||||||
uint8_t endCol; ///< End column of ticker.
|
|
||||||
bool init; ///< clear and initialize display area if true.
|
|
||||||
uint8_t col; ///< Column for start of displayed text.
|
|
||||||
uint8_t skip; ///< Number of pixels to skip in first character.
|
|
||||||
/// @return Count of free queue slots.
|
|
||||||
uint8_t queueFree() {return TICKER_QUEUE_DIM - nQueue;}
|
|
||||||
/// @return Count of used queue slots.
|
|
||||||
uint8_t queueUsed() {return nQueue;}
|
|
||||||
};
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/**
|
/**
|
||||||
* @class SSD1306Ascii
|
* @class SSD1306Ascii
|
||||||
* @brief SSD1306 base class
|
* @brief SSD1306 base class
|
||||||
@ -121,86 +67,6 @@ class SSD1306Ascii : public Print {
|
|||||||
public:
|
public:
|
||||||
using Print::write;
|
using Print::write;
|
||||||
SSD1306Ascii() {}
|
SSD1306Ascii() {}
|
||||||
#if INCLUDE_SCROLLING
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @return the RAM page for top of the RAM window.
|
|
||||||
*/
|
|
||||||
uint8_t pageOffset() const {return m_pageOffset;}
|
|
||||||
/**
|
|
||||||
* @return the display line for pageOffset.
|
|
||||||
*/
|
|
||||||
uint8_t pageOffsetLine() const {return 8*m_pageOffset;}
|
|
||||||
/**
|
|
||||||
* @brief Scroll the Display window.
|
|
||||||
*
|
|
||||||
* @param[in] lines Number of lines to scroll the window.
|
|
||||||
*/
|
|
||||||
void scrollDisplay(int8_t lines) {setStartLine(m_startLine + lines);}
|
|
||||||
/**
|
|
||||||
* @brief Scroll the RAM window.
|
|
||||||
*
|
|
||||||
* @param[in] rows Number of rows to scroll the window.
|
|
||||||
*/
|
|
||||||
void scrollMemory(int8_t rows) {setPageOffset(m_pageOffset + rows);}
|
|
||||||
/**
|
|
||||||
* @return true if the first display line is equal to the
|
|
||||||
* start of the RAM window.
|
|
||||||
*/
|
|
||||||
bool scrollIsSynced() const {return startLine() == pageOffsetLine();}
|
|
||||||
/**
|
|
||||||
* @brief Set page offset.
|
|
||||||
*
|
|
||||||
* @param[in] page the RAM page for start of the RAM window
|
|
||||||
*/
|
|
||||||
void setPageOffset(uint8_t page);
|
|
||||||
/**
|
|
||||||
* @brief Enable or disable scroll mode. Deprecated use setScrollMode().
|
|
||||||
*
|
|
||||||
* @param[in] enable true enable scroll on newline false disable scroll.
|
|
||||||
*/
|
|
||||||
void setScroll(bool enable) __attribute__((deprecated("use setScrollMode"))) {
|
|
||||||
setScrollMode(enable ? SCROLL_MODE_AUTO : SCROLL_MODE_OFF);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @brief Set scroll mode.
|
|
||||||
*
|
|
||||||
* @param[in] mode One of the following.
|
|
||||||
*
|
|
||||||
* SCROLL_MODE_OFF - newline will not scroll the display or RAM window.
|
|
||||||
*
|
|
||||||
* SCROLL_MODE_AUTO - newline will scroll both the display and RAM windows.
|
|
||||||
*
|
|
||||||
* SCROLL_MODE_APP - newline scrolls the RAM window.
|
|
||||||
* The app scrolls the display window.
|
|
||||||
*/
|
|
||||||
void setScrollMode(uint8_t mode) {m_scrollMode = mode;}
|
|
||||||
/**
|
|
||||||
* @brief Set the display start line register.
|
|
||||||
*
|
|
||||||
* @param[in] line RAM line to be mapped to first display line.
|
|
||||||
*/
|
|
||||||
void setStartLine(uint8_t line);
|
|
||||||
/**
|
|
||||||
* @return the display startline.
|
|
||||||
*/
|
|
||||||
uint8_t startLine() const {return m_startLine;}
|
|
||||||
#endif // INCLUDE_SCROLLING
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief Determine the spacing of a character. Spacing is width + space.
|
|
||||||
*
|
|
||||||
* @param[in] c Character code.
|
|
||||||
* @return Spacing of the character in pixels.
|
|
||||||
*/
|
|
||||||
uint8_t charSpacing(uint8_t c) {return charWidth(c) + letterSpacing();}
|
|
||||||
/**
|
|
||||||
* @brief Determine the width of a character.
|
|
||||||
*
|
|
||||||
* @param[in] c Character code.
|
|
||||||
* @return Width of the character in pixels.
|
|
||||||
*/
|
|
||||||
uint8_t charWidth(uint8_t c) const;
|
|
||||||
/**
|
/**
|
||||||
* @brief Clear the display and set the cursor to (0, 0).
|
* @brief Clear the display and set the cursor to (0, 0).
|
||||||
*/
|
*/
|
||||||
@ -236,11 +102,11 @@ class SSD1306Ascii : public Print {
|
|||||||
/**
|
/**
|
||||||
* @return The current column in pixels.
|
* @return The current column in pixels.
|
||||||
*/
|
*/
|
||||||
uint8_t col() const {return m_col;}
|
inline uint8_t col() const {return m_col;}
|
||||||
/**
|
/**
|
||||||
* @return The display hight in pixels.
|
* @return The display hight in pixels.
|
||||||
*/
|
*/
|
||||||
uint8_t displayHeight() const {return m_displayHeight;}
|
inline uint8_t displayHeight() const {return m_displayHeight;}
|
||||||
/**
|
/**
|
||||||
* @brief Set display to normal or 180 degree remap mode.
|
* @brief Set display to normal or 180 degree remap mode.
|
||||||
*
|
*
|
||||||
@ -253,19 +119,11 @@ class SSD1306Ascii : public Print {
|
|||||||
/**
|
/**
|
||||||
* @return The display height in rows with eight pixels to a row.
|
* @return The display height in rows with eight pixels to a row.
|
||||||
*/
|
*/
|
||||||
uint8_t displayRows() const {return m_displayHeight/8;}
|
inline uint8_t displayRows() const {return m_displayHeight/8;}
|
||||||
/**
|
/**
|
||||||
* @return The display width in pixels.
|
* @return The display width in pixels.
|
||||||
*/
|
*/
|
||||||
uint8_t displayWidth() const {return m_displayWidth;}
|
inline uint8_t displayWidth() const {return m_displayWidth;}
|
||||||
/**
|
|
||||||
* @brief Width of a field in pixels.
|
|
||||||
*
|
|
||||||
* @param[in] n Number of characters in the field.
|
|
||||||
*
|
|
||||||
* @return Width of the field.
|
|
||||||
*/
|
|
||||||
size_t fieldWidth(uint8_t n);
|
|
||||||
/**
|
/**
|
||||||
* @return The current font pointer.
|
* @return The current font pointer.
|
||||||
*/
|
*/
|
||||||
@ -273,28 +131,19 @@ class SSD1306Ascii : public Print {
|
|||||||
/**
|
/**
|
||||||
* @return The count of characters in a font.
|
* @return The count of characters in a font.
|
||||||
*/
|
*/
|
||||||
uint8_t fontCharCount() const;
|
inline uint8_t fontCharCount() const {return m_fontCharCount;};
|
||||||
/**
|
/**
|
||||||
* @return The first character in a font.
|
* @return The first character in a font.
|
||||||
*/
|
*/
|
||||||
char fontFirstChar() const;
|
inline char fontFirstChar() const {return m_fontFirstChar;};
|
||||||
/**
|
/**
|
||||||
* @return The current font height in pixels.
|
* @return The current font height in pixels.
|
||||||
*/
|
*/
|
||||||
uint8_t fontHeight() const;
|
inline uint8_t fontHeight() const {return m_fontHeight;};
|
||||||
/**
|
|
||||||
* @return The number of eight pixel rows required to display a character
|
|
||||||
* in the current font.
|
|
||||||
*/
|
|
||||||
uint8_t fontRows() const;
|
|
||||||
/**
|
|
||||||
* @return The maximum width of characters in the current font.
|
|
||||||
*/
|
|
||||||
uint8_t fontWidth() const;
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the cursor position to (0, 0).
|
* @brief Set the cursor position to (0, 0).
|
||||||
*/
|
*/
|
||||||
void home() {setCursor(0, 0);}
|
inline void home() {setCursor(0, 0);}
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the display controller.
|
* @brief Initialize the display controller.
|
||||||
*
|
*
|
||||||
@ -310,33 +159,21 @@ class SSD1306Ascii : public Print {
|
|||||||
/**
|
/**
|
||||||
* @return invert mode.
|
* @return invert mode.
|
||||||
*/
|
*/
|
||||||
bool invertMode() const {return !!m_invertMask;}
|
inline bool invertMode() const {return !!m_invertMask;}
|
||||||
/**
|
/**
|
||||||
* @brief Set invert mode for write/print.
|
* @brief Set invert mode for write/print.
|
||||||
*
|
*
|
||||||
* @param[in] mode Invert pixels if true and use normal mode if false.
|
* @param[in] mode Invert pixels if true and use normal mode if false.
|
||||||
*/
|
*/
|
||||||
void setInvertMode(bool mode) {m_invertMask = mode ? 0XFF : 0;}
|
inline void setInvertMode(bool mode) {m_invertMask = mode ? 0XFF : 0;}
|
||||||
/**
|
/**
|
||||||
* @return letter-spacing in pixels with magnification factor.
|
* @return letter-spacing in pixels with magnification factor.
|
||||||
*/
|
*/
|
||||||
uint8_t letterSpacing() const {return m_magFactor*m_letterSpacing;}
|
inline uint8_t letterSpacing() const {return m_letterSpacing;}
|
||||||
/**
|
|
||||||
* @return The character magnification factor.
|
|
||||||
*/
|
|
||||||
uint8_t magFactor() const {return m_magFactor;}
|
|
||||||
/**
|
/**
|
||||||
* @return the current row number with eight pixels to a row.
|
* @return the current row number with eight pixels to a row.
|
||||||
*/
|
*/
|
||||||
uint8_t row() const {return m_row;}
|
inline uint8_t row() const {return m_row;}
|
||||||
/**
|
|
||||||
* @brief Set the character magnification factor to one.
|
|
||||||
*/
|
|
||||||
void set1X() {m_magFactor = 1;}
|
|
||||||
/**
|
|
||||||
* @brief Set the character magnification factor to two.
|
|
||||||
*/
|
|
||||||
void set2X() {m_magFactor = 2;}
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the current column number.
|
* @brief Set the current column number.
|
||||||
*
|
*
|
||||||
@ -362,12 +199,6 @@ class SSD1306Ascii : public Print {
|
|||||||
* @param[in] font Pointer to a font table.
|
* @param[in] font Pointer to a font table.
|
||||||
*/
|
*/
|
||||||
void setFont(const uint8_t* font);
|
void setFont(const uint8_t* font);
|
||||||
/**
|
|
||||||
* @brief Set letter-spacing. setFont() will restore default letter-spacing.
|
|
||||||
*
|
|
||||||
* @param[in] pixels letter-spacing in pixels before magnification.
|
|
||||||
*/
|
|
||||||
void setLetterSpacing(uint8_t pixels) {m_letterSpacing = pixels;}
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the current row number.
|
* @brief Set the current row number.
|
||||||
*
|
*
|
||||||
@ -380,7 +211,7 @@ class SSD1306Ascii : public Print {
|
|||||||
* @param[in] c The command byte.
|
* @param[in] c The command byte.
|
||||||
* @note The byte will immediately be sent to the controller.
|
* @note The byte will immediately be sent to the controller.
|
||||||
*/
|
*/
|
||||||
void ssd1306WriteCmd(uint8_t c) {writeDisplay(c, SSD1306_MODE_CMD);}
|
inline void ssd1306WriteCmd(uint8_t c) {writeDisplay(c, SSD1306_MODE_CMD);}
|
||||||
/**
|
/**
|
||||||
* @brief Write a byte to RAM in the display controller.
|
* @brief Write a byte to RAM in the display controller.
|
||||||
*
|
*
|
||||||
@ -396,58 +227,7 @@ class SSD1306Ascii : public Print {
|
|||||||
* or ssd1306WriteRam.
|
* or ssd1306WriteRam.
|
||||||
*/
|
*/
|
||||||
void ssd1306WriteRamBuf(uint8_t c);
|
void ssd1306WriteRamBuf(uint8_t c);
|
||||||
/**
|
/**
|
||||||
* @brief Skip leading pixels writing characters to display display RAM.
|
|
||||||
*
|
|
||||||
* @param[in] n Number of pixels to skip.
|
|
||||||
*/
|
|
||||||
void skipColumns(uint8_t n) {m_skip = n;}
|
|
||||||
/**
|
|
||||||
* @brief Character width.
|
|
||||||
*
|
|
||||||
* @param[in] str The pointer to string.
|
|
||||||
* @return the width of the string in pixels.
|
|
||||||
*/
|
|
||||||
size_t strWidth(const char* str) const;
|
|
||||||
// /**
|
|
||||||
// * @brief Initialize TickerState struct and clear ticker field.
|
|
||||||
// *
|
|
||||||
// * @param[in,out] state Ticker state.
|
|
||||||
// * @param[in] font to be displayed.
|
|
||||||
// * @param[in] row Row for ticker.
|
|
||||||
// * @param[in] mag2X set magFactor to two if true.
|
|
||||||
// * @param[in] bgnCol First column of ticker. Default is zero.
|
|
||||||
// * @param[in] endCol Last column of ticker. Default is last column of display.
|
|
||||||
// */
|
|
||||||
// void tickerInit(TickerState* state, const uint8_t* font, uint8_t row,
|
|
||||||
// bool mag2X = false, uint8_t bgnCol = 0, uint8_t endCol = 255);
|
|
||||||
// /**
|
|
||||||
// * @brief Add text pointer to display queue.
|
|
||||||
// *
|
|
||||||
// * @param[in,out] state Ticker state.
|
|
||||||
// * @param[in] str Pointer to String object. Clear queue if nullptr.
|
|
||||||
// * @return false if queue is full else true.
|
|
||||||
// */
|
|
||||||
// bool tickerText(TickerState* state, const String &str) {
|
|
||||||
// return tickerText(state, str ? str.c_str() : nullptr);
|
|
||||||
// }
|
|
||||||
// /**
|
|
||||||
// * @brief Add text pointer to display queue.
|
|
||||||
// *
|
|
||||||
// * @param[in,out] state Ticker state.
|
|
||||||
// * @param[in] text Pointer to C string. Clear queue if nullptr.
|
|
||||||
// * @return false if queue is full else true.
|
|
||||||
// */
|
|
||||||
// bool tickerText(TickerState* state, const char* text);
|
|
||||||
// /**
|
|
||||||
// * @brief Advance ticker by one pixel.
|
|
||||||
// *
|
|
||||||
// * @param[in,out] state Ticker state.
|
|
||||||
// *
|
|
||||||
// * @return Number of entries in text pointer queue.
|
|
||||||
// */
|
|
||||||
// int8_t tickerTick(TickerState* state);
|
|
||||||
/**
|
|
||||||
* @brief Display a character.
|
* @brief Display a character.
|
||||||
*
|
*
|
||||||
* @param[in] c The character to display.
|
* @param[in] c The character to display.
|
||||||
@ -456,7 +236,6 @@ class SSD1306Ascii : public Print {
|
|||||||
size_t write(uint8_t c);
|
size_t write(uint8_t c);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint16_t fontSize() const;
|
|
||||||
virtual void writeDisplay(uint8_t b, uint8_t mode) = 0;
|
virtual void writeDisplay(uint8_t b, uint8_t mode) = 0;
|
||||||
uint8_t m_col; // Cursor column.
|
uint8_t m_col; // Cursor column.
|
||||||
uint8_t m_row; // Cursor RAM row.
|
uint8_t m_row; // Cursor RAM row.
|
||||||
@ -464,14 +243,13 @@ class SSD1306Ascii : public Print {
|
|||||||
uint8_t m_displayHeight; // Display height.
|
uint8_t m_displayHeight; // Display height.
|
||||||
uint8_t m_colOffset; // Column offset RAM to SEG.
|
uint8_t m_colOffset; // Column offset RAM to SEG.
|
||||||
uint8_t m_letterSpacing; // Letter-spacing in pixels.
|
uint8_t m_letterSpacing; // Letter-spacing in pixels.
|
||||||
#if INCLUDE_SCROLLING
|
|
||||||
uint8_t m_startLine; // Top line of display
|
|
||||||
uint8_t m_pageOffset; // Top page of RAM window.
|
|
||||||
uint8_t m_scrollMode = INITIAL_SCROLL_MODE; // Scroll mode for newline.
|
|
||||||
#endif // INCLUDE_SCROLLING
|
|
||||||
uint8_t m_skip = 0;
|
|
||||||
const uint8_t* m_font = nullptr; // Current font.
|
const uint8_t* m_font = nullptr; // Current font.
|
||||||
uint8_t m_invertMask = 0; // font invert mask
|
uint8_t m_invertMask = 0; // font invert mask
|
||||||
uint8_t m_magFactor = 1; // Magnification factor.
|
|
||||||
|
char m_fontFirstChar;
|
||||||
|
uint8_t m_fontCharCount;
|
||||||
|
uint8_t m_fontHeight;
|
||||||
|
uint8_t m_fontWidth;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif // SSD1306Ascii_h
|
#endif // SSD1306Ascii_h
|
||||||
|
@ -31,16 +31,7 @@
|
|||||||
*/
|
*/
|
||||||
class SSD1306AsciiWire : public SSD1306Ascii {
|
class SSD1306AsciiWire : public SSD1306Ascii {
|
||||||
public:
|
public:
|
||||||
#if MULTIPLE_I2C_PORTS
|
|
||||||
/**
|
|
||||||
* @brief Initialize object on specific I2C bus.
|
|
||||||
*
|
|
||||||
* @param[in] bus The I2C bus to be used.
|
|
||||||
*/
|
|
||||||
explicit SSD1306AsciiWire(decltype(Wire) &bus = Wire) : m_oledWire(bus) {}
|
|
||||||
#else // MULTIPLE_I2C_PORTS
|
|
||||||
#define m_oledWire Wire
|
#define m_oledWire Wire
|
||||||
#endif // MULTIPLE_I2C_PORTS
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the display controller.
|
* @brief Initialize the display controller.
|
||||||
*
|
*
|
||||||
@ -100,9 +91,6 @@ class SSD1306AsciiWire : public SSD1306Ascii {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#if MULTIPLE_I2C_PORTS
|
|
||||||
decltype(Wire)& m_oledWire;
|
|
||||||
#endif // MULTIPLE_I2C_PORTS
|
|
||||||
uint8_t m_i2cAddr;
|
uint8_t m_i2cAddr;
|
||||||
#if OPTIMIZE_I2C
|
#if OPTIMIZE_I2C
|
||||||
uint8_t m_nData;
|
uint8_t m_nData;
|
||||||
|
Loading…
Reference in New Issue
Block a user