Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in the drawIcon function #10

Open
ghost opened this issue Dec 20, 2016 · 0 comments
Open

Bug in the drawIcon function #10

ghost opened this issue Dec 20, 2016 · 0 comments

Comments

@ghost
Copy link

ghost commented Dec 20, 2016

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:

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants