mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Better print strings from flash routine
This commit is contained in:
parent
ea575c3999
commit
b833daeec7
1 changed files with 14 additions and 16 deletions
26
RFCOMM.cpp
26
RFCOMM.cpp
|
@ -1523,19 +1523,18 @@ void RFCOMM::print(uint8_t* array, uint8_t length) {
|
||||||
RFCOMM_Command(rfcommbuf,length+4);
|
RFCOMM_Command(rfcommbuf,length+4);
|
||||||
}
|
}
|
||||||
void RFCOMM::print(const __FlashStringHelper *ifsh) {
|
void RFCOMM::print(const __FlashStringHelper *ifsh) {
|
||||||
const uint8_t PROGMEM *p = (const uint8_t PROGMEM *)ifsh;
|
const char PROGMEM *p = (const char PROGMEM *)ifsh;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
while (1) { // Calculate the size of the string
|
while (1) { // Calculate the size of the string
|
||||||
uint8_t c = pgm_read_byte(p++);
|
uint8_t c = pgm_read_byte(p+size);
|
||||||
if (c == 0) break;
|
if (c == 0)
|
||||||
|
break;
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
uint8_t buf[size];
|
uint8_t buf[size];
|
||||||
|
|
||||||
pgm_read_byte(p--); // Go one back
|
for(uint8_t i = 0; i < size; i++)
|
||||||
pgm_read_byte(p--); // Don't include the null character
|
buf[i] = pgm_read_byte(p++);
|
||||||
for(uint8_t i = 1; i < size+1; i++)
|
|
||||||
buf[size-i] = pgm_read_byte(p--); // Write to buffer reversed
|
|
||||||
|
|
||||||
print(buf,size);
|
print(buf,size);
|
||||||
}
|
}
|
||||||
|
@ -1558,19 +1557,18 @@ void RFCOMM::println(uint8_t* array, uint8_t length) {
|
||||||
print(buf,length+2);
|
print(buf,length+2);
|
||||||
}
|
}
|
||||||
void RFCOMM::println(const __FlashStringHelper *ifsh) {
|
void RFCOMM::println(const __FlashStringHelper *ifsh) {
|
||||||
const uint8_t PROGMEM *p = (const uint8_t PROGMEM *)ifsh;
|
const char PROGMEM *p = (const char PROGMEM *)ifsh;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
while (1) { // Calculate the size of the string
|
while (1) { // Calculate the size of the string
|
||||||
uint8_t c = pgm_read_byte(p++);
|
uint8_t c = pgm_read_byte(p+size);
|
||||||
if (c == 0) break;
|
if (c == 0)
|
||||||
|
break;
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
uint8_t buf[size+2];
|
uint8_t buf[size+2];
|
||||||
|
|
||||||
pgm_read_byte(p--); // Go one back
|
for(uint8_t i = 0; i < size; i++)
|
||||||
pgm_read_byte(p--); // Don't include the null character
|
buf[i] = pgm_read_byte(p++);
|
||||||
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] = '\r';
|
||||||
buf[size+1] = '\n';
|
buf[size+1] = '\n';
|
||||||
|
|
Loading…
Reference in a new issue