簡體   English   中英

Arduino庫錯誤:使用已刪除的function

[英]Arduino library error: use of deleted function

我正在為 Arduino 編寫一個庫。 該庫必須使用現有的 TFT_eSPI 庫。 當我嘗試編譯以下內容時,我得到

/.../sketch/src/Display/Display.cpp: 在 static 成員 function 'static void Display::begin()': /.../sketch/src/Display/Display.cpp:16:9: 錯誤: 使用已刪除的 function 'TFT_eSPI& TFT_eSPI::operator=(TFT_eSPI&&)' tft = TFT_eSPI(); ^ 在 /.../sketch/src/Display/Display.h:12:0 包含的文件中,來自 /.../sketch/src/Display/Display.cpp:9: /Users/luigisc/Documents/Arduino /libraries/TFT_eSPI/TFT_eSPI.h:359:7:注意:'TFT_eSPI& TFT_eSPI::operator=(TFT_eSPI&&)' 被隱式刪除,因為默認定義格式不正確:class TFT_eSPI: public Print { ^ /Users/luigisc /Documents/Arduino/libraries/TFT_eSPI/TFT_eSPI.h:359:7:錯誤:非靜態引用成員 'fs::FS& TFT_eSPI::fontFS',不能使用默認賦值運算符

顯示.cpp

#include "Arduino.h"
#include "Display.h"

/*Global objects' declaration and initialization*/

void Display::begin(){
    //Display initializing
    tft = TFT_eSPI();

    tft.fillScreen(TFT_BLACK);
    tft.setTextColor(TFT_WHITE);
    tft.setTextSize(2);
    tft.setRotation(1);

}

// PRIVATE FUNCTIONS

void Display::drawGIF(GIFDRAW *pDraw){
    uint8_t *s;
    uint16_t *d, *usPalette, usTemp[320];
    int x, y, iWidth;

    iWidth = pDraw->iWidth;
    if (iWidth > tft.width())
        iWidth = tft.width();
    usPalette = pDraw->pPalette;
    y = pDraw->iY + pDraw->y; // current line

    s = pDraw->pPixels;
    if (pDraw->ucDisposalMethod == 2) // restore to background color
    {
        for (x=0; x<iWidth; x++)
        {
            if (s[x] == pDraw->ucTransparent)
                s[x] = pDraw->ucBackground;
        }
        pDraw->ucHasTransparency = 0;
    }
    // Apply the new pixels to the main image
    if (pDraw->ucHasTransparency) // if transparency used
    {
        uint8_t *pEnd, c, ucTransparent = pDraw->ucTransparent;
        int x, iCount;
        pEnd = s + iWidth;
        x = 0;
        iCount = 0; // count non-transparent pixels
        while(x < iWidth)
        {
            c = ucTransparent-1;
            d = usTemp;
            while (c != ucTransparent && s < pEnd)
            {
                c = *s++;
                if (c == ucTransparent) // done, stop
                {
                    s--; // back up to treat it like transparent
                }
                else // opaque
                {
                    *d++ = usPalette[c];
                    iCount++;
                }
            } // while looking for opaque pixels
            if (iCount) // any opaque pixels?
            {
                tft.setAddrWindow(pDraw->iX+x, y, iCount, 1);
                tft.startWrite();
                tft.pushPixels(usTemp, iCount);
                tft.endWrite();
                x += iCount;
                iCount = 0;
            }
            // no, look for a run of transparent pixels
            c = ucTransparent;
            while (c == ucTransparent && s < pEnd)
            {
                c = *s++;
                if (c == ucTransparent)
                    iCount++;
                else
                    s--;
            }
            if (iCount)
            {
                x += iCount; // skip these
                iCount = 0;
            }
        }
    }
    else
    {
        s = pDraw->pPixels;
        // Translate the 8-bit pixels through the RGB565 palette (already byte reversed)
        for (x=0; x<iWidth; x++)
            usTemp[x] = usPalette[*s++];
        tft.setAddrWindow(pDraw->iX, y, iWidth, 1);
        tft.startWrite();
        tft.pushPixels(usTemp, iWidth);
        tft.endWrite();
    }
}

// PUBLIC FUNCTIONS

void Display::displayGIF(const uint8_t *gif_file, int gif_size, int nTimes){

    if (gif.open((uint8_t *)gif_file, gif_size, drawGIF)){

        for(int i=0;i<nTimes;i++){
            gif.playFrame(true, NULL);
            while(gif.playFrame(true, NULL)){}
        }

        gif.close();

    }else{
        tft.fillScreen(TFT_BLACK);
        tft.setTextColor(TFT_WHITE);
        tft.setTextSize(2);
        tft.drawString("ERR: Can't load GIF", 0, tft.width()/2);
    }

}   

顯示.h

#ifndef DISPLAY_H
#define DISPLAY_H

#include "Arduino.h"
#include <TFT_eSPI.h>
#include <AnimatedGIF.h>

class Display {

  public:
    static void begin();
    static void displayGIF(const uint8_t *gif_file, int gif_size, int nTimes);

  private:
    static void drawGIF(GIFDRAW *pDraw);
    static AnimatedGIF gif;
    static TFT_eSPI tft;

};

#endif

編輯

我報告了所有代碼,還有需要 static 的 function drawGif。

似乎TFT_eSPI實例根本不屬於您的Display class 。 您似乎使用Display類似於namespace ,因為它只有static成員(變量和函數)。

如果您只想要一個單一TFT_eSPI實例,您可以創建一個免費的 function 將TFT_eSPI&返回給該實例。 例子:

Display.h

class Display {
    // static TFT_eSPI tft; // remove this
};

TFT_eSPI& tft();            // add a declaration of a free function

Display.cpp

void Display::begin(){
    //Display initializing
    //tft = TFT_eSPI();     // remove this
}

TFT_eSPI& tft() {           // add definition of the free function
    static TFT_eSPI instance;
    return instance;
}

然后在您現在執行tft.something()的所有地方,您改為執行tft().something() AnimatedGIF實例可以以同樣的方式處理。

Display也可以做成namespace Display ,並且所有當前的成員函數都可以做成該命名空間中的自由函數,因為Display不保留任何內部 state。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM