-
Notifications
You must be signed in to change notification settings - Fork 2
/
Clockface.cpp
75 lines (53 loc) · 1.43 KB
/
Clockface.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "Clockface.h"
EventBus eventBus;
const char* FORMAT_TWO_DIGITS = "%02d";
// Graphical elements
Tile ground(GROUND, 8, 8);
Object bush(BUSH, 21, 9);
Object cloud1(CLOUD1, 13, 12);
Object cloud2(CLOUD2, 13, 12);
Object hill(HILL, 20, 22);
Mario mario(23, 40);
Block hourBlock(13, 8);
Block minuteBlock(32, 8);
unsigned long lastMillis = 0;
Clockface::Clockface(Adafruit_GFX* display) {
_display = display;
Locator::provide(display);
Locator::provide(&eventBus);
}
void Clockface::setup(CWDateTime *dateTime) {
_dateTime = dateTime;
Locator::getDisplay()->setFont(&Super_Mario_Bros__24pt7b);
Locator::getDisplay()->fillRect(0, 0, 64, 64, SKY_COLOR);
ground.fillRow(DISPLAY_HEIGHT - ground._height);
bush.draw(43, 47);
hill.draw(0, 34);
cloud1.draw(0, 21);
cloud2.draw(51, 7);
updateTime();
hourBlock.init();
minuteBlock.init();
mario.init();
}
void Clockface::update() {
hourBlock.update();
minuteBlock.update();
mario.update();
if (_dateTime->getSecond() == 0 && millis() - lastMillis > 1000) {
mario.jump();
updateTime();
lastMillis = millis();
//Serial.println(_dateTime->getFormattedTime());
}
}
void Clockface::updateTime() {
hourBlock.setText(String(_dateTime->getHour()));
minuteBlock.setText(String(_dateTime->getMinute(FORMAT_TWO_DIGITS)));
}
void Clockface::externalEvent(int type) {
if (type == 0) { //TODO create an enum
mario.jump();
updateTime();
}
}