The sketch fragments below compile without error or warning with UNO, but generates the following warning with the Teensy 4.0:
C:\Users\Mike\AppData\Local\Temp\arduino_build_810777\sketch\pages.h:110:71: warning: invalid conversion from 'void ()()' to 'int16_t ()() {aka short int (*)()}' [-fpermissive]
CreateButton("ONOFF", 2, 340, 65, "ON", BUTTON, RED, *SystemSwitch);
It seems the -fpermissive feature is not set by default when the Teensy board is selected but it is with the arduino UNO.
How can -fpermissive be set when using the arduino IDE and a Teensy board?
Alternatively, how can the code be changed to work in both environments?
This code snippet has comments pointing out the relevant parts. The last line causes the warning.
// this is the structure where the function pointer will be stored
struct Button
{
public:
String buttonKey;
int x;
int y;
int height;
int length;
int16_t (*funct)(); // this is where the function pointer will be stored
};
Button myArray[20];
Button item;
// this is the function prototype with an optional last argument
void CreateButton(String buttonKey, int txSize, int x, int y, String txt, int bgClr, int txClr, int16_t (*funct)() = NULL);
// this is the actual function
{void CreateButton(String buttonKey, int txSize, int x, int y, String txt, int bgClr, int txClr, int16_t (*funct)())
float charWidth[6] = {6, 6, 12, 18, 24, 28};
float charHeight[6] = {7, 7, 14, 22, 30, 36};
float rectWidth, rectHeight;
rectWidth = (txt.length() + 1) * charWidth[txSize];
rectHeight = charHeight[txSize] + 20;
tft.drawRect(x, y, rectWidth, rectHeight, TEXT);
tft.fillRect(x + 1, y + 1, rectWidth - 2, rectHeight - 2, bgClr);
int txtStartX = x + (charWidth[txSize] / 2) + 1;
int txtStartY = y + 10;
tft.setCursor(txtStartX, txtStartY);
tft.setTextColor(txClr);
tft.setTextSize(txSize);
tft.print(txt);
if (funct != NULL)
{
// See if this button is already in the list
for (int i = 0; i < itemCount; i++ )
{
if (buttonKey == myArray[i].buttonKey)
return;
}
// Store the button coordinates for this button press
item.buttonKey = buttonKey;
item.x = x;
item.y = y;
item.length = rectWidth;
item.height = rectHeight;
item.funct = funct;
myArray[itemCount++] = item;
}
}
// this is the actual function call
CreateButton("ONOFF", 2, 340, 65, "ON", BUTTON, RED, *SystemSwitch);