dacostapaulo / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Support printing of progmem strings from Serial, Stream etc. #347

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What change would like to see?

the ability to print from program memory would be very useful from many classes 
that depend on Print

Why?

Would this cause any incompatibilities with previous versions?  If so, how
can these be mitigated?

No problems

It would be 2 simple routines added both would be very small.

Original issue reported on code.google.com by mark.l.s...@gmail.com on 12 Sep 2010 at 3:13

GoogleCodeExporter commented 9 years ago
Rather than adding functions with different names to the Serial class, I'd 
rather do this with a wrapper class for PROGMEM strings / array.  For example, 
something along the lines of: http://arduiniana.org/libraries/flash/

Original comment by dmel...@gmail.com on 13 Sep 2010 at 3:47

GoogleCodeExporter commented 9 years ago
A wrapper class is not necessary. I have working

    void print(prog_char *flashMemStr);
    void println(prog_char *flashMemStr);

These are the primary ones needed.

Do you feel that the rest of the data types should be implemented as well?

Mark

Original comment by mark.l.s...@gmail.com on 13 Sep 2010 at 7:12

GoogleCodeExporter commented 9 years ago
That's great.  How does it get distinguished from RAM strings?  Do you have a 
patch?

Other data types probably aren't necessary for now.

Original comment by dmel...@gmail.com on 13 Sep 2010 at 8:32

GoogleCodeExporter commented 9 years ago
At first it was working great, but more testing showed that it did get 
confused. I am working on it.

I was expecting to use the _P because that's what strcpy and strcat use.

Mark

Original comment by mark.l.s...@gmail.com on 13 Sep 2010 at 11:31

GoogleCodeExporter commented 9 years ago
I had to add "_P" to get this to work properly

Original comment by mark.l.s...@gmail.com on 6 Oct 2010 at 12:21

Attachments:

GoogleCodeExporter commented 9 years ago
We've added the F("string") wrapper to the Arduino 1.0 in development 
(new-extension branch on GitHub) that allows for printing of strings from Flash 
memory.

Original comment by dmel...@gmail.com on 24 May 2011 at 5:32

GoogleCodeExporter commented 9 years ago

Original comment by dmel...@gmail.com on 4 Jun 2011 at 2:08

GoogleCodeExporter commented 9 years ago
Using android 1.0 I am unable to compile lines using the F() macro. I am using 
avr-gcc 4.5.1 on FreeBSD 7.0
/////-- Sample code --

FLASH_STRING(big_string, "The quick brown fox\n"); // Compiles

void setup()
{
    Serial.begin(115200);  // 
    Serial  << big_string;   // Compiles
    Serial << F("jumped over \n");  // Does NOT Compile
    Serial << "the lazy sleeping dogs";    // Compiles
    Serial.print (F("It is so")); // Does NOT Compile
}

////////The pre-processed output is shown below 
static const char big_string_flash[] __attribute__((__progmem__)) = "The quick 
brown fox\n"; _FLASH_STRING big_string(big_string_flash);;

void setup()
{
    Serial.begin(115200);
    Serial << big_string;
    Serial<< (reinterpret_cast<__FlashStringHelper *>((__extension__({static const char __c[] __attribute__((__progmem__)) = ("jumped over \n"); &__c[0];}))));
    Serial << "the sleeping dogs";
    Serial.print ((reinterpret_cast<__FlashStringHelper *>((__extension__({static const char __c[] __attribute__((__progmem__)) = ("It is so"); &__c[0];})))));

}

////// Compiler error
avr-gcc tst.cpp -mmcu=atmega328p -DF_CPU=16000000UL -Os -w -Wl,--gc-sections 
-ffunction-sections -fdata-sections -felide-constructors -std=c++0x 
-DARDUINO=100 -I /home/rr/code/arduino//include/arduino/ -c -o tst.o
tst.cpp: In function 'void setup()':
tst.cpp:9:14: error: reinterpret_cast from type 'const char*' to type 
'__FlashStringHelper*' casts away qualifiers
tst.cpp:11:19: error: reinterpret_cast from type 'const char*' to type 
'__FlashStringHelper*' casts away qualifiers

Original comment by r.rajam...@gmail.com on 8 Mar 2012 at 11:02

GoogleCodeExporter commented 9 years ago
Sorry I meant to say arduino 1.0 and not android!

Original comment by r.rajam...@gmail.com on 8 Mar 2012 at 11:03