"case-sensitive" including libs and syntax rules ?


hi,
i have question "case-sensitive" including libs , syntax rules :

i'm using different tfts different tft libs require different tft print/draw cmds.

my current (poor) appraoch following - requiring lot of memory libs #included plus related ram load , store them....
is there smater way it?
(my perhaps faulty approaches  using
#if defined...
#elif defined...
#elif defined...
#elif defined...
#endif

didn't work, unfortunately... :( ) :



fu**ing 900 char limit!!!

code part 1 because of effing 9000 char limit:

code: [select]

#include <spi.h>
#include <sd.h>


// tft lcd


#define   utft_smallfont     8 // utft 8x10
#define   utft_mediumfont   12 // utft ++
#define   utft_bigfont      18 // utft +++
#define   _smallfont_        1 // 9341 6x9
#define   _mediumfont_       2 // 9341 12x16
#define   _bigfont_          3 // 9341 18x23

int16_t  lcdmaxx , lcdmaxy ;                // display size
int16_t  _curx_, _cury_,                    // last x,y cursor pos on tft screen
         _maxx_, _maxy_;                    // max. x,y cursor pos on tft screen       
char     wspace[128];                       // line of white space


// set lcd tft type
int16_t  lcdtype   =   -1;

#define  _lcd1602_    1  // lcd1602  hitachi hd44780 driver <liquidcrystal.h>
                           // http://www.arduino.cc/en/tutorial/liquidcrystal   //
#define  _serlcd_     2  // sparkfun serlcd 16x2 
                           // http://playground.arduino.cc/code/serlcd   //
#define  _utft_       4  // henning karlsen utft 2.2-2.4" 220x176 - 320x240 lib
                           // http://henningkarlsen.com/electronics/library.php?id=51   //
#define _ili9341_     8  // https://github.com/adafruit/adafruit_ili9340
                           // https://github.com/adafruit/adafruit-gfx-library //
#define _ili9341due_  9  // ili9341_due new lib marek buriak
                           // http://marekburiak.github.io/ili9341_due/ //
                           
-
#define    tft_cs     49
#define    tft_dc     48
#define    tft_rst     0                       
                         

// utft henning karlsen

#include <utftqd.h>

utft   qdutft(qd220a, _megamosi_,_megasck_,tft_cs , 0,      49);   // a0->vc (led), a4->boardreset
 extern  uint8_t smallfont[];

// tft adafruit lil9340/ili9341

#include <adafruit_gfx.h>
#include <adafruit_ili9340.h>

adafruit_ili9340  tft = adafruit_ili9340(tft_cs, tft_dc, tft_rst);



// tft ili9341_due //
41_due_config.h>
#include <ili9341_due.h>
#include <systemfont5x7.h>

ili9341_due      dtft = ili9341_due(tft_cs, tft_dc, tft_rst);

// color set
#define  black           0x0000
#define red             0xf800
#define green           0x07e0
//#define blue            0x001f
#define blue            0x102e
#define cyan            0x07ff
#define magenta         0xf81f
#define yellow          0xffe0
#define orange          0xfd20
#define greenyellow     0xafe5
#define darkgreen       0x03e0
#define white           0xffff

uint16_t  color;



#define  lcdwhiteblack()  {                                                                 \
   if(lcdtype==_utft_)      { qdutft.setcolor(255,255,255); qdutft.setbackcolor(  0,  0,  0);} \
   else if(lcdtype==_ili9341_)   { tft.settextcolor(ili9340_white, ili9340_black) ;} \
   else if(lcdtype==_ili9341due_)   { dtft.settextcolor(white, black) ;} \
}

#define  lcdnormal()      {                                                                 \
   if(lcdtype==_utft_)      { qdutft.setcolor(255,255,255); qdutft.setbackcolor(  0,  0,  0);} \
   else if(lcdtype==_ili9341_)   { tft.settextcolor(ili9340_white, ili9340_black) ;} \
   else if(lcdtype==_ili9341due_)   { dtft.settextcolor(white, black) ;} \
}

#define  lcdinvers()      {                                                                 \
   if(lcdtype==_utft_)      { qdutft.setcolor(  0,  0,  0); qdutft.setbackcolor(255,255,255);} \
   else if(lcdtype==_ili9341_)   { tft.settextcolor(ili9340_black, ili9340_white) ;} \
   else if(lcdtype==_ili9341due_)   { dtft.settextcolor(black, white) ;} \
}

#define  lcdwhitered()    {                                                                 \
   if(lcdtype==_utft_)      { qdutft.setcolor(255,255,255); qdutft.setbackcolor(255,  0,  0);} \
   else if(lcdtype==_ili9341_)   { tft.settextcolor(ili9340_white, ili9340_red) ;} \
   else if(lcdtype==_ili9341due_)   { dtft.settextcolor(white, red) ;} \
}

#define  lcdredblack()    {                                                                 \   
   if(lcdtype==_utft_)      { qdutft.setcolor(255,  0,  0); qdutft.setbackcolor(  0,  0,  0);} \
   else if(lcdtype==_ili9341_)   { tft.settextcolor(ili9340_red, ili9340_black) ;} \
   else if(lcdtype==_ili9341due_)   { dtft.settextcolor(red, black) ;} \
}

#define  lcdyellowblue()  {                                                                 \     
   if(lcdtype==_utft_)      { qdutft.setcolor(255,255,  0); qdutft.setbackcolor( 64, 64, 64);} \
   else if(lcdtype==_ili9341_)   { tft.settextcolor(ili9340_yellow, ili9340_blue);} \
   else if(lcdtype==_ili9341due_)   { dtft.settextcolor(yellow, blue);} \
}

int16_t  fontwi= 8;  // default
int16_t  fonthi=10;  // default


void putfonttype(uint8_t fsize) {
  if(lcdtype==_utft_)  { fontwi= qdutft.getfontxsize(); fonthi=qdutft.getfontysize(); }
  else
  if(lcdtype==_ili9341_) {
     if(fsize==_smallfont_)     { fontwi= 6; fonthi=9; }  // 5x7 + overhead
     else
     if(fsize==_mediumfont_)    { fontwi=12; fonthi=16; } // ?
     else
     if(fsize==_bigfont_)       { fontwi=18; fonthi=23; } // ?
  }
  else
  if(lcdtype==_ili9341due_) {
     if(fsize==_smallfont_)     { fontwi= 6; fonthi=9; }  // 5x7 + overhead
  }
  _maxx_ = lcdmaxx / fontwi;    // max number of letters x>>
  _maxy_ = lcdmaxy / fonthi;    // max number of letters y^^
  memset(wspace, ' ', _maxx_);  // line of white space
  wspace[_maxx_]='\0';
}


void setlcdorient(int16_t orient) {
 
  if(lcdtype==_ili9341_) {
      tft.setrotation(orient);
      lcdmaxx=tft.width();
      lcdmaxy=tft.height();       
   }
   else
   if(lcdtype==_ili9341due_) {
      if(orient==0) dtft.setrotation(ilirotation0);
      else
      if(orient==1) dtft.setrotation(ilirotation90);
      else
      if(orient==2) dtft.setrotation(ilirotation180);
      else
      if(orient==3) dtft.setrotation(ilirotation270);
      lcdmaxx=dtft.width();
      lcdmaxy=dtft.height();   
   }
     
}

void lcdcls()  {                                                         
   if(lcdtype==_utft_)       { qdutft.clrscr();                } 
   else
   if(lcdtype==_ili9341_)    { tft.fillscreen(ili9340_black);  }
   else
   if(lcdtype==_ili9341due_) { dtft.fillscreen(black);  }
   _curx_ =0;  _cury_ =0;
}

void curlf()   {                                                       
   _curx_=0;
   if( _cury_ <=(lcdmaxy-10) ) _cury_+=fonthi;
   else _cury_=0;
     
   if(lcdtype==_ili9341_)    {tft.setcursor(0, _cury_); } 
   else
   if(lcdtype==_ili9341due_) {_cury_+=fonthi; dtft.cursortoxy(0, _cury_); } 
}



void curxy(int16_t  x,  int16_t  y) {
   _curx_ = x;
   _cury_ = y;
   if(lcdtype==_ili9341_)      {tft.setcursor(x, y); }
   else
   if(lcdtype==_ili9341due_)   {dtft.cursortoxy(x, y); }
}



void lcdprintxy(int16_t x, int16_t y, char * str) {
   if(lcdtype==_utft_)          {
     qdutft.print(str,x,y);
     _curx_=x+strlen(str)*fontwi;
     _cury_=y;
   }
   else if(lcdtype==_ili9341_)  {
      tft.setcursor(x,y);     
      tft.print(str);
      _curx_=tft.getcursorx();
      _cury_=tft.getcursory();
   }
   else if(lcdtype==_ili9341due_)  {
      dtft.cursortoxy(x,y);     
      dtft.print(str);
      _curx_=x+strlen(str)*fontwi;
      _cury_=y;
   }
}


void lcdprint(char * str) {
    if(lcdtype==_utft_)     { qdutft.print(str, _curx_, _cury_); _curx_=_curx_+strlen(str)*fontwi; }
    else if(lcdtype==_ili9341_)  {
       tft.setcursor(_curx_, _cury_);
       tft.print(str);
       _curx_=tft.getcursorx();
       _cury_=tft.getcursory();
    }
    else if(lcdtype==_ili9341due_)  {
       dtft.cursortoxy(_curx_, _cury_);
       dtft.print(str);
       _curx_=_curx_+strlen(str)*fontwi;
    }
}







Arduino Forum > Using Arduino > Programming Questions > "case-sensitive" including libs and syntax rules ?


arduino

Comments