c++ - Declaring multiple instances of a TFT screen class? -
undoubtedly due lack of encyclopedic knowledge of c/c++, have found myself in quagmire while trying initialize multiple instances of tft screen class. tft screen adafruit_ssd1331, , have 1 small sketch control more 1 of these identical code.
these errors i'm getting:
slapbmp.ino:61:5: error: 'tft' in 'class adafruit_ssd1331' not name type slapbmp.ino:62:5: error: 'tft' in 'class adafruit_ssd1331' not name type slapbmp.ino:63:3: error: missing type-name in typedef-declaration
...when try to compile code:
#include <adafruit_gfx.h> #include <adafruit_ssd1331.h> #include <sd.h> #include <spi.h> // if using hardware spi interface, these pins (for future ref) #define sclk 13 #define mosi 11 #define rst 9 #define cs 10 #define dc 8 #define cs2 5 #define dc2 4 // color definitions #define black 0x0000 #define blue 0x001f #define red 0xf800 #define green 0x07e0 #define cyan 0x07ff #define magenta 0xf81f #define yellow 0xffe0 #define white 0xffff // draw images sd card, share hardware spi interface namespace std { typedef struct adafruit_ssd1331 { } tft; } namespace initscreens { typedef struct { adafruit_ssd1331::tft scr1 = adafruit_ssd1331(cs, dc, rst); adafruit_ssd1331::tft scr2 = adafruit_ssd1331(cs2, dc2, rst); }; }; // arduino uno/duemilanove, etc // connect sd card mosi going pin 11, miso going pin 12 , sck going pin 13 (standard) // pin 4 goes cs (or whatever have set up) #define sd_cs 3 // set chip select line whatever use (4 doesnt conflict library) #define sd_cs2 2 // file file bmpfile; // information extract bitmap file int bmpwidth, bmpheight; uint8_t bmpdepth, bmpimageoffset; void setup(void) { //...
just note, i'm trying use struct in way allows me not have modify any*.h files.
this looks issue namespacing. compiler error tells compiler wasn't able find name, reason couldn't because name tft
within std
namespace here. need fix or change how code designed.
given c++ change things few things make use of c++ language features:
//get rid of of #defines const int cs = 10; const int dc = 8; //make struct contain info screens struct screens { adafruit_ssd1331 scr1; adafruit_ssd1331 scr2; screens(): scr1(cs, dc, rst), scr2(cs2, dc2, rst) { } };
then can instantiate class once in setup
if using arduino convention. (or place somewhere appropriate before enter main loop)
Comments
Post a Comment