/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: edam
  • Date: 2012-05-18 12:11:01 UTC
  • Revision ID: tim@ed.am-20120518121101-0wik922hyvjkcjdi
switched back to using classes for modes

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"
33
33
#define DATE_SET_IDX 2
34
34
 
35
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 )
 
36
void SettingsMajorMode::draw( int segment )
93
37
{
94
38
        Text::draw( 0, segment );
95
39
}
96
40
 
97
41
 
98
 
void settings_mode_draw_reset()
 
42
void SettingsMajorMode::draw_reset()
99
43
{
100
44
        bool flash = ( ::millis() % 1000 ) > 600;
101
45
        PString str0( Text::_messages[ 0 ], MESSAGE_LEN * 2 );
154
98
}
155
99
 
156
100
 
157
 
void settings_mode_activate()
 
101
void SettingsMajorMode::activate()
158
102
{
159
103
        _item = _part = 0;
160
104
 
161
 
        // reset messages
162
 
        reset_messages();
 
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 );
163
162
}