25
25
#include "config.h"
26
26
#include "Arduino.h"
27
27
#include <avr/pgmspace.h>
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 )
37
30
// the buffer for the message
56
52
static bool _do_draw_reset;
55
#define MASK_MODE_SIZE 0x07
56
#define MASK_MODE_POS 0x40
59
58
void reset_message_param( int message_num )
61
switch( _message_modes[ message_num ] )
64
_message_params[ message_num ] = -BIG_SEGMENTS;
67
_message_params[ message_num ] = -HALF_SEGMENTS;
71
_message_params[ message_num ] = -( BIG_SEGMENTS -
72
TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
76
_message_params[ message_num ] = -( HALF_SEGMENTS -
77
TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
83
void Text::set_message( int message_num, PString &pstring )
86
_message_lens[ message_num ] = pstring.length();
90
void Text::set_message_mode( int message_num, char mode )
92
_message_modes[ message_num ] = mode;
93
reset_message_param( message_num );
60
if( _message_modes[ message_num ] & Text::MODE_HSCROLL )
62
switch( _message_modes[ message_num ] & MASK_MODE_SIZE )
64
case Text::MODE_ONEQUARTER:
65
_message_params[ message_num ] = -NUM_SEGMENTS / 4; break;
66
case Text::MODE_ONETHIRD:
67
_message_params[ message_num ] = -NUM_SEGMENTS / 3; break;
69
_message_params[ message_num ] = -NUM_SEGMENTS / 2; break;
70
case Text::MODE_TWOTHIRDS:
71
_message_params[ message_num ] = -NUM_SEGMENTS * 2 / 3; break;
72
case Text::MODE_THREEQUARTERS:
73
_message_params[ message_num ] = -NUM_SEGMENTS * 3 / 4; break;
75
_message_params[ message_num ] = -NUM_SEGMENTS; break;
80
switch( _message_modes[ message_num ] & MASK_MODE_SIZE )
82
case Text::MODE_ONEQUARTER:
83
_message_params[ message_num ] = NUM_SEGMENTS / 4; break;
84
case Text::MODE_ONETHIRD:
85
_message_params[ message_num ] = NUM_SEGMENTS / 3; break;
87
_message_params[ message_num ] = NUM_SEGMENTS / 2; break;
88
case Text::MODE_TWOTHIRDS:
89
_message_params[ message_num ] = NUM_SEGMENTS * 2 / 3; break;
90
case Text::MODE_THREEQUARTERS:
91
_message_params[ message_num ] = NUM_SEGMENTS * 3 / 4; break;
93
_message_params[ message_num ] = NUM_SEGMENTS; break;
95
_message_params[ message_num ] = -( _message_params[ message_num ] -
96
TextRenderer::get_width( _message_lens[ message_num ],
97
_message_scale[ message_num ] ) ) / 2;
101
106
_last_millis = ::millis();
102
107
_do_draw_reset = false;
109
// clear all message modes (disable messages)
110
for( int a = 0; a < NUM_MESSAGE_BUFFERS; a++ )
111
_message_modes[ a ] = 0;
104
113
// reset the text renderer's output buffer
105
114
TextRenderer::reset_buffer();
118
void Text::set_up_message( int message_num, char mode, char scale )
120
_message_modes[ message_num ] = mode;
121
_message_scale[ message_num ] = scale;
125
void Text::set_message_text( int message_num, PString &pstring )
128
_message_lens[ message_num ] = pstring.length();
109
132
void Text::draw_reset()
111
134
// how many milliseconds have elapsed since last frame?
121
void Text::draw( int message_num, int segment )
144
static void draw_message( int message_num, int segment )
146
TextRenderer::buffer_in_use();
123
148
// perform a mid-frame reset, as necessary
124
if( _do_draw_reset && segment > NUM_SEGMENTS / 2 ) {
125
_do_draw_reset = false;
149
if( _do_draw_reset ) // && segment > NUM_SEGMENTS / 2 )
151
// reset message param
152
reset_message_param( message_num );
127
if( _message_modes[ message_num ] & MODE_HSCROLL )
129
// add to horizontal scroll position
154
// add to horizontal scroll position
155
if( _message_modes[ message_num ] & Text::MODE_HSCROLL ) {
130
156
_message_params[ message_num ] +=
131
157
_duration * TEXT_SCROLL_SPEED / 1000;
132
158
long excess = _message_params[ message_num ] -
133
TextRenderer::get_width( _message_lens[ message_num ] );
159
TextRenderer::get_width( _message_lens[ message_num ],
160
_message_scale[ message_num ] );
134
161
if( excess >= 0 ) {
135
162
reset_message_param( message_num );
136
163
_message_params[ message_num ] += excess;
141
168
// calculate the width
143
switch( _message_modes[ message_num ] & 0x1c )
170
switch( _message_modes[ message_num ] & MASK_MODE_SIZE )
145
case MODE_ONEQUARTER:
172
case Text::MODE_ONEQUARTER:
146
173
width = NUM_SEGMENTS / 4;
175
case Text::MODE_ONETHIRD:
149
176
width = NUM_SEGMENTS / 3;
178
case Text::MODE_HALF:
152
179
width = NUM_SEGMENTS / 2;
181
case Text::MODE_TWOTHIRDS:
155
182
width = NUM_SEGMENTS * 2 / 3;
157
case MODE_THREEQUARTERS:
184
case Text::MODE_THREEQUARTERS:
158
185
width = NUM_SEGMENTS * 3 / 4;
161
188
width = NUM_SEGMENTS;
165
192
// convert segment to display-space
166
switch( _message_modes[ message_num ] & 0x03 )
193
switch( _message_modes[ message_num ] & MASK_MODE_POS )
169
196
if( segment < width / 2 )
170
197
segment += width / 2;
171
198
else if( segment >= NUM_SEGMENTS - width / 2 )
186
215
TextRenderer::render(
187
_messages[ message_num ], _message_lens[ message_num ],
216
Text::_messages[ message_num ], _message_lens[ message_num ],
188
217
(long)segment + _message_params[ message_num ],
189
_message_modes[ message_num ] & 1 == 0, 0 );
218
( _message_modes[ message_num ] & MASK_MODE_POS ) == Text::MODE_BOTTOM,
219
0, _message_scale[ message_num ] );
223
void Text::draw( int segment )
225
// draw any active messages
226
for( int a = 0; a < NUM_MESSAGE_BUFFERS; a++ )
227
if( _message_modes[ a ] & MASK_MODE_SIZE )
228
draw_message( a, segment );
230
// turn off any requested draw reset after all messages are drawn
231
_do_draw_reset = false;