23 #include "TimeField.h"
66 #define EDIT_MINUTE_TENS 1
68 #define EDIT_SECOND_TENS 3
88 , editField(EDIT_HOUR)
108 , _maxHours(maxHours)
110 , _readOnly(readOnly)
111 , editField(EDIT_HOUR)
117 unsigned long newValue;
120 if (event == LCD_BUTTON_UP) {
122 if (editField == EDIT_HOUR) {
124 }
else if (editField == EDIT_MINUTE_TENS) {
125 if (((newValue / 60) % 60) >= 50)
129 }
else if (editField == EDIT_MINUTE) {
130 if (((newValue / 60) % 60) == 59)
134 }
else if (editField == EDIT_SECOND_TENS) {
135 if ((newValue % 60) >= 50)
140 if ((newValue % 60) == 59)
147 }
else if (event == LCD_BUTTON_DOWN) {
149 if (editField == EDIT_HOUR) {
150 if (newValue < 60 * 60)
151 newValue += ((
unsigned long)(_maxHours - 1)) * 60 * 60;
154 }
else if (editField == EDIT_MINUTE_TENS) {
155 if (((newValue / 60) % 60) < 10)
159 }
else if (editField == EDIT_MINUTE) {
160 if (((newValue / 60) % 60) == 0)
164 }
else if (editField == EDIT_SECOND_TENS) {
165 if ((newValue % 60) < 10)
170 if ((newValue % 60) == 0)
177 }
else if (event == LCD_BUTTON_LEFT) {
178 if (editField != EDIT_HOUR) {
183 }
else if (event == LCD_BUTTON_RIGHT) {
184 if (editField != EDIT_SECOND) {
197 editField = EDIT_SECOND;
199 editField = EDIT_HOUR;
229 unsigned long maxSecs = ((
unsigned long)_maxHours) * 60 * 60;
231 if (value != _value) {
270 if (_readOnly != value) {
282 void TimeField::printTime()
284 lcd()->setCursor(0, 1);
285 int col = printField(_value / (60 * 60));
286 int hourCol = col - 1;
289 col += printField((_value / 60) % 60);
290 int minuteCol = col - 1;
293 col += printField(_value % 60);
294 int secondCol = col - 1;
296 while (tempCol++ < _printLen)
300 if (editField == EDIT_HOUR)
301 lcd()->setCursor(hourCol, 1);
302 else if (editField == EDIT_MINUTE_TENS)
303 lcd()->setCursor(minuteCol - 1, 1);
304 else if (editField == EDIT_MINUTE)
305 lcd()->setCursor(minuteCol, 1);
306 else if (editField == EDIT_SECOND_TENS)
307 lcd()->setCursor(secondCol - 1, 1);
309 lcd()->setCursor(secondCol, 1);
313 int TimeField::printField(
unsigned long value)
316 lcd()->write(
'0' + (
int)(value / 10));
317 lcd()->write(
'0' + (
int)(value % 10));
320 unsigned long divisor = 100;
321 while ((value / divisor) >= 10)
324 while (divisor > 0) {
325 lcd()->write(
'0' + (
int)((value / divisor) % 10));
unsigned long value() const
Returns the current value of this time field, in seconds.
void setReadOnly(bool value)
Sets the read-only state of this field to value.
Manages a single data input/output field within a Form.
virtual void enterField(bool reverse)
Enters the field due to form navigation.
LiquidCrystal * lcd() const
Returns the LCD that this field is being drawn on.
int dispatch(int event)
Dispatches event via this field.
virtual void exitField()
Exits the field due to form navigation.
void enterField(bool reverse)
Enters the field due to form navigation.
TimeField(const String &label)
Constructs a new time field with a specific label.
bool isCurrent() const
Returns true if this field is the currently-displayed field in its owning form; false otherwise...
void exitField()
Exits the field due to form navigation.
void setValue(unsigned long value)
Sets the value of this time field, in seconds.