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

  • Committer: Tim Marston
  • Date: 2014-01-08 22:38:10 UTC
  • Revision ID: tim@ed.am-20140108223810-o1mhgns6tath533c
added (unfinished) rc-interface module to src; added arduino.mk

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
#include "receiver.h"
7
7
#include "config.h"
8
 
#include "common.h"
9
8
#include <Arduino.h>
10
9
#include <limits.h>
11
10
 
56
55
}
57
56
 
58
57
 
59
 
bool Receiver::read_channels( int channel_values[] )
 
58
static unsigned long calculate_duration( unsigned long then, unsigned long now )
 
59
{
 
60
        return now - then;
 
61
        
 
62
        if( now < then )
 
63
                return now + ( ULONG_MAX - then );
 
64
        else
 
65
                return now - then;
 
66
}
 
67
 
 
68
 
 
69
bool Receiver::read_channels( unsigned long channel_values[] )
60
70
{
61
71
        static unsigned long last_pulse_down = 0;
62
72
        static int next_channel = 0;
94
104
                        {
95
105
                                // store channel value
96
106
                                int channel = channel_order_[ next_channel ] - 1;
97
 
                                channel_values[ channel ] = MAX_CHANNEL_VALUE *
98
 
                                        ( duration - MIN_PULSE_WIDTH ) /
99
 
                                        ( MAX_PULSE_WIDTH - MIN_PULSE_WIDTH );
 
107
                                channel_values[ channel ] = duration;
100
108
 
101
109
                                // we got a channel
102
110
                                next_channel++;