0

Adafruit_GFX stringArrayError
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit_GFX stringArrayError

by asteroid on Wed Jan 09, 2019 11:11 pm

When running this code:

Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
#include <Wire.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "Adafruit_FT6206.h"

// Default values for Adafruit shield v2.
#define TFT_DC 9
#define TFT_CS 10

// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
Adafruit_GFX_Button btn[8];

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

 const byte row = 4;
 const byte col = 2;

 #define _numBtns row*col
 #define _rotation 0 //(0->3)
// Rotations 0,2 = portrait  : 0->USB=right,upper : 2->USB=left,lower
// Rotations 1,3 = landscape : 1->USB=left,upper  : 3->USB=right,lower

int x, y;
TS_Point p;
unsigned btnColor[_numBtns] = {WHITE,BLUE,RED,GREEN,CYAN,MAGENTA,YELLOW,WHITE};
char *titleStr[_numBtns] = {"AA","BB","CC","DD","EE","FF","GG","HH"};

 void showZeroZero()
 {
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("0,0");
 }
 
void btnHandler(int btnHit )
 {
  // inverted
  btn[btnHit].drawButton(true);
  tft.setCursor(10, 30);
  tft.setTextSize(2);
  tft.setTextColor(WHITE, BLUE);
  tft.print("btn hit = ");
  tft.print(btnHit);
  delay(100);
  // normal
  btn[btnHit].drawButton(false);
 }
 
void btnGrid(){
   int left, top;   
   int l = 20;
   int t = 60;
   int w = 80;
   int h = 40;
   byte hgap = 15;
   byte vgap = 15;
   byte id = 0;
   for(byte j = 0; j < row; j++){
     for (byte i = 0; i < col; i++){
       left = l + i*(w + vgap);
       top = t + j*(h + hgap);
       btn[id].initButtonUL( &tft, left, top, w, h, BLACK, btnColor[id], BLACK, titleStr[id], 3 );
       btn[id].drawButton(false);
       id++;
      }
    }
 }
 
 void setup() {
  Serial.begin(9600);
 tft.begin();
 if (! ctp.begin()) {  // pass in 'sensitivity' coefficient
   Serial.println("Couldn't start FT6206 touchscreen controller");
  while (1);
  }
  tft.setRotation(_rotation);
  tft.fillScreen(BLUE);
  btnGrid();
  showZeroZero();
 }

 void loop() {

 if (! ctp.touched()) { 
    return;
 }
 
  p = ctp.getPoint();

 switch (_rotation) {
  case 0:
   x = 240 - p.x;
   y = 320 - p.y;
  break;
  case 1:   // p.x, p.y reversed
   x = 320 - p.y;
   y = p.x;
  break;
  case 2:
   x = p.x;
   y = p.y;
  break;
  case 3:  // p.x, p.y reversed
   x = p.y;
   y = 240 - p.x;
  break;
 }
 
  while (ctp.touched()) {
   for (int z = 0; z < _numBtns; z++) {
    if (btn[z].contains(x,y)) {
      btn[z].press(true);
    } else {
      btn[z].press(false);   
    }
    if (btn[z].isPressed()) {     
      btnHandler(z);
    } 
   }         
  }
}

I get this error:
err.png
err.png (12.34 KiB) Viewed 79 times


If I change char * to const char* in the method initButtonUL (would also need to be changed for 'classic' initButton) in both Adafruit_GFX.h and Adafruit_GFX.cpp as well as the line for titleStr{} in the demo above it runs without error.

asteroid
 
Posts: 295
Joined: Tue Oct 22, 2013 9:10 pm

Re: Adafruit_GFX stringArrayError

by adafruit_support_bill on Thu Jan 10, 2019 7:27 am

I get this error:

That is a warning - not an error. A warning will not prevent your code from compiling and uploading.

The code in question was developed using an earlier version of the compiler. The C++ committee has decided that certain coding practices that have existed since the invention of the C language are potentially dangerous if misused and have decided to discourage their use. So recent versions of the compiler generate these warnings. Changing "char *" to "const char *" does not alter the generated machine code in any way.

adafruit_support_bill
 
Posts: 71774
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit_GFX stringArrayError

by jim_lee on Sun Jan 13, 2019 12:22 am

We should figure out how to get the c++ committee working on their own new and exiting language.

Then they can leave ours alone..

-jim lee

jim_lee
 
Posts: 456
Joined: Thu May 24, 2012 8:24 pm

Re: Adafruit_GFX stringArrayError

by adafruit_support_bill on Sun Jan 13, 2019 8:35 am

We should figure out how to get the c++ committee working on their own new and exiting language.

Then they can leave ours alone..

I tend to agree. Although features like strong typing and restrictions on the use of pointers do help to make the code more portable across platforms and protect against many kinds of programming errors, they also take away some useful programming techniques. And on resource constrained microcontrollers like the Arduino, sometimes is is necessary to break a few programming style rules to achieve more efficient code.

adafruit_support_bill
 
Posts: 71774
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.