/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock

« back to all changes in this revision

Viewing changes to src/modes/settings_major_mode.cc

  • Committer: Tim Marston
  • Date: 2012-05-18 18:29:50 UTC
  • Revision ID: tim@ed.am-20120518182950-t85bn9a21n72uzm8
text messages are now individually enabled and draw()n automatically

Show diffs side-by-side

added added

removed removed

 
1
/*
 
2
 * settings_major_mode.cc
 
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"
 
24
#include "settings_major_mode.h"
 
25
#include "text.h"
 
26
#include "text_renderer.h"
 
27
#include "time.h"
 
28
#include "common.h"
 
29
 
 
30
 
 
31
#define FONT_SET_IDX 0
 
32
#define TIME_SET_IDX 1
 
33
#define DATE_SET_IDX 2
 
34
 
 
35
 
 
36
SettingsMajorMode::SettingsMajorMode( Button &button )
 
37
        :
 
38
        _button( button )
 
39
{
 
40
}
 
41
 
 
42
 
 
43
void SettingsMajorMode::draw_reset()
 
44
{
 
45
        bool flash = ( ::millis() % 1000 ) > 600;
 
46
        PString str0( Text::_messages[ 0 ], MESSAGE_LEN * 2 );
 
47
        str0.begin();
 
48
 
 
49
        switch( _item ) {
 
50
        case TIME_SET_IDX:
 
51
                if( _part == 0 && flash )
 
52
                        str0.print( ( Time::get_hours() % 12 ) < 10? " " : "  " );
 
53
                else
 
54
                        str0.format( "%d", Time::get_hours() % 12 );
 
55
                str0.print( ':' );
 
56
                if( _part == 1 && flash )
 
57
                        str0.print( "  " );
 
58
                else
 
59
                        str0.format( "%02d", Time::get_minutes() );
 
60
                str0.print( ':' );
 
61
                if( _part == 2 && flash )
 
62
                        str0.print( "  " );
 
63
                else
 
64
                        str0.format( "%02d", Time::get_seconds() );
 
65
                str0.print( ' ' );
 
66
                if( _part == 0 && flash )
 
67
                        str0.print( "  " );
 
68
                else
 
69
                        str0.print( Time::get_hours() > 11? "pm" : "am" );
 
70
                break;
 
71
 
 
72
        case DATE_SET_IDX:
 
73
                if( _part == 0 && flash )
 
74
                        str0.print( "    " );
 
75
                else
 
76
                        str0.format( "%04d", Time::get_year() );
 
77
                str0.print( '-' );
 
78
                if( _part == 1 && flash )
 
79
                        str0.print( "  " );
 
80
                else
 
81
                        str0.format( "%02d", Time::get_month() );
 
82
                str0.print( '-' );
 
83
                if( _part == 2 && flash )
 
84
                        str0.print( "  " );
 
85
                else
 
86
                        str0.format( "%02d", Time::get_day() );
 
87
                break;
 
88
 
 
89
        case FONT_SET_IDX:
 
90
                str0.print( "font " );
 
91
                if( flash )
 
92
                        str0.print( ' ' );
 
93
                else
 
94
                        str0.format( "%d", TextRenderer::get_font() );
 
95
                break;
 
96
        }
 
97
 
 
98
        Text::set_message_text( 0, str0 );
 
99
}
 
100
 
 
101
 
 
102
void SettingsMajorMode::activate()
 
103
{
 
104
        _item = _part = 0;
 
105
 
 
106
        reset_messages();
 
107
 
 
108
        _button.set_press_mode( false );
 
109
}
 
110
 
 
111
 
 
112
void SettingsMajorMode::deactivate()
 
113
{
 
114
        _button.set_press_mode( true );
 
115
 
 
116
        // save time
 
117
 
 
118
}
 
119
 
 
120
 
 
121
void SettingsMajorMode::press()
 
122
{
 
123
        switch( _item )
 
124
        {
 
125
        case TIME_SET_IDX:
 
126
                switch( _part ) {
 
127
                case 0: Time::inc_hours(); break;
 
128
                case 1: Time::inc_minutes(); break;
 
129
                case 2: Time::reset_seconds(); break;
 
130
                }
 
131
                break;
 
132
        case DATE_SET_IDX:
 
133
                switch( _part ) {
 
134
                case 0: Time::inc_year(); break;
 
135
                case 1: Time::inc_month(); break;
 
136
                case 2: Time::inc_day(); break;
 
137
                }
 
138
                break;
 
139
        case FONT_SET_IDX:
 
140
                TextRenderer::inc_font();
 
141
                break;
 
142
        }
 
143
}
 
144
 
 
145
 
 
146
void SettingsMajorMode::long_press()
 
147
{
 
148
        // how many parts does this item have?
 
149
        int max = 1;
 
150
        switch( _item ) {
 
151
        case DATE_SET_IDX: // fall through
 
152
        case TIME_SET_IDX: max = 3; break;
 
153
        }
 
154
 
 
155
        // inc part and item
 
156
        if( ++_part >= max ) {
 
157
                _part = 0;
 
158
                if( ++_item >= 3 )
 
159
                        _item = 0;
 
160
        }
 
161
 
 
162
        reset_messages();
 
163
}
 
164
 
 
165
 
 
166
void SettingsMajorMode::reset_messages()
 
167
{
 
168
        Text::reset();
 
169
 
 
170
        Text::set_up_message( 0, Text::MODE_TOP | Text::MODE_ALL );
 
171
}