/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 14:40:04 UTC
  • Revision ID: tim@ed.am-20120518144004-uuz2zrjmyr78wqd5
updated emacs compile command and readjusted clock shift

Show diffs side-by-side

added added

removed removed

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