/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-23 23:02:50 UTC
  • Revision ID: tim@ed.am-20120523230250-3pls2u6zt3av0uam
fixed text glitch; extended all modes; added screen flip super-long press;
added button unpress debounde; moved interim button press ignoration to
settings mode; fixed left-over led issue; finished for demo!

Show diffs side-by-side

added added

removed removed

1
1
/*
2
 
 * settings_mode.cc
 
2
 * settings_major_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_mode.h"
 
24
#include "settings_major_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 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()
42
 
{
43
 
        switch( _item )
44
 
        {
45
 
/*      case TIME_SET_IDX:
46
 
                switch( _part ) {
47
 
                case 0: Time::inc_hours(); break;
48
 
                case 1: Time::inc_minutes(); break;
49
 
                case 2: Time::reset_seconds(); break;
50
 
                }
51
 
                break;
52
 
        case DATE_SET_IDX:
53
 
                switch( _part ) {
54
 
                case 0: Time::inc_year(); break;
55
 
                case 1: Time::inc_month(); break;
56
 
                case 2: Time::inc_day(); break;
57
 
                }
58
 
                break;*/
59
 
        case FONT_SET_IDX:
60
 
                TextRenderer::inc_font();
61
 
                break;
62
 
        }
63
 
}
64
 
 
65
 
 
66
 
static void reset_messages()
67
 
{
68
 
        Text::reset_message( 0, Text::MODE_TOP | Text::MODE_ALL );
69
 
}
70
 
 
71
 
 
72
 
void settings_mode_long_press()
73
 
{
74
 
        // how many parts does this item have?
75
 
        int max = 1;
76
 
        switch( _item ) {
77
 
        case DATE_SET_IDX: // fall through
78
 
        case TIME_SET_IDX: max = 3; break;
79
 
        }
80
 
 
81
 
        // inc part and item
82
 
        if( ++_part >= max ) {
83
 
                _part = 0;
84
 
                if( ++_item >= 3 )
85
 
                        _item = 0;
86
 
        }
87
 
 
88
 
        // reset messages
89
 
        reset_messages();
90
 
}
91
 
 
92
 
 
93
 
void settings_mode_draw( int segment )
94
 
{
95
 
        Text::draw( 0, segment );
96
 
}
97
 
 
98
 
 
99
 
void settings_mode_draw_reset()
100
 
{
 
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
        // check button state for unpress
 
46
        if( _press_state == 1 && !_button.get_state() )
 
47
                _press_state = 2;
 
48
}
 
49
 
 
50
 
 
51
void SettingsMajorMode::draw_reset()
 
52
{
 
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
 
101
78
        bool flash = ( ::millis() % 1000 ) > 600;
102
79
        PString str0( Text::_messages[ 0 ], MESSAGE_LEN * 2 );
103
 
        str0.begin();
104
80
 
105
81
        switch( _item ) {
106
82
        case TIME_SET_IDX:
107
83
                if( _part == 0 && flash )
108
 
                        str0.print( "  " );
 
84
                        str0.print( ( Time::get_hours() % 12 ) < 10? " " : "  " );
109
85
                else
110
 
                        str0.format( "%2d", Time::get_hours() % 12 );
 
86
                        str0.format( "%d", Time::get_hours() % 12 );
111
87
                str0.print( ':' );
112
88
                if( _part == 1 && flash )
113
89
                        str0.print( "  " );
118
94
                        str0.print( "  " );
119
95
                else
120
96
                        str0.format( "%02d", Time::get_seconds() );
 
97
                str0.print( ' ' );
121
98
                if( _part == 0 && flash )
122
99
                        str0.print( "  " );
123
100
                else
150
127
                break;
151
128
        }
152
129
 
153
 
        Text::set_message( 0, str0 );
 
130
        Text::set_message_text( 0, str0 );
154
131
}
155
132
 
156
133
 
157
 
void settings_mode_activate()
 
134
void SettingsMajorMode::activate()
158
135
{
159
136
        _item = _part = 0;
160
 
 
161
 
        // reset messages
162
 
        reset_messages();
 
137
        _press_state = 0;
 
138
 
 
139
        reset_messages();
 
140
}
 
141
 
 
142
 
 
143
void SettingsMajorMode::deactivate()
 
144
{
 
145
        // save time
 
146
        Time::save_time();
 
147
}
 
148
 
 
149
 
 
150
void SettingsMajorMode::press()
 
151
{
 
152
        _press_state = 1;
 
153
}
 
154
 
 
155
 
 
156
void SettingsMajorMode::long_press()
 
157
{
 
158
        _press_state = 0;
 
159
 
 
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
{
 
180
        Text::reset();
 
181
        Text::set_up_message( 0, Text::MODE_TOP | Text::MODE_ALL );
163
182
}