Subversion Repositories FlightCtrl

Rev

Rev 1617 | Rev 1821 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1617 Rev 1775
1
#include "externalcontrol.h"
1
#include "externalcontrol.h"
2
#include "configuration.h"
2
#include "configuration.h"
3
#include "controlMixer.h"
3
#include "controlMixer.h"
4
 
4
 
5
ExternalControl_t externalControl;
5
ExternalControl_t externalControl;
6
uint8_t externalControlActive;
6
uint8_t externalControlActive;
7
 
7
 
8
int16_t EC_PRTY[4];
8
int16_t EC_PRTY[4];
9
 
9
 
10
// TODO: Who is going to call this
10
// TODO: Who is going to call this
11
void EC_setNeutral(void) {
11
void EC_setNeutral(void) {
12
  // if necessary. From main.c.
12
  // if necessary. From main.c.
13
  externalControl.config = 0;
13
  externalControl.config = 0;
14
  externalControl.pitch = 0;
14
  externalControl.pitch = 0;
15
  externalControl.roll = 0;
15
  externalControl.roll = 0;
16
  externalControl.yaw = 0;
16
  externalControl.yaw = 0;
17
  externalControl.throttle = 0;
17
  externalControl.throttle = 0;
18
 
18
 
19
  // From main.c. What does it do??
19
  // From main.c. What does it do??
20
  externalControl.digital[0] = 0x55;
20
  externalControl.digital[0] = 0x55;
21
}
21
}
22
 
22
 
23
int16_t* EC_getPRTY(void) {
23
int16_t* EC_getPRTY(void) {
24
  return EC_PRTY;
24
  return EC_PRTY;
25
}
25
}
26
 
-
 
27
// not implemented.
26
 
28
uint8_t EC_getArgument(void) {
27
uint8_t EC_getArgument(void) {
29
  return 0;
28
  return externalControl.config;
30
}
-
 
31
 
29
}
32
// not implemented.
30
 
33
uint8_t EC_getCommand(void) {
31
uint8_t EC_getCommand(void) {
34
  return COMMAND_NONE;
32
  return externalControl.free;
35
}
33
}
36
 
34
 
37
// not implemented.
35
// not implemented.
38
int16_t EC_getVariable(uint8_t varNum) {
36
int16_t EC_getVariable(uint8_t varNum) {
39
  return 0;
37
  return 0;
40
}
38
}
41
 
39
 
42
void EC_update() {
40
void EC_update() {
43
  if (externalControlActive) {
41
  if (externalControlActive) {
44
    externalControlActive--;
42
    externalControlActive--;
45
    EC_PRTY[CONTROL_PITCH] = (int16_t) externalControl.pitch * (int16_t) staticParams.StickP;
43
    EC_PRTY[CONTROL_PITCH] = (int16_t) externalControl.pitch * (int16_t) staticParams.StickP;
46
    EC_PRTY[CONTROL_ROLL] = externalControl.roll * (int16_t) staticParams.StickP;
44
    EC_PRTY[CONTROL_ROLL] = externalControl.roll * (int16_t) staticParams.StickP;
47
    EC_PRTY[CONTROL_THROTTLE] = externalControl.throttle;
45
    EC_PRTY[CONTROL_THROTTLE] = externalControl.throttle;
48
    EC_PRTY[CONTROL_YAW] = externalControl.yaw; // No stickP or similar??????
46
    EC_PRTY[CONTROL_YAW] = externalControl.yaw; // No stickP or similar??????
49
  } else {
47
  } else {
50
    EC_PRTY[CONTROL_PITCH] = EC_PRTY[CONTROL_ROLL] = EC_PRTY[CONTROL_THROTTLE] = EC_PRTY[CONTROL_YAW] = 0;
48
    EC_PRTY[CONTROL_PITCH] = EC_PRTY[CONTROL_ROLL] = EC_PRTY[CONTROL_THROTTLE] = EC_PRTY[CONTROL_YAW] = 0;
51
  }
49
  }
52
}
50
}
53
 
51
 
54
uint8_t EC_getSignalQuality(void) {
52
uint8_t EC_getSignalQuality(void) {
55
  if (externalControlActive > 100)
53
  if (externalControlActive > 80)
56
    // Configured and heard from recently
54
    // Configured and heard from recently
57
    return SIGNAL_GOOD;
55
    return SIGNAL_GOOD;
58
 
56
 
59
  if (externalControlActive)
57
  if (externalControlActive)
60
    // Configured and heard from
58
    // Configured and heard from
61
    return SIGNAL_OK;
59
    return SIGNAL_OK;
62
 
60
 
63
  if (!(externalControl.config & 0x01 && dynamicParams.ExternalControl > 128))
61
  if (!(externalControl.config & 0x01 && dynamicParams.ExternalControl > 128))
64
    // External control is not even configured.
62
    // External control is not even configured.
65
    return NO_SIGNAL;
63
    return NO_SIGNAL;
66
 
64
 
67
  // Configured but expired.
65
  // Configured but expired.
68
  return SIGNAL_LOST;
66
  return SIGNAL_LOST;
69
}
67
}
70
 
68