-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSdImageViewer.cpp
More file actions
73 lines (60 loc) · 1.75 KB
/
SdImageViewer.cpp
File metadata and controls
73 lines (60 loc) · 1.75 KB
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
#include "SdImageViewer.h"
#include "ScopedPin.h"
#include "Util.h"
static constexpr uint32_t ReadBufferSize = 4200;
namespace errorColor {
static constexpr Color NoImage = Color::Blue;
static constexpr Color CardFailure = Color::Orange;
static constexpr Color LowBattery = Color::Red;
}
void SdImageViewer::setup() const {
pinMode(ledPin, OUTPUT);
}
void SdImageViewer::displayImage(FsFile& file, Color fallbackColor) const {
ePaper.init();
ePaper.clear(Color::Clean);
if (file.isOpen()) {
ePaper.beginImage();
uint8_t buf[ReadBufferSize];
int bytesRead;
while ((bytesRead = file.read(buf, array_size(buf))) > 0) {
ePaper.sendImageData(buf, bytesRead);
}
file.close();
ePaper.endImage();
} else {
ePaper.clear(fallbackColor);
}
ePaper.sleep();
}
void SdImageViewer::showNextImage() {
FsFile file;
auto ledOn = ScopedHighPin(ledPin);
if (sd.begin()) {
file = sd.getNextImage();
displayImage(file, errorColor::NoImage);
} else {
displayImage(file, errorColor::CardFailure);
}
}
void SdImageViewer::showCurrentImage() {
FsFile file;
auto ledOn = ScopedHighPin(ledPin);
if (sd.begin()) {
file = sd.getCurrentImage();
displayImage(file, errorColor::NoImage);
} else {
displayImage(file, errorColor::CardFailure);
}
}
void SdImageViewer::showSystemImage(const char* fileName, Color fallbackColor) {
FsFile file;
auto ledOn = ScopedHighPin(ledPin);
if (sd.begin()) {
file = sd.getSystemImage(fileName);
}
displayImage(file, fallbackColor);
}
void SdImageViewer::showLowBatteryImage() {
showSystemImage("LowBattery.bin", errorColor::LowBattery);
}