Flash.h errors with Arduino 1.0.6 and Teensy 3.1 (Teensyduino, Version 1.20)

683 views Asked by At

I have been am using Flash.h library from (http://arduiniana.org/libraries/flash/) Version 5 with Arduino 1.0.5 and teensy 3.1 without any issues. I had to upgrade to version 1.0.6 and now I am getting this error

[removed path from message]
/.../libraries/Flash/Flash.h: In member function 'char* _FLASH_STRING::copy(char*, size_t, size_t) const':
/.../libraries/Flash/Flash.h:79:44: error: operands to ?: have different types 'int' and 'char*'

and this is the code in flash.h

char *copy(char *to, size_t size = -1, size_t offset = 0) const 
  { 
    return size == -1 ?
      strcpy_P(to, _arr + offset) : strncpy_P(to, _arr + offset, size);
  }

at first glance I can see that the operand is comparing strcpy and strncpy and both of them return char* so I am not sure why it thinks one is an int.

this page has reference about the two functions used http://tuxgraphics.org/common/src2/article12051/avr-libc-user-manual/manual/group__avr__pgmspace.html

Any help would be appreciated to figure out what is the problem. Library test works with vailla Arduino 1.0.6, but when I install the Teensyduino, Version 1.20 and try to compile for teensy 3.1 I get this error. If I compile it to Arduino Uno it works.

Thanks in advance

2

There are 2 answers

0
Adonis On

I found the answer for this on PJRC forum. I applied the code changes and it worked for me. reference url: http://forum.pjrc.com/threads/26156-Teensy-3-1-and-TinyWebServer-Library?highlight=flash.h

Changed from

char *copy(char *to, size_t size = -1, size_t offset = 0) const 
{ 
  return size == -1 ?
  strcpy_P(to, _arr + offset) : strncpy_P(to, _arr + offset, size);
}

to

void *copy(char *to, size_t size = -1, size_t offset = 0) const 
{ 
if (size == -1) strcpy_P(to, _arr + offset);
 else strncpy_P(to, _arr + offset, size);
}

Hope this helps someone who is using flash.h library

0
Adonis On

And it seems that there is a bug in teensy library.

You can edit it to fix the compile error.

http://forum.pjrc.com/threads/26676-Teensy3-x-strncpy_P()-bug?p=54965

Note: Even after making changes to code and teensy3 avr headers I can not run the flash demo.