mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Added printFlashString function
This commit is contained in:
parent
734f004671
commit
8a22dd66e7
2 changed files with 27 additions and 32 deletions
41
SPP.cpp
41
SPP.cpp
|
@ -716,9 +716,6 @@ void SPP::print(const char* str) {
|
|||
|
||||
RFCOMM_Command(l2capoutbuf,length+4);
|
||||
}
|
||||
void SPP::print(uint8_t data) {
|
||||
print(&data,1);
|
||||
}
|
||||
void SPP::print(uint8_t* array, uint8_t length) {
|
||||
if(!connected)
|
||||
return;
|
||||
|
@ -734,22 +731,6 @@ void SPP::print(uint8_t* array, uint8_t length) {
|
|||
|
||||
RFCOMM_Command(l2capoutbuf,length+4);
|
||||
}
|
||||
void SPP::print(const __FlashStringHelper *ifsh) {
|
||||
const char PROGMEM *p = (const char PROGMEM *)ifsh;
|
||||
size_t size = 0;
|
||||
while (1) { // Calculate the size of the string
|
||||
uint8_t c = pgm_read_byte(p+size);
|
||||
if (c == 0)
|
||||
break;
|
||||
size++;
|
||||
}
|
||||
uint8_t buf[size];
|
||||
|
||||
for(uint8_t i = 0; i < size; i++)
|
||||
buf[i] = pgm_read_byte(p++);
|
||||
|
||||
print(buf,size);
|
||||
}
|
||||
void SPP::println(const String &str) {
|
||||
String output = str + "\r\n";
|
||||
print(output);
|
||||
|
@ -768,26 +749,29 @@ void SPP::println(uint8_t* array, uint8_t length) {
|
|||
uint8_t buf[length+2];
|
||||
memcpy(buf,array,length);
|
||||
buf[length] = '\r';
|
||||
buf[length+1] = '\n';
|
||||
buf[length+1] = '\n';
|
||||
print(buf,length+2);
|
||||
}
|
||||
void SPP::println(const __FlashStringHelper *ifsh) {
|
||||
const char PROGMEM *p = (const char PROGMEM *)ifsh;
|
||||
size_t size = 0;
|
||||
void SPP::printFlashString(const __FlashStringHelper *ifsh, bool newline) {
|
||||
const char PROGMEM *p = (const char PROGMEM *)ifsh;
|
||||
uint8_t size = 0;
|
||||
while (1) { // Calculate the size of the string
|
||||
uint8_t c = pgm_read_byte(p+size);
|
||||
if (c == 0)
|
||||
break;
|
||||
size++;
|
||||
}
|
||||
uint8_t buf[size+2];
|
||||
uint8_t buf[size+2]; // Add two extra in case it needs to print a newline and carriage return
|
||||
|
||||
for(uint8_t i = 0; i < size; i++)
|
||||
buf[i] = pgm_read_byte(p++);
|
||||
|
||||
buf[size] = '\r';
|
||||
buf[size+1] = '\n';
|
||||
print(buf,size+2);
|
||||
if(newline) {
|
||||
buf[size] = '\r';
|
||||
buf[size+1] = '\n';
|
||||
print(buf,size+2);
|
||||
} else
|
||||
print(buf,size);
|
||||
}
|
||||
void SPP::println(void) {
|
||||
uint8_t buf[2] = {'\r','\n'};
|
||||
|
@ -805,8 +789,7 @@ void SPP::printNumberln(uint32_t n) {
|
|||
intToString(n,output);
|
||||
strcat(output,"\r\n");
|
||||
print(output);
|
||||
}
|
||||
|
||||
}
|
||||
void SPP::printNumber(int32_t n) {
|
||||
char output[12];
|
||||
intToString(n,output);
|
||||
|
|
18
SPP.h
18
SPP.h
|
@ -128,6 +128,7 @@ public:
|
|||
* @param str String to send.
|
||||
*/
|
||||
void println(const String &str);
|
||||
|
||||
/**
|
||||
* Used to send standard strings.
|
||||
* @param str String to send.
|
||||
|
@ -138,16 +139,18 @@ public:
|
|||
* @param str String to send.
|
||||
*/
|
||||
void println(const char* str);
|
||||
|
||||
/**
|
||||
* Used to send single bytes.
|
||||
* @param data Data to send.
|
||||
*/
|
||||
void print(uint8_t data);
|
||||
void print(uint8_t data) { print(&data,1); };
|
||||
/**
|
||||
* Same as print(uint8_t data), but will include newline and carriage return.
|
||||
* @param data Data to send.
|
||||
*/
|
||||
void println(uint8_t data);
|
||||
|
||||
/**
|
||||
* Used to send arrays.
|
||||
* @param array Array to send.
|
||||
|
@ -160,16 +163,25 @@ public:
|
|||
* @param length Number of bytes to send.
|
||||
*/
|
||||
void println(uint8_t* array, uint8_t length);
|
||||
|
||||
/**
|
||||
* Used to print strings stored in flash.
|
||||
* @param ifsh String to send - see: http://playground.arduino.cc/Learning/Memory.
|
||||
*/
|
||||
void print(const __FlashStringHelper *ifsh);
|
||||
void print(const __FlashStringHelper *ifsh) { printFlashString(ifsh,false); };
|
||||
/**
|
||||
* Same as print(const __FlashStringHelper *ifsh), but will include newline and carriage return.
|
||||
* @param ifsh String to send - see: http://playground.arduino.cc/Learning/Memory.
|
||||
*/
|
||||
void println(const __FlashStringHelper *ifsh);
|
||||
void println(const __FlashStringHelper *ifsh) { printFlashString(ifsh,true); };
|
||||
/**
|
||||
* Helper function to convert from a string stored in flash to a string in ram.
|
||||
* @param ifsh String to convert.
|
||||
* @param newline Set this to true to include newline and carriage return.
|
||||
*/
|
||||
void printFlashString(const __FlashStringHelper *ifsh, bool newline);
|
||||
|
||||
|
||||
/** Use this to print newline and carriage return. */
|
||||
void println(void);
|
||||
|
||||
|
|
Loading…
Reference in a new issue