Subversion Repositories FlightCtrl

Rev

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

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