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

  • Committer: Tim Marston
  • Date: 2012-05-17 22:48:38 UTC
  • Revision ID: tim@ed.am-20120517224838-25hjd6umh35vmtwn
updated arduino.mk

Show diffs side-by-side

added added

removed removed

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 )
 
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
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()
 
72
{
 
73
        // how many parts does this item have?
 
74
        int max = 1;
 
75
        switch( _item ) {
 
76
        case DATE_SET_IDX: // fall through
 
77
        case TIME_SET_IDX: max = 3; break;
 
78
        }
 
79
 
 
80
        // inc part and item
 
81
        if( ++_part >= max ) {
 
82
                _part = 0;
 
83
                if( ++_item >= 3 )
 
84
                        _item = 0;
 
85
        }
 
86
 
 
87
        // reset messages
 
88
        reset_messages();
 
89
}
 
90
 
 
91
 
 
92
void settings_mode_draw( int segment )
44
93
{
45
94
        Text::draw( 0, segment );
46
95
}
47
96
 
48
97
 
49
 
void SettingsMajorMode::draw_reset()
 
98
void settings_mode_draw_reset()
50
99
{
51
100
        bool flash = ( ::millis() % 1000 ) > 600;
52
101
        PString str0( Text::_messages[ 0 ], MESSAGE_LEN * 2 );
105
154
}
106
155
 
107
156
 
108
 
void SettingsMajorMode::activate()
 
157
void settings_mode_activate()
109
158
{
110
159
        _item = _part = 0;
111
160
 
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()
128
 
{
129
 
        switch( _item )
130
 
        {
131
 
        case TIME_SET_IDX:
132
 
                switch( _part ) {
133
 
                case 0: Time::inc_hours(); break;
134
 
                case 1: Time::inc_minutes(); break;
135
 
                case 2: Time::reset_seconds(); break;
136
 
                }
137
 
                break;
138
 
        case DATE_SET_IDX:
139
 
                switch( _part ) {
140
 
                case 0: Time::inc_year(); break;
141
 
                case 1: Time::inc_month(); break;
142
 
                case 2: Time::inc_day(); break;
143
 
                }
144
 
                break;
145
 
        case FONT_SET_IDX:
146
 
                TextRenderer::inc_font();
147
 
                break;
148
 
        }
149
 
}
150
 
 
151
 
 
152
 
void SettingsMajorMode::long_press()
153
 
{
154
 
        // how many parts does this item have?
155
 
        int max = 1;
156
 
        switch( _item ) {
157
 
        case DATE_SET_IDX: // fall through
158
 
        case TIME_SET_IDX: max = 3; break;
159
 
        }
160
 
 
161
 
        // inc part and item
162
 
        if( ++_part >= max ) {
163
 
                _part = 0;
164
 
                if( ++_item >= 3 )
165
 
                        _item = 0;
166
 
        }
167
 
 
168
 
        reset_messages();
169
 
}
170
 
 
171
 
 
172
 
void SettingsMajorMode::reset_messages()
173
 
{
174
 
        Text::reset_message( 0, Text::MODE_TOP | Text::MODE_ALL );
 
161
        // reset messages
 
162
        reset_messages();
175
163
}