This repository was archived by the owner on Nov 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreen.cpp
More file actions
119 lines (107 loc) · 2.33 KB
/
Screen.cpp
File metadata and controls
119 lines (107 loc) · 2.33 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
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
#include "Screen.h"
#include "Arduino.h"
#include "U8x8lib.h"
#include "TimeLib.h"
#include "PulseSensor.h"
U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_NONE);
Screen::Screen() {
this->stepCount = 0;
this->bpm = 0;
}
void Screen::setup() {
u8x8.begin();
u8x8.clear();
// u8x8.setFont(u8x8_font_amstrad_cpc_extended_f);
u8x8.setFont(u8x8_font_chroma48medium8_r);
// u8x8.setFont(u8x8_font_victoriamedium8_u);
//u8x8.setFlipMode(1);
Serial.println("OLED screen setup complete!");
}
void Screen::showTimerScreen() {
u8x8.setCursor(0, 2);
String h, m, s;
String d, mo, y;
if (hour() < 10) {
h = "0" + String(hour());
} else {
h = String(hour());
}
if (minute() < 10) {
m = "0" + String(minute());
} else {
m = String(minute());
}
if (second() < 10) {
s = "0" + String(second());
} else {
s = String(second());
}
if (day() < 10) {
d = "0" + String(day());
} else {
d = String(day());
}
if (month() < 10) {
mo = "0" + String(month());
} else {
mo = String(month());
}
y = String(year());
String time = h + ":" + m + ":" + s;
String date = d + " " + mo + " " + y;
// u8x8.print(dateTime);
u8x8.setCursor(3, 1);
u8x8.print(date);
u8x8.draw2x2String(0, 3, time.c_str());
}
void Screen::showFootStepScreen() {
u8x8.setCursor(3, 2);
u8x8.println("Buoc chan");
// u8x8.println(this->stepCount);
u8x8.draw2x2String(2, 3, String(this->stepCount).c_str());
}
void Screen::showHeartRateScreen() {
this->pulseSen.run(); u8x8.setCursor(3, 2);
u8x8.print("BPM: ");
this->bpm = this->pulseSen.getBpm();
// u8x8.print(this->bpm);
u8x8.draw2x2String(2, 3, String(this->bpm).c_str());
}
void Screen::showAboutScreen() {
this->bpm = 0;
u8x8.setCursor(0, 1);
u8x8.println("My Watch");
u8x8.println("Ver 1.0");
u8x8.println("Last mod:");
u8x8.println("11:00 - 20/11");
u8x8.println("Thank you");
}
void Screen::run() {
switch (this->showingScreenId) {
case 0:
this->showTimerScreen();
break;
case 1:
this->showFootStepScreen();
break;
case 2:
this->showHeartRateScreen();
break;
case 3:
this->pulseSen.stop();
this->showAboutScreen();
break;
}
}
void Screen::changeToNextScreen() {
u8x8.clear();
if (this->showingScreenId == this->numberOfScreen - 1) {
this->showingScreenId = 0;
} else {
this->showingScreenId++;
}
}
void Screen::setStepCount(int inStep) {
this->stepCount = inStep;
this->run();
}