Subversion Repositories FlightCtrl

Rev

Rev 1910 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2099 - 1
#include "externalControl.h"
1910 - 2
#include "configuration.h"
3
#include "controlMixer.h"
4
 
5
ExternalControl_t externalControl;
2099 - 6
uint8_t externalControlActive = 0;
7
// int16_t EC_PRTY[4];
8
// TODO: Who is going to call this
1910 - 9
 
10
void EC_setNeutral(void) {
2099 - 11
  // if necessary. From main.c.
12
  externalControl.config = 0;
13
  externalControl.pitch = 0;
14
  externalControl.roll = 0;
15
  externalControl.yaw = 0;
16
  externalControl.throttle = 0;
1910 - 17
 
2099 - 18
  // From main.c. What does it do??
19
  externalControl.digital[0] = 0x55;
1910 - 20
}
21
 
2099 - 22
void EC_periodicTaskAndPRTY(int16_t* PRTY) {
23
  if (externalControlActive) {
24
    externalControlActive--;
25
    PRTY[CONTROL_ELEVATOR] += externalControl.pitch * 8;
26
    PRTY[CONTROL_AILERONS] += externalControl.roll * 8;
27
    PRTY[CONTROL_THROTTLE] += externalControl.throttle * 8;
28
    PRTY[CONTROL_RUDDER] += externalControl.yaw * 8;
29
  }
1910 - 30
}
31
 
32
uint8_t EC_getArgument(void) {
2099 - 33
  return externalControl.config;
1910 - 34
}
35
 
36
uint8_t EC_getCommand(void) {
2099 - 37
  return externalControl.free;
1910 - 38
}
39
 
40
// not implemented.
41
int16_t EC_getVariable(uint8_t varNum) {
2099 - 42
  return 0;
1910 - 43
}
44
 
45
uint8_t EC_getSignalQuality(void) {
46
  if (externalControlActive > 40)
47
    // Configured and heard from recently
48
    return SIGNAL_GOOD;
2099 - 49
 
1910 - 50
  if (externalControlActive)
51
    // Configured and heard from
52
    return SIGNAL_OK;
2099 - 53
 
54
  if (!(externalControl.config & 0x01 && dynamicParams.externalControl > 128))
1910 - 55
    // External control is not even configured.
56
    return NO_SIGNAL;
2099 - 57
 
1910 - 58
  // Configured but expired.
59
  return SIGNAL_LOST;
60
}