1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
//
// comms.cc
//
#include "comms.h"
#include "config.h"
#include <Arduino.h>
// the width of the display of a single channel (in chars)
#define GRAPH_SIZE 7
void Comms::setup()
{
Serial.begin( 9600 );
}
static void draw_graph( int channel_values[] )
{
// init graph
static char graph[ GRAPH_SIZE + 2 ];
static char inited_graph = false;
if( !inited_graph ) {
for( int a = 1; a < GRAPH_SIZE + 1; a++ )
graph[ a ] = '_';
graph[ 0 ] = '|';
graph[ GRAPH_SIZE + 1 ] = 0;
inited_graph = true;
}
// draw channels
for( int a = 0; a < NUM_CHANNELS; a++ ) {
unsigned long value = min( channel_values[ a ], MAX_CHANNEL_VALUE );
int pos = ( GRAPH_SIZE ) * value / MAX_CHANNEL_VALUE;
graph[ pos + 1 ] = '^';
Serial.print( graph );
graph[ pos + 1 ] = '_';
}
Serial.println( "|" );
}
static void write_raw_channel_data( int channel_values[] )
{
Serial.write( -1 );
Serial.write( -1 );
unsigned char *data = reinterpret_cast< unsigned char * >( channel_values );
Serial.write( data, sizeof( channel_values ) * NUM_CHANNELS );
}
void Comms::write_channels( int channel_values[] )
{
// draw_graph( channel_values );
write_raw_channel_data( channel_values );
}
|