代码之家  ›  专栏  ›  技术社区  ›  rball

为什么渲染速度这么慢?

  •  1
  • rball  · 技术社区  · 6 年前

    代码如下。我用的是带羽毛翼TFT显示屏的Adafuit Huzzah羽毛。我正在尝试创建一个简单的GUI,上面有几个按钮。最初显示的按钮非常快,至少据我所知。当我点击触摸屏进入一个新的“页面”时,我可以看到这个矩形被绘制了一秒钟,然后用我正在绘制的新按钮也可以看到相同的东西。这件事应该这么慢还是我做了那么蠢的事?我甚至在使用“更快”的TFT-ESPI库。对于其他示例,如按钮,显示更新非常快。有什么想法吗?

    #include <SPI.h>
    #include <Wire.h>      // this is needed even tho we aren't using it
    #include <ESP8266WiFi.h>
    #include "FS.h"
    #include <TFT_eSPI.h>    // Core graphics library
    #include <Adafruit_STMPE610.h> // Touchscreen Controller
    
    #define CALIBRATION_FILE "/TouchCalData3"
    #define REPEAT_CAL false
    #define TS_MINX 3800
    #define TS_MAXX 100
    #define TS_MINY 100
    #define TS_MAXY 3750
    
    const char *ssid = "AP"; // The name of the Wi-Fi network that will be created
    const char *password = "changeme";   // The password required to connect to it, leave blank for an open network
    Adafruit_STMPE610 ts = Adafruit_STMPE610(16);
    
    int currentPage = 0;
    bool allSelected = true;
    
    TFT_eSPI tft = TFT_eSPI();  // Invoke library, pins defined in User_Setup.h
    void setup(void) {
      Serial.begin(115200);
    
      delay(10);  
    
      if (!ts.begin()) {
        Serial.println("Couldn't start touchscreen controller");
        while (1);
      }
      Serial.println("Touchscreen started");
    
      tft.init();
      tft.setRotation(0);
    
      setupAp();
      drawHomePage();
    }
    
    void drawHomePage() { 
      wipe();
      Serial.println("Drawing HP");
    
      long time1 = millis();
      tft.drawRoundRect(10, 10, 220, 145, 7, ILI9341_WHITE);
      tft.drawCentreString("LIGHTS", 120, 60, 2);
    
      tft.drawRoundRect(10, 165, 220, 145, 7, ILI9341_YELLOW);
      tft.setTextColor(ILI9341_YELLOW);
      tft.drawCentreString("GAUGES", 120, 220, 2);
    
      long time2 = millis();
      long result = time2 - time1;
      Serial.print("HP Took: "); Serial.println(result);
    }
    
    void drawLightsHomePage() {
      wipe();
      Serial.println("Drawing Lights");
      long time1 = millis();
    
      if(allSelected) {
        tft.fillRect(10, 10, 58, 52, ILI9341_WHITE);
        tft.setTextColor(ILI9341_BLACK);
        tft.drawCentreString("All", 34, 20, 2);
      }
      else {
        tft.drawRect(10, 10, 68, 52, ILI9341_WHITE);
        tft.setTextColor(ILI9341_WHITE);
        tft.drawCentreString("All", 34, 60, 2);
      }
    
      long time2 = millis();
      long result = time2 - time1;
      Serial.print("Lights Took: "); Serial.println(result);
    }
    
    void wipe() {
      long time1 = millis();
      Serial.println("Wiping screen");
      tft.fillRect(0, 0, 240, 320, ILI9341_BLACK);
      long time2 = millis();
      long result = time2 - time1;
      Serial.print("Wiping took: "); Serial.println(result);
    }
    
    void loop() {
      // Retrieve a point  
      TS_Point p = ts.getPoint();
    
      if (ts.bufferSize()) {
        p = ts.getPoint(); 
      } else {    
        p.x = p.y = p.z = -1;// this is our way of tracking touch 'release'!
      }
    
      if (p.z != -1) {
        tft.fillCircle(p.x, p.y, 2, TFT_WHITE);
        p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
        p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
        Serial.print("("); Serial.print(p.x); Serial.print(", "); 
        Serial.print(p.y); Serial.print(", "); 
        Serial.print(p.z); Serial.println(") ");
    
        if(currentPage == 0) {
          if(p.y < 160) {
            Serial.println("Hit Button");
            currentPage = 1;
            drawLightsHomePage();
          }
          else if(p.y > 160 && p.y < 320) {
          }
        }
      }
    }
    
    void setupAp() {
      Serial.println('\n');
    
      WiFi.softAP(ssid, password);             // Start the access point
      Serial.print("Access Point \"");
      Serial.print(ssid);
      Serial.println("\" started");
    
      Serial.print("IP address:\t");
      Serial.println(WiFi.softAPIP());         // Send the IP address of the ESP8266 to the computer
    }
    

    下面是时间的输出示例,但我可以发誓,即使绘制按钮也要花半秒钟的时间。太痛苦了!

    Wiping screen
    Wiping took: 48
    Drawing HP
    HP Took: 6
    (109, 111, 50)
    Hit Button
    Wiping screen
    Wiping took: 1234
    Drawing Lights
    Lights Took: 52
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   rball    6 年前

    读完后,简单的答案是:因为硬件/库的速度太慢了。