11
// the width of the display of a single channel (in chars)
21
static void draw_graph( int channel_values[] )
24
static char graph[ GRAPH_SIZE + 2 ];
25
static char inited_graph = false;
27
for( int a = 1; a < GRAPH_SIZE + 1; a++ )
30
graph[ GRAPH_SIZE + 1 ] = 0;
35
for( int a = 0; a < NUM_CHANNELS; a++ ) {
36
unsigned long value = min( channel_values[ a ], MAX_CHANNEL_VALUE );
37
int pos = ( GRAPH_SIZE ) * value / MAX_CHANNEL_VALUE;
38
graph[ pos + 1 ] = '^';
39
Serial.print( graph );
40
graph[ pos + 1 ] = '_';
42
Serial.println( "|" );
46
void Comms::write_channels( int channel_values[] )
48
// draw_graph( channel_values );
52
unsigned char *data = reinterpret_cast< unsigned char * >( channel_values );
53
Serial.write( data, sizeof( channel_values ) * NUM_CHANNELS );
57
bool Comms::read_channels( int channel_values[] )
59
static unsigned char buf[ sizeof( int ) * ( NUM_MOTORS + 1 ) ];
60
static unsigned int buflen = 0;
62
bool frame_complete = false;
64
while( buflen < sizeof( buf ) && Serial.available() )
67
buf[ buflen++ ] = Serial.read();
69
// check if we've got a frame
71
buf[ buflen - 1 ] == 0xff && buf[ buflen - 2 ] == 0xff )
73
// got a complete frame?
74
if( buflen == sizeof( buf ) ) {
75
frame_complete = true;
77
// copy channel values
79
reinterpret_cast< unsigned char * >( channel_values );
80
memcpy( buf, data, sizeof( int ) * NUM_MOTORS );
88
// reset read buffer in the case where the buffer is full, but there's been
89
// no end-of-frame marker (i.e., bad data)
90
if( buflen >= sizeof( buf ) )
93
return frame_complete;