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

  • Committer: Tim Marston
  • Date: 2012-04-29 15:27:05 UTC
  • Revision ID: tim@ed.am-20120429152705-9z2o01ugaewxipq6
change our BOARD to pro5v328

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "config.h"
26
26
#include "Arduino.h"
27
27
#include <avr/pgmspace.h>
28
 
#include "display.h"
29
 
 
30
 
 
31
 
// the proportion of the display to use (in segments)
32
 
#define BIG_SEGMENTS ( NUM_SEGMENTS * 2 / 3 )
33
 
#define SMALL_SEGMENTS ( NUM_SEGMENTS - BIG_TEXT_SEGMENTS )
34
 
#define HALF_SEGMENTS ( NUM_SEGMENTS / 2 )
35
28
 
36
29
 
37
30
// the buffer for the message
55
48
// recalculate message params, based on _duration
56
49
static bool _do_draw_reset;
57
50
 
 
51
// recalculate messages parameters (after message reset)
 
52
static unsigned char _message_recalc_flags;
 
53
 
58
54
 
59
55
void reset_message_param( int message_num )
60
56
{
61
 
        switch( _message_modes[ message_num ] )
62
 
        {
63
 
        case 'S':
64
 
                _message_params[ message_num ] = -BIG_SEGMENTS;
65
 
                break;
66
 
        case 's':
67
 
                _message_params[ message_num ] = -HALF_SEGMENTS;
68
 
                break;
69
 
        case 'B':
70
 
        case 'T':
71
 
                _message_params[ message_num ] = -( BIG_SEGMENTS -
72
 
                        TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
73
 
                break;
74
 
        case 'b':
75
 
        case 't':
76
 
                _message_params[ message_num ] = -( HALF_SEGMENTS -
77
 
                        TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
78
 
                break;
 
57
        if( _message_modes[ message_num ] & Text::MODE_HSCROLL )
 
58
        {
 
59
                switch( _message_modes[ message_num ] & 0x1c )
 
60
                {
 
61
                case Text::MODE_ONEQUARTER:
 
62
                        _message_params[ message_num ] = -NUM_SEGMENTS / 4; break;
 
63
                case Text::MODE_ONETHIRD:
 
64
                        _message_params[ message_num ] = -NUM_SEGMENTS / 3; break;
 
65
                case Text::MODE_HALF:
 
66
                        _message_params[ message_num ] = -NUM_SEGMENTS / 2; break;
 
67
                case Text::MODE_TWOTHIRDS:
 
68
                        _message_params[ message_num ] = -NUM_SEGMENTS * 2 / 3; break;
 
69
                case Text::MODE_THREEQUARTERS:
 
70
                        _message_params[ message_num ] = -NUM_SEGMENTS * 3 / 4; break;
 
71
                case Text::MODE_ALL:
 
72
                        _message_params[ message_num ] = -NUM_SEGMENTS; break;
 
73
                }
 
74
        }
 
75
        else
 
76
        {
 
77
                switch( _message_modes[ message_num ] & 0x1c )
 
78
                {
 
79
                case Text::MODE_ONEQUARTER:
 
80
                        _message_params[ message_num ] = NUM_SEGMENTS / 4; break;
 
81
                case Text::MODE_ONETHIRD:
 
82
                        _message_params[ message_num ] = NUM_SEGMENTS / 3; break;
 
83
                case Text::MODE_HALF:
 
84
                        _message_params[ message_num ] = NUM_SEGMENTS / 2; break;
 
85
                case Text::MODE_TWOTHIRDS:
 
86
                        _message_params[ message_num ] = NUM_SEGMENTS * 2 / 3; break;
 
87
                case Text::MODE_THREEQUARTERS:
 
88
                        _message_params[ message_num ] = NUM_SEGMENTS * 3 / 4; break;
 
89
                case Text::MODE_ALL:
 
90
                        _message_params[ message_num ] = NUM_SEGMENTS; break;
 
91
                }
 
92
                _message_params[ message_num ] = -( _message_params[ message_num ] -
 
93
                        TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
79
94
        }
80
95
}
81
96
 
87
102
}
88
103
 
89
104
 
90
 
void Text::set_message_mode( int message_num, char mode )
 
105
void Text::reset_message( int message_num, char mode )
91
106
{
92
107
        _message_modes[ message_num ] = mode;
93
 
        reset_message_param( message_num );
 
108
        _message_recalc_flags |= 1 << message_num;
94
109
}
95
110
 
96
111
 
100
115
        _duration = 0;
101
116
        _last_millis = ::millis();
102
117
        _do_draw_reset = false;
 
118
        _message_recalc_flags = 0;
103
119
 
104
120
        // reset the text renderer's output buffer
105
121
        TextRenderer::reset_buffer();
120
136
 
121
137
void Text::draw( int message_num, int segment )
122
138
{
 
139
        TextRenderer::buffer_in_use();
 
140
 
123
141
        // perform a mid-frame reset, as necessary
124
142
        if( _do_draw_reset && segment > NUM_SEGMENTS / 2 ) {
125
143
                _do_draw_reset = false;
126
144
 
127
 
                if( _message_modes[ message_num ] & MODE_HSCROLL )
128
 
                {
129
 
                        // add to horizontal scroll position
 
145
                // reset message param?
 
146
                if( _message_recalc_flags & ( 1 << message_num ) ) {
 
147
                        _message_recalc_flags &= ~( 1 << message_num );
 
148
                        reset_message_param( message_num );
 
149
                }
 
150
 
 
151
                // add to horizontal scroll position
 
152
                if( _message_modes[ message_num ] & MODE_HSCROLL ) {
130
153
                        _message_params[ message_num ] +=
131
154
                                _duration * TEXT_SCROLL_SPEED / 1000;
132
155
                        long excess = _message_params[ message_num ] -
176
199
        case MODE_BOTTOM:
177
200
                if( segment > ( NUM_SEGMENTS - width ) / 2 &&
178
201
                        segment < ( NUM_SEGMENTS - width ) / 2 + width )
179
 
                        segment -= ( NUM_SEGMENTS - width ) / 2;
 
202
                {
 
203
                        segment = width - ( segment - ( NUM_SEGMENTS - width ) / 2 );
 
204
                }               
180
205
                else
181
206
                        return;
182
207
                break;
186
211
        TextRenderer::render(
187
212
                _messages[ message_num ], _message_lens[ message_num ],
188
213
                (long)segment + _message_params[ message_num ],
189
 
                _message_modes[ message_num ] & 1 == 0, 0 );
 
214
                ( _message_modes[ message_num ] & 1 ) == 0, 0 );
190
215
}