-
Notifications
You must be signed in to change notification settings - Fork 0
/
cardHelp.ino
126 lines (119 loc) · 2.61 KB
/
cardHelp.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <Arduino.h>
/* SD Card setup
51 - MOSI
50 - MISO
52 - CLK | SCK
53 - CS
53,51,52,50,
*/
void cardInit() {
pp("\nInitializing SD card...");
if (!SD.begin(chipSelect)) {
p("initialization failed!");
while (1);
}
p("initialization done.");
}
bool cardFile(String file) {
if (SD.exists(file)) {
p("Soubor " + file + " existije");
return true;
} else {
p("Soubor " + file + " NEexistije");
return false;
}
}
void cardZastatDefault(String file) {
File myFile;
myFile = SD.open(file, FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to " + file + "...");
myFile.print("#:##:##\n");
myFile.print("A:line 1:1111\n");
myFile.print("B:line 2:222\n");
myFile.print("C:line 3:33\n");
myFile.print("D:line 4:4\n");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening " + file);
}
}
File cardOpenFile(String file) {
File myFile = SD.open(file);
if (myFile) {
return myFile;
}
return File();
}
char cardGetChar(File myFile) {
char r;
do {
r = cardReadChar(myFile);
} while (!((r >= 32 && r <= 125 ) || r == '\n'));
return r;
}
char cardReadChar(File myFile) {
if (myFile.available()) {
return myFile.read();
} else {
return ';';
}
}
bool cardLoadData(String file) {
if (cardFile(file)) {
p("File exists");
lcdl1(init3);
return true;
} else {
lcdl1(init4);
lcdl2(init5);
cardZastatDefault(file);
return cardLoadData(file);
}
return false;
}
void cardLoadFile() {
char t;
//
if (cardLoadData(FFILE)) {
lcdl2(init1);
File file = cardOpenFile(FFILE);
do {
t = cardGetChar(file);
} while (t != '\n');
p("--------LD---------------");
for (int x = 0; x < FINT; x++) {
p("Loading of question");
_otazky[x] = cardGetChar(file);
cardGetChar(file); //:
p("question text");
while (true) {
t = cardGetChar(file);
if (t == ':') { //:
break;
}
_text[x] += t;
}
p("correct key");
while (true) {
t = cardGetChar(file);
if (!(t >= 48 && t <= 58)) {
break;
}
_kod[x] += t;
}
p("Next question");
}
for (int x = 0; x < FINT; x++) {
p("------------------");
p(_otazky[x]);
p(_text[x]);
p(_kod[x]);
p("------------------");
}
}
}