-
Notifications
You must be signed in to change notification settings - Fork 0
/
Field.cpp
194 lines (164 loc) · 5.01 KB
/
Field.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "Field.h"
#include <LiquidCrystal_I2C.h>
extern LiquidCrystal_I2C lcd; // 1602 LCD Setup
Field::Field(enum Field::Format _format, int _value, int _column, int _row)
{
this->cursors = false;
this->format = _format;
this->value = _value;
this->row = _row;
this->column = _column;
}
//--------------------------------------------P R I N T F I E L D--------------------------------------------
void Field::printField()
{
lcd.setCursor(column, row); // move to the specified location on the screen
if (format == DAY) // DAY FIELDS
{
switch(value) { // display the day
case 1 : lcd.print("MON"); break;
case 2 : lcd.print("TUE"); break;
case 3 : lcd.print("WED"); break;
case 4 : lcd.print("THU"); break;
case 5 : lcd.print("FRI"); break;
}
}
if (format == NUMBER) // NUMBER FIELDS
{
if (value < 10) // values above 9 represent a blank digit
{
lcd.print(value); // print digits that are not blank
}
}
if (format == TIME) // TIME FIELDS
{
if (value < 10)
{
lcd.print("0");
}
lcd.print(value); // print the time
}
if (cursors == true)
{
printCursors();
}
else
{
removeCursors();
}
}
//--------------------------------------------S E L E C T F I E L D--------------------------------------------
void Field::selectField()
{
cursors = true;
}
//------------------------------------------D E S E L E C T F I E L D------------------------------------------
void Field::deselectField()
{
cursors = false;
}
//---------------------------------------------R E S E T F I E L D---------------------------------------------
void Field::resetField()
{
int defaultDay = 1; // Monday
int defaultNumber = 10; // blank
int defaultTime = 10; // 10 Minutes
if (format == DAY)
{
value = defaultDay;
}
if (format == NUMBER)
{
value = defaultNumber;
}
if (format == TIME)
{
value = defaultTime;
}
}
//------------------------------------------I N C R E M E N T D A Y S------------------------------------------
void Field::incrementDays()
{
if (value >= 5) // if the day is set to Friday
{
value = 1; // increment it to Monday
}
else
{
value++; // otherwise just increment normally
}
}
//------------------------------------------D E C R E M E N T D A Y S------------------------------------------
void Field::decrementDays()
{
if (value <= 1) // if the day is set to Monday
{
value = 5; // decrement it to Friday
}
else
{
value--; // otherwise just decrement normally
}
}
//------------------------------------------I N C R E M E N T T I M E------------------------------------------
void Field::incrementTime()
{
if (value < 20) // if less than 20 minutes
{
value = value + 5; // increment the time by 5 minutes
}
}
//------------------------------------------D E C R E M E N T T I M E------------------------------------------
void Field::decrementTime()
{
if (value > 5) // if more than 5 minutes
{
value = value - 5; // decrement the time by 5 minutes
}
}
//---------------------------------------------I S S E L E C T E D---------------------------------------------
bool Field::isSelected()
{
return cursors; // if the cursors are on then it is selected
}
//-------------------------------------------P R I N T C U R S O R S-------------------------------------------
void Field::printCursors()
{
if (format == DAY)
{
lcd.setCursor((column - 1), row);
lcd.print(">");
lcd.setCursor((column + 3), row);
lcd.print("<");
}
if (format == NUMBER)
{
lcd.setCursor(column, row);
lcd.print("_");
}
if (format == TIME)
{
lcd.setCursor((column - 1), row);
lcd.print(">");
lcd.setCursor((column + 2), row);
lcd.print("<");
}
}
//-------------------------------------------R E M O V E C U R S O R S-------------------------------------------
void Field::removeCursors()
{
if (format == DAY)
{
lcd.setCursor((column - 1), row);
lcd.print(" ");
lcd.setCursor((column + 3), row);
lcd.print(" ");
}
if (format == TIME)
{
lcd.setCursor((column - 1), row);
lcd.print(" ");
lcd.setCursor((column + 2), row);
lcd.print(" ");
}
}