/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/settings_mode.cc

  • Committer: Tim Marston
  • Date: 2012-03-21 20:35:28 UTC
  • Revision ID: tim@ed.am-20120321203528-wfhpych1tub75rgj
fixed bug initialising text services on mode activation

Show diffs side-by-side

added added

removed removed

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