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 |
||
87
by edam
switched back to using classes for modes |
36 |
void SettingsMajorMode::draw( int segment ) |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
37 |
{ |
38 |
Text::draw( 0, segment ); |
|
39 |
} |
|
40 |
||
41 |
||
87
by edam
switched back to using classes for modes |
42 |
void SettingsMajorMode::draw_reset() |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
43 |
{ |
44 |
bool flash = ( ::millis() % 1000 ) > 600; |
|
45 |
PString str0( Text::_messages[ 0 ], MESSAGE_LEN * 2 ); |
|
46 |
str0.begin(); |
|
47 |
||
48 |
switch( _item ) { |
|
49 |
case TIME_SET_IDX: |
|
50 |
if( _part == 0 && flash ) |
|
75
by Tim Marston
fixed time centring and display in settings mode |
51 |
str0.print( ( Time::get_hours() % 12 ) < 10? " " : " " ); |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
52 |
else |
75
by Tim Marston
fixed time centring and display in settings mode |
53 |
str0.format( "%d", Time::get_hours() % 12 ); |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
54 |
str0.print( ':' ); |
55 |
if( _part == 1 && flash ) |
|
56 |
str0.print( " " ); |
|
57 |
else |
|
58 |
str0.format( "%02d", Time::get_minutes() ); |
|
59 |
str0.print( ':' ); |
|
60 |
if( _part == 2 && flash ) |
|
61 |
str0.print( " " ); |
|
62 |
else |
|
63 |
str0.format( "%02d", Time::get_seconds() ); |
|
75
by Tim Marston
fixed time centring and display in settings mode |
64 |
str0.print( ' ' ); |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
65 |
if( _part == 0 && flash ) |
66 |
str0.print( " " ); |
|
67 |
else |
|
68 |
str0.print( Time::get_hours() > 11? "pm" : "am" ); |
|
69 |
break; |
|
70 |
||
71 |
case DATE_SET_IDX: |
|
72 |
if( _part == 0 && flash ) |
|
73 |
str0.print( " " ); |
|
74 |
else |
|
75 |
str0.format( "%04d", Time::get_year() ); |
|
76 |
str0.print( '-' ); |
|
77 |
if( _part == 1 && flash ) |
|
78 |
str0.print( " " ); |
|
79 |
else |
|
80 |
str0.format( "%02d", Time::get_month() ); |
|
81 |
str0.print( '-' ); |
|
82 |
if( _part == 2 && flash ) |
|
83 |
str0.print( " " ); |
|
84 |
else |
|
85 |
str0.format( "%02d", Time::get_day() ); |
|
86 |
break; |
|
87 |
||
88 |
case FONT_SET_IDX: |
|
89 |
str0.print( "font " ); |
|
90 |
if( flash ) |
|
91 |
str0.print( ' ' ); |
|
92 |
else |
|
93 |
str0.format( "%d", TextRenderer::get_font() ); |
|
94 |
break; |
|
95 |
} |
|
96 |
||
97 |
Text::set_message( 0, str0 ); |
|
98 |
} |
|
99 |
||
100 |
||
87
by edam
switched back to using classes for modes |
101 |
void SettingsMajorMode::activate() |
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
102 |
{ |
103 |
_item = _part = 0; |
|
104 |
||
87
by edam
switched back to using classes for modes |
105 |
reset_messages(); |
106 |
} |
|
107 |
||
108 |
||
109 |
void SettingsMajorMode::deactivate() |
|
110 |
{ |
|
111 |
} |
|
112 |
||
113 |
||
114 |
void SettingsMajorMode::press() |
|
115 |
{ |
|
116 |
switch( _item ) |
|
117 |
{ |
|
118 |
case TIME_SET_IDX: |
|
119 |
switch( _part ) { |
|
120 |
case 0: Time::inc_hours(); break; |
|
121 |
case 1: Time::inc_minutes(); break; |
|
122 |
case 2: Time::reset_seconds(); break; |
|
123 |
} |
|
124 |
break; |
|
125 |
case DATE_SET_IDX: |
|
126 |
switch( _part ) { |
|
127 |
case 0: Time::inc_year(); break; |
|
128 |
case 1: Time::inc_month(); break; |
|
129 |
case 2: Time::inc_day(); break; |
|
130 |
} |
|
131 |
break; |
|
132 |
case FONT_SET_IDX: |
|
133 |
TextRenderer::inc_font(); |
|
134 |
break; |
|
135 |
} |
|
136 |
} |
|
137 |
||
138 |
||
139 |
void SettingsMajorMode::long_press() |
|
140 |
{ |
|
141 |
// how many parts does this item have? |
|
142 |
int max = 1; |
|
143 |
switch( _item ) { |
|
144 |
case DATE_SET_IDX: // fall through |
|
145 |
case TIME_SET_IDX: max = 3; break; |
|
146 |
} |
|
147 |
||
148 |
// inc part and item |
|
149 |
if( ++_part >= max ) { |
|
150 |
_part = 0; |
|
151 |
if( ++_item >= 3 ) |
|
152 |
_item = 0; |
|
153 |
} |
|
154 |
||
155 |
reset_messages(); |
|
156 |
} |
|
157 |
||
158 |
||
159 |
void SettingsMajorMode::reset_messages() |
|
160 |
{ |
|
161 |
Text::reset_message( 0, Text::MODE_TOP | Text::MODE_ALL ); |
|
71
by Tim Marston
added time set mode, made text renderer's buffer auto reset/output |
162 |
} |