ubitx-v5d-xcvr/ubitx_iop/ubitx_iop.ino
Rob French 564c35f397 Modifications, mainly based on a code walkthrough as well as adding some
debugging output.  Compiles, but untested.
2020-05-25 23:08:55 -05:00

180 lines
4.6 KiB
C++

//======================================================================
// ubitx_iop.ino
//======================================================================
#include <iopcomm.h>
#include "audio.h"
#include "config.h"
#include "ubitx_iop.h"
#include "keyer.h"
#include "rig.h"
#include "TxSwitch.h"
Keyer keyer{15, 3.0}; // NOTE: make configurable
RigConfig rigConfig;
RigAudio rigAudio{rigConfig.audio};
Rig rig{rigConfig, rigAudio};
CATSwitch catPTT;
//MicSwitch micPTTHelper;
GPIOSwitch micPTT(true, MIC_PTT_PIN);
//LineSwitch linePTTHelper;
GPIOSwitch linePTT(false, LINE_PTT_PIN);
elapsedMillis frameMillis;
unsigned frameCounter;
//======================================================================
void setup() {
// put your setup code here, to run once:
initCAT(38400, SERIAL_8N1);
USBDEBUG("setup started");
AudioMemory(20); // NOTE: Need to fine tune this. Have had errors due to this being too low.
initKeyLine();
rigAudio.init();
frameCounter = 0;
frameMillis = 0;
USBDEBUG("setup completed");
// audioInit();
/*
#if defined(FACTORY_CALIBRATION)
setRigMode(RIG_MODE_TEST);
#else
setRigMode(RIG_MODE_SSB);
#endif
*/
}
//======================================================================
void loop()
{
static char frame_status[100];
static bool paddle_loop = false;
RigMode oldRigMode;
frameCounter++;
if (rig.isCWMode()) {
if (keyer.do_paddles()) {
// Checking for T/R separately from the paddle loop, because it's
// possible we're already transmitting (PTT/Key being held), and
// we don't want to run the tx() actions if we're already in TX.
if (rig.isRx()) {
USBDEBUG("entered TX via paddles");
rig.tx();
}
paddle_loop = true;
if (keyer.is_down()) {
setKeyDown();
} else {
setKeyUp();
}
return; // return early for paddle responsiveness
} else {
if (paddle_loop) {
// If we exit the paddle loop (i.e. keyer completes its keying
// sequence), then we'll go back to receive, even if one of the
// PTT/Key lines is still held separately. General principle is
// that if "something" stops transmitting, then the rig will
// stop transmitting.
paddle_loop = false;
rig.rx();
USBDEBUG("exited TX from paddles");
}
}
}
rig.update();
oldRigMode = rig.modeNum();
// Update the mic PTT. We need to tell it if we're in SSB mode, so that
// it knows if it should switch to the mic input if pressed. We also
// need to make it inactive if we're in DGT mode, since only CAT will be
// used to start transmitting in that case.
micPTT.setSSBMode(rig.isSSBMode());
micPTT.update(rig.mode(), !rig.isDGTMode());
// Update the line PTT. We need to tell it if we're in SSB mode, so that
// it knows if it should switch to the line input if pressed. We also
// need to make it inactive if we're in DGT mode, since only CAT will be
// used to start transmitting in that case.
linePTT.setSSBMode(rig.isSSBMode());
linePTT.update(rig.mode(), !rig.isDGTMode());
serviceCAT();
// send current status @ 10 Hz
//if (frame10Hz > 100) {
if ((rig.modeNum() != oldRigMode)) { // || (rxFilter != oldRxFilter)) {
USBDEBUG("mode changed");
switch(rig.modeNum()) {
case RIG_MODE_LSB:
USBDEBUG("sending LSB mode status");
sendIOPSSBStatus(rigConfig.lsb);
break;
case RIG_MODE_USB:
USBDEBUG("sending USB mode status");
sendIOPSSBStatus(rigConfig.usb);
break;
case RIG_MODE_DGL:
USBDEBUG("sending DGL mode status");
sendIOPDGTStatus(rigConfig.dgl);
break;
case RIG_MODE_DGU:
USBDEBUG("sending DGU mode status");
sendIOPDGTStatus(rigConfig.dgu);
break;
case RIG_MODE_CWL:
USBDEBUG("sending CWL mode status");
sendIOPCWStatus(rigConfig.cwl);
break;
case RIG_MODE_CWU:
USBDEBUG("sending CWU mode status");
sendIOPCWStatus(rigConfig.cwu);
break;
case RIG_MODE_TTL:
USBDEBUG("sending TTL mode status");
sendIOPTestStatus();
break;
case RIG_MODE_TTU:
USBDEBUG("sending TTU mode status");
sendIOPTestStatus();
break;
}
//frame10Hz = 0;
}
if (frameMillis > 1000) {
#if defined(DEBUG)
sprintf(frame_status, "update: %d ms, %d frames\n", frameMillis, frameCounter);
USBDEBUG(frame_status);
#endif
}
//audioUpdate(); // was used to update the speech compressor
}
//======================================================================
// EOF
//======================================================================