-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPPM.h
80 lines (69 loc) · 2.68 KB
/
PPM.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
#ifndef PPM_H
#define PPM_H
#include "mbed.h"
#include "PERIPHERALS.h"
uint16_t channelVal[6];
void measureChannel(); //gets all channel values
void printChannelVals(bool printChannel);
uint8_t currentChannel; //to keep track of which channel is being read
void measureChannel(){
int elapsedTime = t.read_us();
//if any pulse shorter than 1000us, discard as garbage
if(elapsedTime < 900){
t.reset();
return;
}
else{
//if start/stop sequence, then set currentChannel = 1 and begin to read
if(elapsedTime > 2100) {
currentChannel = 1;
t.reset();
return;
}
//read channel value
else if(elapsedTime >= 1000 && elapsedTime <= 2000){
if(currentChannel == 1){
channelVal[0] = elapsedTime;
currentChannel = 2;
t.reset();
return;
}
else if(currentChannel == 2){
channelVal[1] = elapsedTime;
currentChannel = 3;
t.reset();
return;
}
else if(currentChannel == 3){
channelVal[2] = elapsedTime;
currentChannel = 4;
t.reset();
return;
}
else if(currentChannel == 4){
channelVal[3] = elapsedTime;
currentChannel = 5;
t.reset();
return;
}
else if(currentChannel == 5){
channelVal[4] = elapsedTime;
currentChannel = 6;
t.reset();
return;
}
else if(currentChannel == 6){
channelVal[5] = elapsedTime;
currentChannel = 0;
t.reset();
return;
}
}
}
}
void printChannelVals(bool printChannel){
if(printChannel)
pc.printf("1: %d ; 2: %d ; 3: %d ; 4: %d\n", channelVal[0], channelVal[1], channelVal[2], channelVal[3]);
}
#endif