-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDCardManager.cpp
executable file
·53 lines (42 loc) · 1.13 KB
/
SDCardManager.cpp
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
//
// Created by Anders on 14.12.2015.
//
#include "SDCardManager.h"
SDCardManager::SDCardManager() {
if (!SD.begin(CHIP_SELECT)) {
return;
}
}
char* SDCardManager::getHighScore(char highScoreArray[], const byte len) {
openFile();
if (highScoreTxt) {
for (byte i = 0; i < len; i++) {
highScoreArray[i] = (char) highScoreTxt.read();
}
highScoreTxt.close();
} else {
for (byte i = 0; i < len; i++) {
highScoreArray[i] = '0';
}
}
highScoreArray[len] = '\0';
return highScoreArray;
}
void SDCardManager::setHighScore(const int highScore) {
openFile(true);
char valueArray[6];
if (highScoreTxt) {
highScoreTxt.write(Utils::getCharArrayFromInteger(valueArray, highScore), 6);
highScoreTxt.close();
}
}
void SDCardManager::openFile(const boolean write) {
char txtFileArray[7];
Utils::getCharArrayFromProgmem(txtFileArray, highScoreTxtFile);
if (write) {
SD.remove(txtFileArray);
highScoreTxt = SD.open(txtFileArray, FILE_WRITE);
} else {
highScoreTxt = SD.open(txtFileArray);
}
}