diff --git a/RFCOMM.cpp b/RFCOMM.cpp index 133eb2f1..75dab41e 100644 --- a/RFCOMM.cpp +++ b/RFCOMM.cpp @@ -1522,6 +1522,23 @@ void RFCOMM::print(uint8_t* array, uint8_t length) { RFCOMM_Command(rfcommbuf,length+4); } +void RFCOMM::print(const __FlashStringHelper *ifsh) { + const uint8_t PROGMEM *p = (const uint8_t PROGMEM *)ifsh; + size_t size = 0; + while (1) { // Calculate the size of the string + uint8_t c = pgm_read_byte(p++); + if (c == 0) break; + size++; + } + uint8_t buf[size]; + + pgm_read_byte(p--); // Go one back + pgm_read_byte(p--); // Don't include the null character + for(uint8_t i = 1; i < size+1; i++) + buf[size-i] = pgm_read_byte(p--); // Write to buffer reversed + + print(buf,size); +} void RFCOMM::println(const char* data) { char output[strlen(data)+2]; @@ -1540,6 +1557,25 @@ void RFCOMM::println(uint8_t* array, uint8_t length) { buf[length+1] = '\n'; print(buf,length+2); } +void RFCOMM::println(const __FlashStringHelper *ifsh) { + const uint8_t PROGMEM *p = (const uint8_t PROGMEM *)ifsh; + size_t size = 0; + while (1) { // Calculate the size of the string + uint8_t c = pgm_read_byte(p++); + if (c == 0) break; + size++; + } + uint8_t buf[size+2]; + + pgm_read_byte(p--); // Go one back + pgm_read_byte(p--); // Don't include the null character + for(uint8_t i = 1; i < size+1; i++) + buf[size-i] = pgm_read_byte(p--); // Write to buffer reversed + + buf[size] = '\r'; + buf[size+1] = '\n'; + print(buf,size+2); +} uint8_t RFCOMM::read() { uint8_t output = rfcommDataBuffer[0]; diff --git a/RFCOMM.h b/RFCOMM.h index 6de8338f..d19fa667 100644 --- a/RFCOMM.h +++ b/RFCOMM.h @@ -203,9 +203,13 @@ public: void print(const char* data); // Used to send strings void print(uint8_t data); // Used to send single bytes void print(uint8_t* array, uint8_t length); // Used to send arrays + void print(const __FlashStringHelper *); // Used to print strings stored in flash + void println(const char* data); // Include newline and carriage return void println(uint8_t data); // Include newline and carriage return void println(uint8_t* array, uint8_t length); // Include newline and carriage return + void println(const __FlashStringHelper *); // Include newline and carriage return + uint8_t available() { return rfcommAvailable; }; // Get the bytes waiting to be read uint8_t read(); // Used to read the buffer diff --git a/examples/RFCOMM/RFCOMM.ino b/examples/RFCOMM/RFCOMM.ino index 923d2e0e..8249d3ae 100644 --- a/examples/RFCOMM/RFCOMM.ino +++ b/examples/RFCOMM/RFCOMM.ino @@ -25,7 +25,7 @@ void loop() { if(SerialBT.connected) { if(firstMessage) { firstMessage = false; - SerialBT.println("Hello from Arduino"); // Send welcome message + SerialBT.println(F("Hello from Arduino")); // Send welcome message } if(Serial.available()) SerialBT.print(Serial.read());