/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock
71 by Tim Marston
added time set mode, made text renderer's buffer auto reset/output
1
/*
2
 * settings_mode.cc
3
 *
4
 * Copyright (C) 2011 Tim Marston <tim@ed.am> and Dan Marston.
5
 *
6
 * This file is part of propeller-clock (hereafter referred to as "this
7
 * program"). See http://ed.am/dev/software/arduino/propeller-clock for more
8
 * information.
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Lesser General Public License as published
12
 * by the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Lesser General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Lesser General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
#include "Arduino.h"
24
#include "settings_mode.h"
25
#include "text.h"
26
#include "text_renderer.h"
27
#include "time.h"
28
#include "common.h"
29
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
	{
76 by edam
switch button to no interim presses during settings mode; added NVRAM support
45
	case TIME_SET_IDX:
71 by Tim Marston
added time set mode, made text renderer's buffer auto reset/output
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
		}
76 by edam
switch button to no interim presses during settings mode; added NVRAM support
58
		break;
71 by Tim Marston
added time set mode, made text renderer's buffer auto reset/output
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 )
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 )
75 by Tim Marston
fixed time centring and display in settings mode
107
			str0.print( ( Time::get_hours() % 12 ) < 10? " " : "  " );
71 by Tim Marston
added time set mode, made text renderer's buffer auto reset/output
108
		else
75 by Tim Marston
fixed time centring and display in settings mode
109
			str0.format( "%d", Time::get_hours() % 12 );
71 by Tim Marston
added time set mode, made text renderer's buffer auto reset/output
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() );
75 by Tim Marston
fixed time centring and display in settings mode
120
		str0.print( ' ' );
71 by Tim Marston
added time set mode, made text renderer's buffer auto reset/output
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();
163
}