forked from tiefpunkt/arduino_sd_recovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sd_recovery_raw.ino
89 lines (75 loc) · 1.68 KB
/
sd_recovery_raw.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <SD.h>
File root;
Sd2Card card;
void setup()
{
Serial.begin(115200);
pinMode(10, OUTPUT);
card.init(SPI_HALF_SPEED, 10);
// SD.begin(10);
long blocks = card.cardSize();
//Serial.println(blocks);
uint8_t data[512];
int i = 0;
boolean notZero = false;
for (long blockNumber = 0; blockNumber < blocks; blockNumber++) {
//card.chipSelectLow();
if (!card.readBlock(blockNumber, data)) {
Serial.println("Z");
break;
}
notZero = false;
for (i = 0; i<512; i++) {
if (data[i] > 0x00) {
notZero = true;
break;
}
}
if (notZero) {
for (i = 0; i<512; i++) {
if (data[i] < 0x10) {
Serial.print("0");
}
Serial.print(data[i], HEX);
}
Serial.println("X");
} else {
Serial.println("Y");
}
//Serial.println("done!");
}
void loop()
{
// nothing happens after setup finishes.
}
void printDirectory(File dir, String folder) {
boolean files = true;
while(files) {
File entry = dir.openNextFile();
if (! entry) {
files = false;
} else {
if (entry.isDirectory()) {
String folder_new = folder;
folder_new += entry.name();
folder_new += "/";
printDirectory(entry, folder_new);
} else {
Serial.print("--- ");
Serial.print(folder);
Serial.print(entry.name());
Serial.print(";");
Serial.println(entry.size(), DEC);
byte r;
while (entry.available()) {
r = entry.read();
if (r < 0x10) {
Serial.print("0");
}
Serial.print(r, HEX);
}
Serial.println();
}
}
}
}