Skip to content

Commit

Permalink
Non-font space, clang-format, cppcheck mods, include guard fix
Browse files Browse the repository at this point in the history
  • Loading branch information
greiman committed Feb 13, 2023
1 parent 696b6c4 commit c43eaa9
Show file tree
Hide file tree
Showing 16 changed files with 232 additions and 185 deletions.
2 changes: 1 addition & 1 deletion extras/cpplint.bat
@@ -1,2 +1,2 @@
sh cpplint.sh
pause
pause
30 changes: 15 additions & 15 deletions extras/cpplint.py
Expand Up @@ -67,7 +67,7 @@
<file> [file] ...
The style guidelines this tries to follow are those in
https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
https://google.github.io/styleguide/cppguide.html
Every problem is given a confidence score from 1-5, with 5 meaning we are
certain of the problem, and 1 meaning it could be a legitimate construct.
Expand Down Expand Up @@ -1383,7 +1383,7 @@ def FindNextMultiLineCommentEnd(lines, lineix):

def RemoveMultiLineCommentsFromRange(lines, begin, end):
"""Clears a range of lines for multi-line comments."""
# Having // dummy comments makes the lines non-empty, so we will not get
# Having // <empty> comments makes the lines non-empty, so we will not get
# unnecessary blank line warnings later in the code.
for i in range(begin, end):
lines[i] = '/**/'
Expand Down Expand Up @@ -1757,7 +1757,7 @@ def CheckForCopyright(filename, lines, error):
"""Logs an error if no Copyright message appears at the top of the file."""

# We'll say it should occur by line 10. Don't forget there's a
# dummy line at the front.
# placeholder line at the front.
for line in xrange(1, min(len(lines), 11)):
if re.search(r'Copyright', lines[line], re.I): break
else: # means no copyright line was found
Expand Down Expand Up @@ -3283,8 +3283,8 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error):
line = clean_lines.elided[linenum]

# You shouldn't have spaces before your brackets, except maybe after
# 'delete []' or 'return []() {};'
if Search(r'\w\s+\[', line) and not Search(r'(?:delete|return)\s+\[', line):
# 'delete []', 'return []() {};', or 'auto [abc, ...] = ...;'.
if Search(r'\w\s+\[', line) and not Search(r'(?:auto&?|delete|return)\s+\[', line):
error(filename, linenum, 'whitespace/braces', 5,
'Extra space before [')

Expand Down Expand Up @@ -3866,9 +3866,9 @@ def CheckTrailingSemicolon(filename, clean_lines, linenum, error):

# Block bodies should not be followed by a semicolon. Due to C++11
# brace initialization, there are more places where semicolons are
# required than not, so we use a whitelist approach to check these
# rather than a blacklist. These are the places where "};" should
# be replaced by just "}":
# required than not, so we explicitly list the allowed rules rather
# than listing the disallowed ones. These are the places where "};"
# should be replaced by just "}":
# 1. Some flavor of block following closing parenthesis:
# for (;;) {};
# while (...) {};
Expand Down Expand Up @@ -3924,11 +3924,11 @@ def CheckTrailingSemicolon(filename, clean_lines, linenum, error):
# - INTERFACE_DEF
# - EXCLUSIVE_LOCKS_REQUIRED, SHARED_LOCKS_REQUIRED, LOCKS_EXCLUDED:
#
# We implement a whitelist of safe macros instead of a blacklist of
# We implement a list of safe macros instead of a list of
# unsafe macros, even though the latter appears less frequently in
# google code and would have been easier to implement. This is because
# the downside for getting the whitelist wrong means some extra
# semicolons, while the downside for getting the blacklist wrong
# the downside for getting the allowed checks wrong means some extra
# semicolons, while the downside for getting disallowed checks wrong
# would result in compile errors.
#
# In addition to macros, we also don't want to warn on
Expand Down Expand Up @@ -5124,19 +5124,19 @@ def CheckForNonConstReference(filename, clean_lines, linenum,
#
# We also accept & in static_assert, which looks like a function but
# it's actually a declaration expression.
whitelisted_functions = (r'(?:[sS]wap(?:<\w:+>)?|'
allowed_functions = (r'(?:[sS]wap(?:<\w:+>)?|'
r'operator\s*[<>][<>]|'
r'static_assert|COMPILE_ASSERT'
r')\s*\(')
if Search(whitelisted_functions, line):
if Search(allowed_functions, line):
return
elif not Search(r'\S+\([^)]*$', line):
# Don't see a whitelisted function on this line. Actually we
# Don't see an allowed function on this line. Actually we
# didn't see any function name on this line, so this is likely a
# multi-line parameter list. Try a bit harder to catch this case.
for i in xrange(2):
if (linenum > i and
Search(whitelisted_functions, clean_lines.elided[linenum - i - 1])):
Search(allowed_functions, clean_lines.elided[linenum - i - 1])):
return

decls = ReplaceAll(r'{[^}]*}', ' ', line) # exclude function body
Expand Down
2 changes: 1 addition & 1 deletion extras/cpplint.sh
@@ -1,4 +1,4 @@
#!/bin/sh
export PATH=/cygdrive/c/Python27:/cygdrive/c/Python27/DLLs:/cygdrive/c/Python27/Scripts:$PATH
echo $PATH
python cpplint.py --filter=-build/include,-runtime/references,-build/header_guard ../src/*.* ../src/utility/*.* 2>cpplint.txt
python cpplint.py --filter=-build/include,-runtime/references,-build/header_guard ../src/*.* ../src/utility/*.* ../src/fonts/allfonts.h 2>cpplint.txt
2 changes: 1 addition & 1 deletion library.properties
@@ -1,5 +1,5 @@
name=SSD1306Ascii
version=1.3.4
version=1.3.5
author=Bill Greiman <fat16lib@sbcglobal.net>
maintainer=Bill Greiman <fat16lib@sbcglobal.net>
sentence=Text display on small monochrome OLED modules.
Expand Down
82 changes: 44 additions & 38 deletions src/SSD1306Ascii.cpp
Expand Up @@ -35,18 +35,18 @@ uint8_t SSD1306Ascii::charWidth(uint8_t c) const {
}
if (fontSize() > 1) {
// Proportional font.
return m_magFactor*readFontByte(m_font + FONT_WIDTH_TABLE + c - first);
return m_magFactor * readFontByte(m_font + FONT_WIDTH_TABLE + c - first);
}
// Fixed width font.
return m_magFactor*readFontByte(m_font + FONT_WIDTH);
return m_magFactor * readFontByte(m_font + FONT_WIDTH);
}
//------------------------------------------------------------------------------
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) {
Expand All @@ -67,7 +67,7 @@ void SSD1306Ascii::clear(uint8_t c0, uint8_t c1, uint8_t r0, uint8_t r1) {
}
//------------------------------------------------------------------------------
void SSD1306Ascii::clearToEOL() {
clear(m_col, displayWidth() -1, m_row, m_row + fontRows() - 1);
clear(m_col, displayWidth() - 1, m_row, m_row + fontRows() - 1);
}
//------------------------------------------------------------------------------
void SSD1306Ascii::clearField(uint8_t col, uint8_t row, uint8_t n) {
Expand All @@ -80,7 +80,7 @@ void SSD1306Ascii::displayRemap(bool mode) {
}
//------------------------------------------------------------------------------
size_t SSD1306Ascii::fieldWidth(uint8_t n) {
return n*(fontWidth() + letterSpacing());
return n * (fontWidth() + letterSpacing());
}
//------------------------------------------------------------------------------
uint8_t SSD1306Ascii::fontCharCount() const {
Expand All @@ -92,27 +92,29 @@ char SSD1306Ascii::fontFirstChar() const {
}
//------------------------------------------------------------------------------
uint8_t SSD1306Ascii::fontHeight() const {
return m_font ? m_magFactor*readFontByte(m_font + FONT_HEIGHT) : 0;
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;
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;
return m_font ? m_magFactor * readFontByte(m_font + FONT_WIDTH) : 0;
}
//------------------------------------------------------------------------------
void SSD1306Ascii::init(const DevType* dev) {
m_col = 0;
m_row = 0;
#ifdef __AVR__
const uint8_t* table = (const uint8_t*)pgm_read_word(&dev->initcmds);
#else // __AVR__
const uint8_t* table =
reinterpret_cast<const uint8_t*>(pgm_read_word(&dev->initcmds));
#else // __AVR__
const uint8_t* table = dev->initcmds;
#endif // __AVR
uint8_t size = readFontByte(&dev->initSize);
Expand Down Expand Up @@ -151,7 +153,7 @@ void SSD1306Ascii::setCursor(uint8_t col, uint8_t row) {
void SSD1306Ascii::setFont(const uint8_t* font) {
m_font = font;
if (font && fontSize() == 1) {
m_letterSpacing = 0;
m_letterSpacing = 0;
} else {
m_letterSpacing = 1;
}
Expand All @@ -162,7 +164,7 @@ void SSD1306Ascii::setRow(uint8_t row) {
m_row = row;
#if INCLUDE_SCROLLING
ssd1306WriteCmd(SSD1306_SETSTARTPAGE | ((m_row + m_pageOffset) & 7));
#else // INCLUDE_SCROLLING
#else // INCLUDE_SCROLLING
ssd1306WriteCmd(SSD1306_SETSTARTPAGE | m_row);
#endif // INCLUDE_SCROLLING
}
Expand All @@ -178,11 +180,11 @@ void SSD1306Ascii::setStartLine(uint8_t line) {
m_startLine = line & 0X3F;
ssd1306WriteCmd(SSD1306_SETSTARTLINE | m_startLine);
}
#endif // INCLUDE_SCROLLING
#endif // INCLUDE_SCROLLING
//------------------------------------------------------------------------------
void SSD1306Ascii::ssd1306WriteRam(uint8_t c) {
if (m_col < m_displayWidth) {
writeDisplay(c^m_invertMask, SSD1306_MODE_RAM);
writeDisplay(c ^ m_invertMask, SSD1306_MODE_RAM);
m_col++;
}
}
Expand All @@ -191,17 +193,13 @@ void SSD1306Ascii::ssd1306WriteRamBuf(uint8_t c) {
if (m_skip) {
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++;
}
}
//------------------------------------------------------------------------------
GLCDFONTDECL(scaledNibble) = {
0X00, 0X03, 0X0C, 0X0F,
0X30, 0X33, 0X3C, 0X3F,
0XC0, 0XC3, 0XCC, 0XCF,
0XF0, 0XF3, 0XFC, 0XFF
};
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;
Expand All @@ -216,7 +214,8 @@ size_t SSD1306Ascii::strWidth(const char* str) const {
}
//------------------------------------------------------------------------------
void SSD1306Ascii::tickerInit(TickerState* state, const uint8_t* font,
uint8_t row, bool mag2X, uint8_t bgnCol, uint8_t endCol) {
uint8_t row, bool mag2X, uint8_t bgnCol,
uint8_t endCol) {
state->font = font;
state->row = row;
state->mag2X = mag2X;
Expand Down Expand Up @@ -250,7 +249,8 @@ int8_t SSD1306Ascii::tickerTick(TickerState* state) {
setFont(state->font);
m_magFactor = state->mag2X ? 2 : 1;
if (state->init) {
clear(state->bgnCol, state->endCol, state->row, state->row + fontRows() -1);
clear(state->bgnCol, state->endCol, state->row,
state->row + fontRows() - 1);
state->col = state->endCol;
state->skip = 0;
state->init = false;
Expand Down Expand Up @@ -305,7 +305,7 @@ size_t SSD1306Ascii::write(uint8_t ch) {
}
uint8_t w = readFontByte(m_font + FONT_WIDTH);
uint8_t h = readFontByte(m_font + FONT_HEIGHT);
uint8_t nr = (h + 7)/8;
uint8_t nr = (h + 7) / 8;
uint8_t first = readFontByte(m_font + FONT_FIRST_CHAR);
uint8_t count = readFontByte(m_font + FONT_CHAR_COUNT);
const uint8_t* base = m_font + FONT_WIDTH_TABLE;
Expand All @@ -316,7 +316,7 @@ size_t SSD1306Ascii::write(uint8_t ch) {
}
if (ch == '\n') {
setCol(0);
uint8_t fr = m_magFactor*nr;
uint8_t fr = m_magFactor * nr;
#if INCLUDE_SCROLLING
uint8_t dr = displayRows();
uint8_t tmpRow = m_row + fr;
Expand All @@ -325,28 +325,34 @@ size_t SSD1306Ascii::write(uint8_t ch) {
setRow(tmpRow);
} else {
m_pageOffset = (m_pageOffset + delta) & 7;
m_row = dr - fr;
m_row = dr - fr;
// Cursor will be positioned by clearToEOL.
clearToEOL();
if (m_scrollMode == SCROLL_MODE_AUTO) {
setStartLine(8*m_pageOffset);
setStartLine(8 * m_pageOffset);
}
}
#else // INCLUDE_SCROLLING
#else // INCLUDE_SCROLLING
setRow(m_row + fr);
#endif // INCLUDE_SCROLLING
return 1;
}
// Error if not in font.
if (ch < first || (first + count) <= ch) {
bool nfSpace = false;
if (first <= ch && ch < (first + count)) {
ch -= first;
} else if (ENABLE_NONFONT_SPACE && ch == ' ') {
nfSpace = true;
} else {
// Error if not in font.
return 0;
}
ch -= first;
uint8_t s = letterSpacing();
uint8_t thieleShift = 0;
if (fontSize() < 2) {
if (nfSpace) {
// non-font space.
} else if (fontSize() < 2) {
// Fixed width font.
base += nr*w*ch;
base += nr * w * ch;
} else {
if (h & 7) {
thieleShift = 8 - (h & 7);
Expand All @@ -356,7 +362,7 @@ size_t SSD1306Ascii::write(uint8_t ch) {
index += readFontByte(base + i);
}
w = readFontByte(base + ch);
base += nr*index + count;
base += nr * index + count;
}
uint8_t scol = m_col;
uint8_t srow = m_row;
Expand All @@ -368,14 +374,14 @@ size_t SSD1306Ascii::write(uint8_t ch) {
setCursor(scol, m_row + 1);
}
for (uint8_t c = 0; c < w; c++) {
uint8_t b = readFontByte(base + c + r*w);
uint8_t b = nfSpace ? 0 : readFontByte(base + c + r * w);
if (thieleShift && (r + 1) == nr) {
b >>= thieleShift;
}
if (m_magFactor == 2) {
b = m ? b >> 4 : b & 0XF;
b = readFontByte(scaledNibble + b);
ssd1306WriteRamBuf(b);
b = m ? b >> 4 : b & 0XF;
b = readFontByte(scaledNibble + b);
ssd1306WriteRamBuf(b);
}
ssd1306WriteRamBuf(b);
}
Expand Down

0 comments on commit c43eaa9

Please sign in to comment.