Subversion Repositories FlightCtrl

Rev

Rev 2099 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "externalControl.h"
#include "configuration.h"
#include "controlMixer.h"

ExternalControl_t externalControl;
uint8_t externalControlActive = 0;

void EC_setNeutral(void) {
  // if necessary. From main.c.
  externalControl.config = 0;
  externalControl.pitch = 0;
  externalControl.roll = 0;
  externalControl.yaw = 0;
  externalControl.throttle = 0;

  // From main.c. What does it do??
  externalControl.digital[0] = 0x55;
}

void EC_periodicTaskAndPRYT(int16_t* PRYT) {
  if (externalControlActive) {
    externalControlActive--;
    PRYT[CONTROL_ELEVATOR] += externalControl.pitch * 8;
    PRYT[CONTROL_AILERONS] += externalControl.roll * 8;
    PRYT[CONTROL_THROTTLE] += externalControl.throttle * 8;
    PRYT[CONTROL_RUDDER] += externalControl.yaw * 8;
  }
}

uint8_t EC_getArgument(void) {
  return externalControl.config;
}

uint8_t EC_getCommand(void) {
  return externalControl.free;
}

// not implemented.
int16_t EC_getVariable(uint8_t varNum) {
  return 0;
}

uint8_t EC_getSignalQuality(void) {
  if (externalControlActive > 40)
    // Configured and heard from recently
    return SIGNAL_GOOD;

  if (externalControlActive)
    // Configured and heard from
    return SIGNAL_OK;

  if (!(externalControl.config & 0x01 && dynamicParams.externalControl > 128))
    // External control is not even configured.
    return NO_SIGNAL;

  // Configured but expired.
  return SIGNAL_LOST;
}