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

  • Committer: Tim Marston
  • Date: 2013-03-31 17:07:36 UTC
  • Revision ID: tim@ed.am-20130331170736-hphm2hg0y6l7w6z1
made rtc-test's DS1307 library a symlink to the main one in src/util

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "Arduino.h"
28
28
 
29
29
 
30
 
// display flavour
31
 
static int _flavour = 0;
32
 
 
33
 
// previous millis
34
 
static unsigned long _millis_last = 0;
35
 
 
36
 
 
37
 
static void reset_messages()
38
 
{
39
 
        switch( _flavour )
40
 
        {
41
 
        case 0:
42
 
                Text::reset_message( 0, Text::MODE_TOP | Text::MODE_THREEQUARTERS |
43
 
                                Text::MODE_HSCROLL, Text::SCALE_SMALL );
44
 
                break;
45
 
        case 1:
46
 
                Text::reset_message( 0, Text::MODE_TOP | Text::MODE_HALF,
47
 
                                Text::SCALE_FAT );
48
 
                Text::reset_message( 1, Text::MODE_BOTTOM | Text::MODE_HALF,
49
 
                                Text::SCALE_FAT );
50
 
                break;
51
 
        }
52
 
}
53
 
 
54
 
 
55
 
void info_mode_press()
56
 
{
57
 
        if( ++_flavour >= 2 )
58
 
                _flavour = 0;
59
 
 
60
 
        // reset messages
61
 
        reset_messages();
62
 
}
63
 
 
64
 
 
65
 
void info_mode_draw( int segment )
66
 
{
67
 
        Text::draw( 0, segment );
68
 
        if( _flavour == 1 )
69
 
                Text::draw( 1, segment );
70
 
}
71
 
 
72
 
 
73
 
void info_mode_draw_reset()
 
30
 
 
31
void InfoMode::draw_reset()
74
32
{
75
33
        switch( _flavour )
76
34
        {
77
35
        case 0: {
78
36
                        PString str0( Text::_messages[ 0 ], MESSAGE_LEN * 4 );
79
 
                        str0.begin();
80
37
                        str0.format(
81
38
                                        "Propeller Clock mk.1   ...   "
82
 
                                        "Created by Tim and Dan Marston in 2011   ...   "
 
39
                                        "Created by Tim and Dan Marston in 2012   ...   "
83
40
                                        "http://ed.am/dev/elec/propeller-clock" );
84
 
                        Text::set_message( 0, str0 );
 
41
                        Text::set_message_text( 0, str0 );
85
42
                }
86
43
                break;
87
44
        case 1: {
88
45
                        PString str0( Text::_messages[ 0 ], MESSAGE_LEN );
89
46
                        PString str1( Text::_messages[ 1 ], MESSAGE_LEN );
90
 
                        str0.begin();
91
 
                        str1.begin();
92
47
                        str0.format( "RPM" );
93
48
                        unsigned long millis = ::millis();
94
49
                        str1.format( "%ld",
95
50
                                        (unsigned long)60 * 1000 / ( millis - _millis_last ) );
96
51
                        _millis_last = millis;
97
 
                        Text::set_message( 0, str0 );
98
 
                        Text::set_message( 1, str1 );
 
52
                        Text::set_message_text( 0, str0 );
 
53
                        Text::set_message_text( 1, str1 );
 
54
                }
 
55
                break;
 
56
        case 2: {
 
57
                        PString str0( Text::_messages[ 0 ], MESSAGE_LEN );
 
58
                        PString str1( Text::_messages[ 1 ], MESSAGE_LEN );
 
59
                        str0.format( "FPS" );
 
60
                        unsigned long millis = ::millis();
 
61
                        str1.format( "%ld",
 
62
                                        (unsigned long)1000 / ( millis - _millis_last ) );
 
63
                        _millis_last = millis;
 
64
                        Text::set_message_text( 0, str0 );
 
65
                        Text::set_message_text( 1, str1 );
99
66
                }
100
67
                break;
101
68
        }
102
69
}
103
70
 
104
71
 
105
 
void info_mode_activate()
 
72
void InfoMode::activate()
106
73
{
107
74
        _flavour = 0;
108
75
        _millis_last = ::millis();
109
76
 
110
 
        // reset messages
111
 
        reset_messages();
 
77
        reset_messages();
 
78
}
 
79
 
 
80
 
 
81
void InfoMode::press()
 
82
{
 
83
        if( ++_flavour >= 3 )
 
84
                _flavour = 0;
 
85
 
 
86
        reset_messages();
 
87
}
 
88
 
 
89
 
 
90
void InfoMode::reset_messages()
 
91
{
 
92
        Text::reset();
 
93
 
 
94
        switch( _flavour )
 
95
        {
 
96
        case 0:
 
97
                Text::set_up_message( 0, Text::MODE_TOP | Text::MODE_THREEQUARTERS |
 
98
                                Text::MODE_HSCROLL, Text::SCALE_SMALL );
 
99
                break;
 
100
        case 1: // fall through
 
101
        case 2:
 
102
                Text::set_up_message( 0, Text::MODE_TOP | Text::MODE_HALF,
 
103
                                Text::SCALE_FAT );
 
104
                Text::set_up_message( 1, Text::MODE_BOTTOM | Text::MODE_HALF,
 
105
                                Text::SCALE_FAT );
 
106
                break;
 
107
        }
112
108
}