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

  • Committer: Tim Marston
  • Date: 2012-03-09 23:42:20 UTC
  • Revision ID: tim@ed.am-20120309234220-xr1vxzve0o5n2oss
added support for eclipse project and converted to a manual Makefile

Show diffs side-by-side

added added

removed removed

1
1
/*
2
 
 * digital_clock.cc
 
2
 * digital_clock_mode.cc
3
3
 *
4
4
 * Copyright (C) 2011 Tim Marston <tim@ed.am> and Dan Marston.
5
5
 *
20
20
 * You should have received a copy of the GNU Lesser General Public License
21
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
22
 */
23
 
#include "digital_clock.h"
24
 
#include "common.h"
 
23
#include "digital_clock_mode.h"
 
24
#include "display.h"
25
25
#include "text.h"
26
26
#include "text_renderer.h"
27
27
#include "time.h"
28
28
 
29
29
 
30
 
// font flavour
31
 
static int _flavour = 0;
32
 
 
33
 
 
34
 
static void set_message( bool update )
35
 
{
 
30
DigitalClockMode::DigitalClockMode()
 
31
        :
 
32
        MinorMode( 4 )
 
33
{
 
34
}
 
35
 
 
36
 
 
37
void DigitalClockMode::press()
 
38
{
 
39
        MinorMode::press();
 
40
 
 
41
//      set_message( false );
 
42
}
 
43
 
 
44
 
 
45
void DigitalClockMode::draw( int segment )
 
46
{
 
47
        Text::draw( 0, segment );
 
48
//      Text::draw( 1, segment );
 
49
        TextRenderer::output_buffer();
 
50
}
 
51
 
 
52
 
 
53
void DigitalClockMode::draw_reset()
 
54
{
 
55
        // gotta update message, the time might have changed!
 
56
        set_message( true );
 
57
 
 
58
        Text::draw_reset();
 
59
}
 
60
 
 
61
 
 
62
void DigitalClockMode::activate()
 
63
{
 
64
        MinorMode::activate();
 
65
 
 
66
        Display::leds_off();
 
67
 
 
68
        Text::reset();
 
69
        set_message( false );
 
70
}
 
71
 
 
72
 
 
73
void DigitalClockMode::set_message( bool update )
 
74
{
 
75
        Time &time = Time::get_instance();
 
76
 
36
77
        PString str0( Text::_messages[ 0 ], MESSAGE_LEN );
37
78
//      PString str1( Text::_messages[ 1 ], MESSAGE_LEN );
38
79
        str0.begin();
54
95
//              }
55
96
//              break;
56
97
//      case 1:
57
 
                str0.format( "%d%s %s, %d", Time::get_day(),
58
 
                                        Time::get_day_suffix(),
59
 
                                        Time::get_month_name(), Time::get_year() );
 
98
                str0.format( "%d%s %s, %d", time.get_day(),
 
99
                                        time.get_day_suffix(),
 
100
                                        time.get_month_name(), time.get_year() );
60
101
                Text::set_message( 0, str0 );
61
102
//              Text::set_message( 1, str1 );
62
103
                if( !update ) {
68
109
//              break;
69
110
//      }
70
111
 
71
 
        TextRenderer::select_font( _flavour );
72
 
}
73
 
 
74
 
 
75
 
void digital_clock_press()
76
 
{
77
 
        if( ++_flavour >= 4 )
78
 
                _flavour = 0;
79
 
}
80
 
 
81
 
 
82
 
void digital_clock_draw( int segment )
83
 
{
84
 
        Text::draw( 0, segment );
85
 
//      Text::draw( 1, segment );
86
 
        TextRenderer::output_buffer();
87
 
}
88
 
 
89
 
 
90
 
void digital_clock_draw_reset()
91
 
{
92
 
        // gotta update message, the time might have changed!
93
 
        set_message( true );
94
 
 
95
 
        Text::draw_reset();
96
 
}
97
 
 
98
 
 
99
 
void digital_clock_activate()
100
 
{
101
 
        leds_off();
102
 
 
103
 
        Text::reset();
104
 
        set_message( false );
105
 
 
106
 
        _flavour = 0;
 
112
        TextRenderer::select_font( get_flavour() );
107
113
}