ubitx-v5d-xcvr/ubitx_iop.ino
Rob French 211d9ff9b4 (Temporarily?) resolved issue with no transmit output. It looks like
switching dacVolumes around from transmit to receive wasn't working as
expected.  Transmit audio through the DAC stayed muted.  If I need to
use that for smooth audio transitions, I'll need to do some more
research.
2020-05-03 01:27:54 -05:00

116 lines
2.8 KiB
C++

//======================================================================
// ubitx_iop.ino
//======================================================================
#include "ubitx_iop.h"
#include <Bounce2.h>
#define BOUNCE_WITH_PROMPT_DETECTION
RigMode rigMode = MODE_SSB;
IOPConfig iopConfig;
#define MIC_PTT_PIN 21
#define LINE_PTT_PIN 20
#define PTT_KEY_OUT_PIN 2
Bounce micPTT = Bounce();
Bounce linePTT = Bounce();
bool micPTT_active = false;
bool linePTT_active = false;
void checkPTT()
{
// Update the PTT lines. USB/DIGI is not part of this. CW should work, however.
micPTT.update();
linePTT.update();
if (rigMode == MODE_SSB || rigMode == MODE_CW) {
if (micPTT_active) {
// ignore line PTT; just wait for release of mic PTT
if (micPTT.rose()) {
digitalWrite(PTT_KEY_OUT_PIN, HIGH);
audioReceive();
micPTT_active = false;
}
} else if (linePTT_active) {
// ignore mic PTT; just wait for release of line PTT
if (linePTT.rose()) {
digitalWrite(PTT_KEY_OUT_PIN, HIGH);
audioReceive();
linePTT_active = false;
}
} else {
// Whichever PTT source was last active, will determine the TX audio source.
if (micPTT.fell()) {
audioSelectTxInput(TX_MIC_IN);
micPTT_active = true;
audioTransmit();
digitalWrite(PTT_KEY_OUT_PIN, LOW);
} else if (linePTT.fell()) {
audioSelectTxInput(TX_LINE_IN);
linePTT_active = true;
audioTransmit();
digitalWrite(PTT_KEY_OUT_PIN, LOW);
}
}
}
#if defined(DEBUG)
if (micPTT.fell()) {
USBSERIAL.println("Mic PTT pressed!");
} else if (micPTT.rose()) {
USBSERIAL.println("Mic PTT released!");
}
if (linePTT.fell()) {
USBSERIAL.println("Line PTT pressed!");
} else if (linePTT.rose()) {
USBSERIAL.println("Line PTT released!");
}
#endif
}
void setup() {
// put your setup code here, to run once:
initCAT(38400, SERIAL_8N1);
AudioMemory(12);
micPTT.attach(MIC_PTT_PIN, INPUT_PULLUP);
micPTT.interval(25);
linePTT.attach(LINE_PTT_PIN, INPUT_PULLUP);
linePTT.interval(25);
pinMode(PTT_KEY_OUT_PIN, OUTPUT);
digitalWrite(PTT_KEY_OUT_PIN, HIGH);
audioInit();
}
void loop() {
elapsedMillis frame_timer = 0;
checkPTT();
serviceCAT();
/*
#if defined(DEBUG)
int frame_skews = 0; // for debugging; see how often we skew frames
#endif
// put your main code here, to run repeatedly:
// Run at a nominal 20 Hz frame rate.
#if defined(DEBUG)
if (frame_timer > 50) {
frame_skews += 1;
}
#endif
while (frame_timer < 50) { // this doesn't seem like a good way to do this
}
*/
}
//======================================================================
// EOF
//======================================================================