-
Notifications
You must be signed in to change notification settings - Fork 0
/
Channel.h
82 lines (74 loc) · 1.97 KB
/
Channel.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
81
82
#pragma once
#include <WString.h>
#include <RCLib.h>
class Channel {
private:
int _chType;
int _value;
protected:
const char* _type;
int _inPin;
int _high;
int _low;
public:
void loop();
void setValue(int);
int getValue();
double getPerc();
const char* getType();
static const char* ELEVATOR;
static const char* AILERON;
static const char* THROTTLE;
static const char* RUDDER;
static const char* AUX1;
static const char* AUX2;
Channel(const char* type, int inPin, int low, int high);
};
const char* Channel::ELEVATOR = "elevator";
const char* Channel::AILERON = "aileron";
const char* Channel::THROTTLE = "throttle";
const char* Channel::RUDDER = "rudder";
const char* Channel::AUX1 = "aux1";
const char* Channel::AUX2 = "aux2";
Channel::Channel(const char* type, int inPin, int low, int high) {
this->_type = type;
this->_inPin = inPin;
this->_high = high;
this->_low = low;
// this->setValue(0);
// if(this->_inPin != NULL) pinMode(this->_inPin, INPUT); // input is controlled included library
}
void Channel::setValue(int v) {
// if(armed == true && v < Channel::PWM_NOSPIN) v = Channel::PWM_NOSPIN;
this->_value = v;
}
int Channel::getValue() {
return this->_value;
}
double Channel::getPerc() {
double p = map(this->getValue(), this->_low, this->_high, 0, 1000);
p /= 1000;
if(p > 1) p = 1;
if(p < 0) p = 0;
return p;
}
const char* Channel::getType() {
return this->_type;
}
void Channel::loop() {
// Serial.println("Channel Loop");
if(this->_inPin != NULL) {
for(int i = 0; i < NUM_RC_CHANNELS; ++i) {
if(RC_Channel_Pin[i] == this->_inPin) {
if(false && this->getType() == "throttle") { // debug
Serial.print(F("channel input: "));
Serial.print(this->_type);
Serial.print(F(": "));
Serial.print(RC_Channel_Value[i]);
Serial.println();
}
this->setValue(RC_Channel_Value[i]);
}
}
}
}