The out of range check in the drawIcon function is broken as this code illustrates. Using the current
version of drawIcon, the WiFi icon will not be drawn in the center of the lcd display because the range check fails. If the code is changed as shown in the header comment below drawIcon works as expected.
/*
* This code should draw the WiFi Icon in the center of the display
* But there is a bug in the function drawIcon
*
* The line:
* if ((x + iWidth) * scale >= _width || (y + iHeight) * scale >= _height) return;//cannot be
*
* Should probably be this line:
* // if ((x + (iWidth * scale) >= _width) || (y + (iHeight * scale) >= _height)) return;//cannot be
*
*/
#define LCD_CS 4 // D2
#define LCD_DC 0 // D0
#include <SPI.h>
#include <TFT_ST7735.h>
#include "_icons/wifi.c"
// Create instance of LCD display
TFT_ST7735 lcd = TFT_ST7735(LCD_CS, LCD_DC);
// Draw WiFi Icon centered on display
void drawWiFiIcon(uint16_t color) {
int iconWidth = wifi.image_width * 2;
int iconHeight = wifi.image_height * 2;
// Calculate position of icon
int xOffset = (lcd.width() - iconWidth) / 2;
int yOffset = (lcd.height() - iconHeight) / 2;
lcd.drawIcon(xOffset, yOffset, &wifi, 2, color, BLACK, 1);
}
void setup() {
Serial.begin(115200);
delay(1000);
// Start the lcd
lcd.begin();
lcd.clearScreen();
lcd.setRotation(1);
// Display the WiFi logo icon centered on display
drawWiFiIcon(BLUE);
}
void loop() {
// put your main code here, to run repeatedly:
}
The out of range check in the drawIcon function is broken as this code illustrates. Using the current version of drawIcon, the WiFi icon will not be drawn in the center of the lcd display because the range check fails. If the code is changed as shown in the header comment below drawIcon works as expected.