mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Added ability to store strings in flash
This commit is contained in:
parent
2fb8dcf8ae
commit
ea575c3999
3 changed files with 41 additions and 1 deletions
36
RFCOMM.cpp
36
RFCOMM.cpp
|
@ -1522,6 +1522,23 @@ 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) {
|
||||||
|
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) {
|
void RFCOMM::println(const char* data) {
|
||||||
char output[strlen(data)+2];
|
char output[strlen(data)+2];
|
||||||
|
@ -1540,6 +1557,25 @@ void RFCOMM::println(uint8_t* array, uint8_t length) {
|
||||||
buf[length+1] = '\n';
|
buf[length+1] = '\n';
|
||||||
print(buf,length+2);
|
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 RFCOMM::read() {
|
||||||
uint8_t output = rfcommDataBuffer[0];
|
uint8_t output = rfcommDataBuffer[0];
|
||||||
|
|
4
RFCOMM.h
4
RFCOMM.h
|
@ -203,9 +203,13 @@ public:
|
||||||
void print(const char* data); // Used to send strings
|
void print(const char* data); // Used to send strings
|
||||||
void print(uint8_t data); // Used to send single bytes
|
void print(uint8_t data); // Used to send single bytes
|
||||||
void print(uint8_t* array, uint8_t length); // Used to send arrays
|
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(const char* data); // Include newline and carriage return
|
||||||
void println(uint8_t 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(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 available() { return rfcommAvailable; }; // Get the bytes waiting to be read
|
||||||
uint8_t read(); // Used to read the buffer
|
uint8_t read(); // Used to read the buffer
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ void loop() {
|
||||||
if(SerialBT.connected) {
|
if(SerialBT.connected) {
|
||||||
if(firstMessage) {
|
if(firstMessage) {
|
||||||
firstMessage = false;
|
firstMessage = false;
|
||||||
SerialBT.println("Hello from Arduino"); // Send welcome message
|
SerialBT.println(F("Hello from Arduino")); // Send welcome message
|
||||||
}
|
}
|
||||||
if(Serial.available())
|
if(Serial.available())
|
||||||
SerialBT.print(Serial.read());
|
SerialBT.print(Serial.read());
|
||||||
|
|
Loading…
Reference in a new issue