bzr branch
http://bzr.ed.am/elec/propeller-clock
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
1 |
/* |
87
by edam
switched back to using classes for modes |
2 |
* settings_major_mode.cc |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
3 |
* |
4 |
* Copyright (C) 2011 Tim Marston <tim@ed.am> and Dan Marston. |
|
5 |
* |
|
6 |
* This file is part of propeller-clock (hereafter referred to as "this |
|
7 |
* program"). See http://ed.am/dev/software/arduino/propeller-clock for more |
|
8 |
* information. |
|
9 |
* |
|
10 |
* This program is free software: you can redistribute it and/or modify |
|
11 |
* it under the terms of the GNU Lesser General Public License as published |
|
12 |
* by the Free Software Foundation, either version 3 of the License, or |
|
13 |
* (at your option) any later version. |
|
14 |
* |
|
15 |
* This program is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
* GNU Lesser General Public License for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU Lesser General Public License |
|
21 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22 |
*/ |
|
23 |
#include "Arduino.h" |
|
87
by edam
switched back to using classes for modes |
24 |
#include "settings_major_mode.h" |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
25 |
#include "text.h" |
26 |
#include "text_renderer.h" |
|
27 |
#include "time.h" |
|
28 |
#include "common.h" |
|
29 |
||
30 |
||
86
by Tim Marston
various tweaks, a (failed) attempt to fix text reset bug and added TODO |
31 |
#define FONT_SET_IDX 0 |
32 |
#define TIME_SET_IDX 1 |
|
33 |
#define DATE_SET_IDX 2 |
|
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
34 |
|
35 |
||
89
by Tim Marston
moved rount Time a bit, and passed _button to SettingsMajorMode so that it can |
36 |
SettingsMajorMode::SettingsMajorMode( Button &button ) |
37 |
: |
|
38 |
_button( button ) |
|
39 |
{ |
|
40 |
} |
|
41 |
||
42 |
||
91
by Tim Marston
fixed text glitch; extended all modes; added screen flip super-long press; |
43 |
void SettingsMajorMode::draw( int segment ) |
44 |
{ |
|
45 |
// check button state for unpress |
|
46 |
if( _press_state == 1 && !_button.get_state() ) |
|
47 |
_press_state = 2; |
|
48 |
} |
|
49 |
||
50 |
||
87
by edam
switched back to using classes for modes |
51 |
void SettingsMajorMode::draw_reset() |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
52 |
{ |
91
by Tim Marston
fixed text glitch; extended all modes; added screen flip super-long press; |
53 |
// do a short button press? |
54 |
if( _press_state == 2 ) { |
|
55 |
_press_state = 0; |
|
56 |
switch( _item ) |
|
57 |
{ |
|
58 |
case TIME_SET_IDX: |
|
59 |
switch( _part ) { |
|
60 |
case 0: Time::inc_hours(); break; |
|
61 |
case 1: Time::inc_minutes(); break; |
|
62 |
case 2: Time::reset_seconds(); break; |
|
63 |
} |
|
64 |
break; |
|
65 |
case DATE_SET_IDX: |
|
66 |
switch( _part ) { |
|
67 |
case 0: Time::inc_year(); break; |
|
68 |
case 1: Time::inc_month(); break; |
|
69 |
case 2: Time::inc_day(); break; |
|
70 |
} |
|
71 |
break; |
|
72 |
case FONT_SET_IDX: |
|
73 |
TextRenderer::inc_font(); |
|
74 |
break; |
|
75 |
} |
|
76 |
} |
|
77 |
||
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
78 |
bool flash = ( ::millis() % 1000 ) > 600; |
79 |
PString str0( Text::_messages[ 0 ], MESSAGE_LEN * 2 ); |
|
80 |
||
81 |
switch( _item ) { |
|
82 |
case TIME_SET_IDX: |
|
83 |
if( _part == 0 && flash ) |
|
75
by Tim Marston
fixed time centring and display in settings mode |
84 |
str0.print( ( Time::get_hours() % 12 ) < 10? " " : " " ); |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
85 |
else |
75
by Tim Marston
fixed time centring and display in settings mode |
86 |
str0.format( "%d", Time::get_hours() % 12 ); |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
87 |
str0.print( ':' ); |
88 |
if( _part == 1 && flash ) |
|
89 |
str0.print( " " ); |
|
90 |
else |
|
91 |
str0.format( "%02d", Time::get_minutes() ); |
|
92 |
str0.print( ':' ); |
|
93 |
if( _part == 2 && flash ) |
|
94 |
str0.print( " " ); |
|
95 |
else |
|
96 |
str0.format( "%02d", Time::get_seconds() ); |
|
75
by Tim Marston
fixed time centring and display in settings mode |
97 |
str0.print( ' ' ); |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
98 |
if( _part == 0 && flash ) |
99 |
str0.print( " " ); |
|
100 |
else |
|
101 |
str0.print( Time::get_hours() > 11? "pm" : "am" ); |
|
102 |
break; |
|
103 |
||
104 |
case DATE_SET_IDX: |
|
105 |
if( _part == 0 && flash ) |
|
106 |
str0.print( " " ); |
|
107 |
else |
|
108 |
str0.format( "%04d", Time::get_year() ); |
|
109 |
str0.print( '-' ); |
|
110 |
if( _part == 1 && flash ) |
|
111 |
str0.print( " " ); |
|
112 |
else |
|
113 |
str0.format( "%02d", Time::get_month() ); |
|
114 |
str0.print( '-' ); |
|
115 |
if( _part == 2 && flash ) |
|
116 |
str0.print( " " ); |
|
117 |
else |
|
118 |
str0.format( "%02d", Time::get_day() ); |
|
119 |
break; |
|
120 |
||
121 |
case FONT_SET_IDX: |
|
122 |
str0.print( "font " ); |
|
123 |
if( flash ) |
|
124 |
str0.print( ' ' ); |
|
125 |
else |
|
126 |
str0.format( "%d", TextRenderer::get_font() ); |
|
127 |
break; |
|
128 |
} |
|
129 |
||
90
by Tim Marston
text messages are now individually enabled and draw()n automatically |
130 |
Text::set_message_text( 0, str0 ); |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
131 |
} |
132 |
||
133 |
||
87
by edam
switched back to using classes for modes |
134 |
void SettingsMajorMode::activate() |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
135 |
{ |
136 |
_item = _part = 0; |
|
91
by Tim Marston
fixed text glitch; extended all modes; added screen flip super-long press; |
137 |
_press_state = 0; |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
138 |
|
87
by edam
switched back to using classes for modes |
139 |
reset_messages(); |
140 |
} |
|
141 |
||
142 |
||
143 |
void SettingsMajorMode::deactivate() |
|
144 |
{ |
|
89
by Tim Marston
moved rount Time a bit, and passed _button to SettingsMajorMode so that it can |
145 |
// save time |
91
by Tim Marston
fixed text glitch; extended all modes; added screen flip super-long press; |
146 |
Time::save_time(); |
87
by edam
switched back to using classes for modes |
147 |
} |
148 |
||
149 |
||
150 |
void SettingsMajorMode::press() |
|
151 |
{ |
|
91
by Tim Marston
fixed text glitch; extended all modes; added screen flip super-long press; |
152 |
_press_state = 1; |
87
by edam
switched back to using classes for modes |
153 |
} |
154 |
||
155 |
||
156 |
void SettingsMajorMode::long_press() |
|
157 |
{ |
|
91
by Tim Marston
fixed text glitch; extended all modes; added screen flip super-long press; |
158 |
_press_state = 0; |
159 |
||
87
by edam
switched back to using classes for modes |
160 |
// how many parts does this item have? |
161 |
int max = 1; |
|
162 |
switch( _item ) { |
|
163 |
case DATE_SET_IDX: // fall through |
|
164 |
case TIME_SET_IDX: max = 3; break; |
|
165 |
} |
|
166 |
||
167 |
// inc part and item |
|
168 |
if( ++_part >= max ) { |
|
169 |
_part = 0; |
|
170 |
if( ++_item >= 3 ) |
|
171 |
_item = 0; |
|
172 |
} |
|
173 |
||
174 |
reset_messages(); |
|
175 |
} |
|
176 |
||
177 |
||
178 |
void SettingsMajorMode::reset_messages() |
|
179 |
{ |
|
90
by Tim Marston
text messages are now individually enabled and draw()n automatically |
180 |
Text::reset(); |
181 |
Text::set_up_message( 0, Text::MODE_TOP | Text::MODE_ALL ); |
|
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
182 |
} |