-
Notifications
You must be signed in to change notification settings - Fork 0
/
editObject.cpp
140 lines (123 loc) · 2.33 KB
/
editObject.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
#include "editObject.h"
void editObject::setXY(int x, int y)
{
X = x;
Y = y;
}
void editObject::setLeadingChar(unsigned char c)
{
leadingChar = c;
}
void editObject::setLCD (LiquidCrystal_I2C* newLCD)
{
LCD = newLCD;
}
void editObject::setValue(int newValue)
{
if (newValue >= minValue && newValue <= maxValue && newValue != Value)
{
Value=newValue;
ValueAsString = String(Value);
if (ValueAsString.length() <= 1)
ValueAsString = '0' + ValueAsString;
}
}
void editObject::print()
{
LCD->setCursor(X,Y);
if (editMode)
{
LCD->write(byte(0));
LCD->print(ValueAsString);
LCD->write(byte(0));
}
else if (Active)
{
LCD->write(byte(1));
LCD->print(ValueAsString);
LCD->write(byte(2));
}
else
{
LCD->write(leadingChar);
LCD->print(ValueAsString);
}
}
void editObject::setNext(editObject* next)
{
Next = next;
}
void editObject::setPrev(editObject* prev)
{
Prev = prev;
}
editObject* editObject::getPrev()
{
return Prev;
}
editObject* editObject::getNext()
{
return Next;
}
editObject::editObject(int x, int y, int minval, int maxval, LiquidCrystal_I2C* newLCD, editObject* next, editObject* prev)
{
X = x;
Y = y;
minValue = minval;
maxValue = maxval;
Value = minval;
ValueAsString = String(Value);
if (ValueAsString.length() <= 1)
ValueAsString = '0' + ValueAsString;
LCD = newLCD;
Next = next;
Prev = prev;
Active = false;
if (Prev != NULL) Prev->setNext(this);
//if (Next != NULL) Next->setPrev(this);
readOnly = true;
editMode = false;
if (next == NULL)
Next = this;
if (prev == NULL)
Prev = this;
}
void editObject::setReadOnly(bool mode)
{
readOnly = mode;
}
void editObject::incrementValue(int increment = 1)
{
setValue(Value + increment);
}
void editObject::decrementValue(int decrement = 1)
{
setValue(Value - decrement);
}
void editObject::setEditMode(bool mode)
{
editMode=readOnly?false:mode;
}
bool editObject::getEditMode()
{
return editMode;
}
void editObject::setActive(bool active)
{
Active = active;
}
bool editObject::isActive()
{
return Active;
}
void displayTime(editObject* h, editObject* m, editObject* s)
{
editObject* t[] = {h, m, s};
int act = -1;
for (int i = 0; i < 3; i++)
{
if (t[i]->isActive() || t[i]->getEditMode()) act = i;
else t[i]->print();
}
if (act>=0) t[act]->print();
}