ubitx-v5d-xcvr/ubitx_iop.ino
Rob French f819e211da Significant reorganization of the code. Got rid of the audio classes,
just moved all the audio stuff into its own files.  Created a structure
for storing configuration data in... the intent is that it will be
stored to EEPROM (using EEPROMAnything).  It does compile now, but
haven't actually tried it out.  Notable learning points:  need to set
micGain AFTER selecting the mic input.  So lot of code now to take care
of trying to smoothly mute and unmute things.
2020-05-02 00:54:58 -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;
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
//======================================================================