-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeConverter.h
91 lines (85 loc) · 2.11 KB
/
TimeConverter.h
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
class FibValues {
public:
FibValues() {
}
void setField(byte t, byte n, bool state) { // t == 0 == hour
if( t <= 1 ) {
this->fieldStates[n-1][t] = state;
}
}
void setFieldHour(int n, bool state) {
this->fieldStates[n-1][0] = state;
}
void setFieldMinute(int n, bool state) {
this->fieldStates[n-1][1] = state;
}
//TODO: private setzen, optimieren
bool fieldStates[5][2] = {
// H M
{false, false},
{false, false},
{false, false},
{false, false},
{false, false}
};
};
class TimeConverter {
public:
TimeConverter(byte h, byte m) : hour(h), minute(m) {
}
FibValues getFibTime( void ) {
this->calcFieldStated();
return this->fs;
}
private:
byte hour;
byte minute;
FibValues fs;
void calcFieldStated() {
//hours:
if( this->hour > 11 ) {
this->hour -= 12; //normieren auf 0 bis 11 Stunden
}
if( this->hour - 5 >= 0 ) {
fs.setFieldHour(5,true);
this->hour -= 5;
}
if( this->hour - 3 >= 0 ) {
fs.setFieldHour(4,true);
this->hour -= 3;
}
if( this->hour - 2 >= 0 ) {
fs.setFieldHour(3,true);
this->hour -= 2;
}
if( this->hour - 1 >= 0 ) {
fs.setFieldHour(2,true);
this->hour -= 1;
}
if( this->hour - 1 == 0 ) {
fs.setFieldHour(1,true);
this->hour -= 1;
}
//minutes:
if( this->minute - 25 >= 0 ) {
fs.setFieldMinute(5,true);
this->minute -= 25;
}
if( this->minute - 15 >= 0 ) {
fs.setFieldMinute(4,true);
this->minute -= 15;
}
if( this->minute - 10 >= 0 ) {
fs.setFieldMinute(3,true);
this->minute -= 10;
}
if( this->minute - 5 >= 0 ) {
fs.setFieldMinute(2,true);
this->minute -= 5;
}
if( this->minute - 5 == 0 ) {
fs.setFieldMinute(1,true);
this->minute -= 5;
}
}
};