From 2cea42bad188e931d0fe2d7ee1d23aaefbed2e54 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 30 Jan 2021 23:09:38 +0100 Subject: [PATCH] more cppcheck fixes --- lib/Display/Bitmap.cpp | 27 +++++++++++++++++++++++++-- lib/Display/OLEDDisplay.cpp | 19 ++++++++++++++----- lib/Display/SSD1306.h | 1 - platformio.ini | 2 +- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/lib/Display/Bitmap.cpp b/lib/Display/Bitmap.cpp index b8374b5..b8518b8 100644 --- a/lib/Display/Bitmap.cpp +++ b/lib/Display/Bitmap.cpp @@ -3,18 +3,21 @@ #include "FontConfig.h" //#include "OLEDDisplayFonts.h" +// cppcheck-suppress unusedFunction Bitmap::Bitmap(uint width, uint height) : _width(width), _height(height), _buffer(0) { allocateBuffer(); } +// cppcheck-suppress unusedFunction Bitmap::Bitmap(OLEDDisplay * display) : _width(display->getWidth()), _height(display->getHeight()), _buffer(0) { allocateBuffer(); } +// cppcheck-suppress unusedFunction Bitmap::~Bitmap() { if(_buffer != 0) @@ -23,16 +26,19 @@ Bitmap::~Bitmap() } } +// cppcheck-suppress unusedFunction uint Bitmap::getWidth() const { return _width; } +// cppcheck-suppress unusedFunction uint Bitmap::getHeight() const { return _height; } +// cppcheck-suppress unusedFunction void Bitmap::setPixel(int x, int y) { if(x >= 0 && x < _width && y >= 0 && y < _height) @@ -41,6 +47,7 @@ void Bitmap::setPixel(int x, int y) } } +// cppcheck-suppress unusedFunction void Bitmap::clearPixel(int x, int y) { if(x >= 0 && x < _width && y >= 0 && y < _height) @@ -49,6 +56,7 @@ void Bitmap::clearPixel(int x, int y) } } +// cppcheck-suppress unusedFunction bool Bitmap::getPixel(int x, int y) const { if(x >= 0 && x < _width && y >= 0 && y < _height) @@ -58,11 +66,13 @@ bool Bitmap::getPixel(int x, int y) const return false; } +// cppcheck-suppress unusedFunction void Bitmap::clear() { memset(_buffer, 0, _width * _height / 8); } +// cppcheck-suppress unusedFunction void Bitmap::drawLine(int x0, int y0, int x1, int y1) { int dx = abs(x1 - x0); @@ -70,7 +80,6 @@ void Bitmap::drawLine(int x0, int y0, int x1, int y1) int sx = x0 < x1 ? 1 : -1; int sy = y0 < y1 ? 1 : -1; int err = (dx > dy ? dx : -dy) / 2; - int e2; while(true) { @@ -78,7 +87,7 @@ void Bitmap::drawLine(int x0, int y0, int x1, int y1) if(x0 == x1 && y0 == y1) break; - e2 = err; + int e2 = err; if(e2 > -dx) { err -= dy; @@ -92,6 +101,7 @@ void Bitmap::drawLine(int x0, int y0, int x1, int y1) } } +// cppcheck-suppress unusedFunction void Bitmap::drawHorizontalLine(int x, int y, int length) { if(y < 0 || y >= _height) @@ -105,6 +115,7 @@ void Bitmap::drawHorizontalLine(int x, int y, int length) } } +// cppcheck-suppress unusedFunction void Bitmap::drawVerticalLine(int x, int y, int length) { if (x < 0 || x >= _width) @@ -118,6 +129,7 @@ void Bitmap::drawVerticalLine(int x, int y, int length) } } +// cppcheck-suppress unusedFunction void Bitmap::drawRect(int x, int y, int width, int height) { drawHorizontalLine(x, y, width); @@ -126,6 +138,7 @@ void Bitmap::drawRect(int x, int y, int width, int height) drawHorizontalLine(x, y + height - 1, width); } +// cppcheck-suppress unusedFunction void Bitmap::fillRect(int x, int y, int width, int height) { for (int i = 0; i < width; i++) @@ -134,6 +147,7 @@ void Bitmap::fillRect(int x, int y, int width, int height) } } +// cppcheck-suppress unusedFunction void Bitmap::drawCircle(int x0, int y0, int radius) { int x = 0; @@ -168,6 +182,7 @@ void Bitmap::drawCircle(int x0, int y0, int radius) setPixel(x0, y0 - radius); } +// cppcheck-suppress unusedFunction void Bitmap::fillCircle(int x0, int y0, int radius) { int x = 0; @@ -195,6 +210,7 @@ void Bitmap::fillCircle(int x0, int y0, int radius) drawHorizontalLine(x0 - radius, y0, 2 * radius); } +// cppcheck-suppress unusedFunction void Bitmap::drawCircleQuads(int x0, int y0, int radius, int quads) { int x = 0; @@ -251,6 +267,7 @@ void Bitmap::drawCircleQuads(int x0, int y0, int radius, int quads) } } +// cppcheck-suppress unusedFunction void Bitmap::drawProgressBar(int x, int y, int width, int height, int progress) { int radius = height / 2; @@ -271,6 +288,7 @@ void Bitmap::drawProgressBar(int x, int y, int width, int height, int progress) fillCircle(xRadius + maxProgressWidth, yRadius, innerRadius); } +// cppcheck-suppress unusedFunction int Bitmap::drawChar(int x, int y, char c) { fontDesc_t const * font = getSystemFont(); @@ -322,6 +340,7 @@ int Bitmap::drawChar(int x, int y, char c) return x + FONT_CHAR_SPACING; } +// cppcheck-suppress unusedFunction int Bitmap::drawString(int x, int y, String text) { int next_x = x; @@ -332,6 +351,7 @@ int Bitmap::drawString(int x, int y, String text) return next_x; } +// cppcheck-suppress unusedFunction void Bitmap::drawStringf(int x, int y, char * buffer, String format, ... ) { va_list myargs; @@ -341,6 +361,7 @@ void Bitmap::drawStringf(int x, int y, char * buffer, String format, ... ) drawString(x, y, buffer); } +// cppcheck-suppress unusedFunction int Bitmap::drawStringLF(int x, int y, String text) { fontDesc_t const * font = getSystemFont(); @@ -357,6 +378,7 @@ int Bitmap::drawStringLF(int x, int y, String text) return next_x; } +// cppcheck-suppress unusedFunction void Bitmap::drawStringLFf(int x, int y, char * buffer, String format, ... ) { va_list myargs; @@ -394,6 +416,7 @@ void Bitmap::drawStringLFf(int x, int y, char * buffer, String format, ... ) } }*/ +// cppcheck-suppress unusedFunction void Bitmap::allocateBuffer() { _buffer = new uint8_t[_width * _height / 8]; diff --git a/lib/Display/OLEDDisplay.cpp b/lib/Display/OLEDDisplay.cpp index c5d0869..2bc7db8 100644 --- a/lib/Display/OLEDDisplay.cpp +++ b/lib/Display/OLEDDisplay.cpp @@ -40,26 +40,31 @@ OLEDDisplay::~OLEDDisplay() { } +// cppcheck-suppress unusedFunction void OLEDDisplay::displayOn() { sendCommand(DISPLAYON); } +// cppcheck-suppress unusedFunction void OLEDDisplay::displayOff() { sendCommand(DISPLAYOFF); } +// cppcheck-suppress unusedFunction void OLEDDisplay::invertDisplay() { sendCommand(INVERTDISPLAY); } +// cppcheck-suppress unusedFunction void OLEDDisplay::normalDisplay() { sendCommand(NORMALDISPLAY); } +// cppcheck-suppress unusedFunction void OLEDDisplay::setContrast(uint8_t contrast, uint8_t precharge, uint8_t comdetect) { sendCommand(SETPRECHARGE); //0xD9 @@ -73,18 +78,15 @@ void OLEDDisplay::setContrast(uint8_t contrast, uint8_t precharge, uint8_t comde sendCommand(DISPLAYON); } +// cppcheck-suppress unusedFunction void OLEDDisplay::setBrightness(uint8_t brightness) { - uint8_t contrast = brightness; + uint8_t contrast = brightness * 1.171 - 43; if (brightness < 128) { // Magic values to get a smooth/ step-free transition contrast = brightness * 1.171; } - else - { - contrast = brightness * 1.171 - 43; - } uint8_t precharge = 241; if (brightness == 0) @@ -95,28 +97,33 @@ void OLEDDisplay::setBrightness(uint8_t brightness) setContrast(contrast, precharge, comdetect); } +// cppcheck-suppress unusedFunction void OLEDDisplay::resetOrientation() { sendCommand(SEGREMAP); sendCommand(COMSCANINC); } +// cppcheck-suppress unusedFunction void OLEDDisplay::flipScreenVertically() { sendCommand(SEGREMAP | 0x01); sendCommand(COMSCANDEC); } +// cppcheck-suppress unusedFunction void OLEDDisplay::mirrorScreen() { sendCommand(SEGREMAP); sendCommand(COMSCANDEC); } +// cppcheck-suppress unusedFunction void OLEDDisplay::clear() { } +// cppcheck-suppress unusedFunction uint OLEDDisplay::getWidth() { switch(_geometry) @@ -131,6 +138,7 @@ uint OLEDDisplay::getWidth() return 0; } +// cppcheck-suppress unusedFunction uint OLEDDisplay::getHeight() { switch(_geometry) @@ -146,6 +154,7 @@ uint OLEDDisplay::getHeight() return 0; } +// cppcheck-suppress unusedFunction void OLEDDisplay::sendInitCommands() { sendCommand(DISPLAYOFF); diff --git a/lib/Display/SSD1306.h b/lib/Display/SSD1306.h index fe4b1d5..01d2032 100644 --- a/lib/Display/SSD1306.h +++ b/lib/Display/SSD1306.h @@ -46,7 +46,6 @@ private: TwoWire * _wire = NULL; uint8_t _address; bool _doI2cAutoInit = false; - int _frequency; virtual void sendCommand(uint8_t command) override; }; diff --git a/platformio.ini b/platformio.ini index f53dc1f..c150286 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,7 +12,7 @@ lib_deps = peterus/ESP-FTP-Server-Lib @ 0.9.5 check_tool = cppcheck check_flags = - cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK --force lib -ilib/TimeLib -ilib/LoRa -ilib/NTPClient -ilib/Display + cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK --force lib -ilib/TimeLib -ilib/LoRa -ilib/NTPClient check_skip_packages = yes #monitor_flags = --raw # activate for OTA Update, use the CALLSIGN from is-cfg.json as upload_port: