mirror of
https://github.com/2martens/uni.git
synced 2026-05-06 19:36:26 +02:00
[ES] Added readString method
Signed-óff-by: Jim Martens <github@2martens.de>
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
#include <SD.h>
|
||||||
|
|
||||||
// pins
|
// pins
|
||||||
int slaveSelectPin = 10;
|
int slaveSelectPin = 10;
|
||||||
@ -304,3 +305,35 @@ int printString(int x, int y, const char* text, int textLength)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the contents of a text file into a string.
|
||||||
|
*
|
||||||
|
* Returns an empty string on failure.
|
||||||
|
*
|
||||||
|
* @param File file
|
||||||
|
*/
|
||||||
|
const char* readString(File file)
|
||||||
|
{
|
||||||
|
if (file) {
|
||||||
|
unsigned long fileSize = file.size();
|
||||||
|
char result[fileSize];
|
||||||
|
int i = 0;
|
||||||
|
while (file.available()) {
|
||||||
|
char c = file.read();
|
||||||
|
if (c != '\n') {
|
||||||
|
result[i] = c;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result[i] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// something happened
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user