/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: 2012-05-17 22:49:36 UTC
  • Revision ID: tim@ed.am-20120517224936-0wgyem932dlq5bs4
various tweaks, a (failed) attempt to fix text reset bug and added TODO

Show diffs side-by-side

added added

removed removed

27
27
#include "Arduino.h"
28
28
 
29
29
 
30
 
 
31
 
void InfoMode::draw_reset()
 
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()
32
74
{
33
75
        switch( _flavour )
34
76
        {
35
77
        case 0: {
36
78
                        PString str0( Text::_messages[ 0 ], MESSAGE_LEN * 4 );
 
79
                        str0.begin();
37
80
                        str0.format(
38
81
                                        "Propeller Clock mk.1   ...   "
39
 
                                        "Created by Tim and Dan Marston in 2012   ...   "
 
82
                                        "Created by Tim and Dan Marston in 2011   ...   "
40
83
                                        "http://ed.am/dev/elec/propeller-clock" );
41
 
                        Text::set_message_text( 0, str0 );
 
84
                        Text::set_message( 0, str0 );
42
85
                }
43
86
                break;
44
87
        case 1: {
45
88
                        PString str0( Text::_messages[ 0 ], MESSAGE_LEN );
46
89
                        PString str1( Text::_messages[ 1 ], MESSAGE_LEN );
 
90
                        str0.begin();
 
91
                        str1.begin();
47
92
                        str0.format( "RPM" );
48
93
                        unsigned long millis = ::millis();
49
94
                        str1.format( "%ld",
50
95
                                        (unsigned long)60 * 1000 / ( millis - _millis_last ) );
51
96
                        _millis_last = millis;
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 );
 
97
                        Text::set_message( 0, str0 );
 
98
                        Text::set_message( 1, str1 );
66
99
                }
67
100
                break;
68
101
        }
69
102
}
70
103
 
71
104
 
72
 
void InfoMode::activate()
 
105
void info_mode_activate()
73
106
{
74
107
        _flavour = 0;
75
108
        _millis_last = ::millis();
76
109
 
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
 
        }
 
110
        // reset messages
 
111
        reset_messages();
108
112
}