//======================================================================
// TR.cpp
//======================================================================

#include <Arduino.h>
#include "TR.h"

UBitxTR TR(DSP);

void UBitxTR::update(bool cw) {
  updatePTT();
  updateVOX();
  updateKey();
  
  if (isTX) {
    // If we are currently transmitting, then ANY T/R release (key
    // release) will result in exitting transmit... except for VOX
    // and CAT which can only function as a release if it was enabled.
    if (pttReleased() || keyReleased() || 
        (voxEnable && voxDeactivated()) ||
        (catEnable && catDeactivated())) {
      // first, stop transmitting; then, setup RX audio
      DBGCMD( setRX()  );
      DBGCMD( dsp.rx() );
    }
  } else {
    if ((pttEnable && pttPressed()) || (voxEnable && voxActivated())) {
      // first, setup TX audio; then, start transmitting (from Mic)
      DBGCMD( dsp.txMicIn() );
      DBGCMD( setTX()       );
    } else if (keyEnable && keyPressed()) {
      // first, setup TX audio; then, start transmitting (from Line In)
      DBGCMD( dsp.txLineIn() );
      DBGCMD( setTX()        );
    } else if (catEnable && catActivated()) {
      // first, setup TX audio; then, start transmitting (USB)
      DBGCMD( dsp.txUSBIn() );
      DBGCMD( setTX()       );
    }
  }    
}

//======================================================================
// EOF
//======================================================================
