/elec/quadcopter

To get this branch, use:
bzr branch http://bzr.ed.am/elec/quadcopter

« back to all changes in this revision

Viewing changes to src/rc-interface/comms.cc

  • Committer: Tim Marston
  • Date: 2013-11-21 00:05:58 UTC
  • Revision ID: tim@ed.am-20131121000558-06xtcb4fue72td7q
updated 8-channel pulse width reading test program's comments

Show diffs side-by-side

added added

removed removed

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