fixed text output, added some sanity checks

master
Sascha Nitsch 2022-03-22 03:43:08 +01:00
parent 988dd9b99b
commit 46ee10990a
1 changed files with 3 additions and 1 deletions

View File

@ -93,6 +93,7 @@ bool CimditSSD1306::begin() {
} }
void CimditSSD1306::drawPixel(uint8_t x, uint8_t y, bool state) { void CimditSSD1306::drawPixel(uint8_t x, uint8_t y, bool state) {
if (x >= m_width || y >= m_height) return;
if (state) { if (state) {
m_buffer[x + (y >> 3) * m_width] |= (1 << (y & 7)); m_buffer[x + (y >> 3) * m_width] |= (1 << (y & 7));
} else { } else {
@ -105,6 +106,7 @@ void CimditSSD1306::clearDisplay(void) {
} }
void CimditSSD1306::drawFastHLine(uint8_t x, uint8_t y, uint8_t w, bool state) { void CimditSSD1306::drawFastHLine(uint8_t x, uint8_t y, uint8_t w, bool state) {
if ((x + w) >= m_width || (y >= m_height)) return;
uint8_t *pBuf = m_buffer + (y / 8) * m_width + x; uint8_t *pBuf = m_buffer + (y / 8) * m_width + x;
uint8_t mask = 1 << (y & 7); uint8_t mask = 1 << (y & 7);
if (state) { if (state) {
@ -237,7 +239,7 @@ void CimditSSD1306::setTextSize(uint8_t sX, uint8_t sY) {
} }
size_t CimditSSD1306::write(uint8_t c) { size_t CimditSSD1306::write(uint8_t c) {
if (c == '\n' || m_cursorX + m_textsizeX * 6) { // a newline or text oveflow if (c == '\n' || (m_cursorX + m_textsizeX * 6 > m_width)) { // a newline or text oveflow
m_cursorX = 0; // set X to zero m_cursorX = 0; // set X to zero
m_cursorY += m_textsizeY * 8; // go down one line m_cursorY += m_textsizeY * 8; // go down one line
} else if (c == '\r') { // a carriage return } else if (c == '\r') { // a carriage return