I'm writing a library for Arduino. This library has to use the existing TFT_eSPI library. When I try to compile the following I get
/.../sketch/src/Display/Display.cpp: In static member function 'static void Display::begin()': /.../sketch/src/Display/Display.cpp:16:9: error: use of deleted function 'TFT_eSPI& TFT_eSPI::operator=(TFT_eSPI&&)' tft = TFT_eSPI(); ^ In file included from /.../sketch/src/Display/Display.h:12:0, from /.../sketch/src/Display/Display.cpp:9: /Users/luigisc/Documents/Arduino/libraries/TFT_eSPI/TFT_eSPI.h:359:7: note: 'TFT_eSPI& TFT_eSPI::operator=(TFT_eSPI&&)' is implicitly deleted because the default definition would be ill-formed: class TFT_eSPI : public Print { ^ /Users/luigisc/Documents/Arduino/libraries/TFT_eSPI/TFT_eSPI.h:359:7: error: non-static reference member 'fs::FS& TFT_eSPI::fontFS', can't use default assignment operator
Display.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);
}
}
Display.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
Edit
I reported all the code, also the function drawGif that need to be static.
CodePudding user response:
It seems like the TFT_eSPI instance doesn't belong in your Display class at all. You seem to use Display similar to a namespace since it only has static members (both variables and functions).
If you only want one single TFT_eSPI instance everywhere, you could create a free function returning a TFT_eSPI& to that one instance. Example:
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;
}
Then in all places where you now do tft.something() you instead do tft().something(). The AnimatedGIF instance could be handled the same way.
Display could also be made into namespace Display and all the current member functions could be made into free functions in that namespace since Display does not keep any internal state.
