ubitx-iop/ubitx_iop/RigMode.h
Rob French c27e2eddd6 More robust menu system, slightly. But still doesn't get correctly
displayed on the Raduino.  See most recently Raduino (ubitx-v5d) commit.
2020-06-06 22:28:11 -05:00

416 lines
9.2 KiB
C++

//======================================================================
// RigMode.h
//======================================================================
#ifndef __RigMode_h__
#define __RigMode_h__
#include "audio.h"
// Exceptions not active (for Arduino, I assume?).
//enum IModeExceptions {
// MODE_ALREADY_ACTIVE = -1,
// MODE_STILL_TRANSMITTING = -2,
// MODE_ALREADY_TRANSMITTING = -3,
// MODE_NOT_TRANSMITTING = -4,
//};
//======================================================================
// IMode
//
// Interface to a rig mode (SSB, CW, etc.).
//======================================================================
class IMode {
public:
IMode(IConfig& c, RigAudio& a, IFilter& f):
_config(c), _audio(a), _filter(f), _active(false), _transmitting(false)
{
}
virtual ~IMode() {}
inline IConfig& config() { return _config; }
inline RigAudio& audio() { return _audio; }
inline IFilter& filter() { return _filter; }
// Called upon mode entry. Should assume that the rig's state is
// "clean", i.e. that it still needs to enable anything it needs for
// use in the mode.
virtual void onEntry() = 0;
// Called upon mode exit. Should clean everything up that it used,
// and not make assumptions about which mode is being entered next.
virtual void onExit() = 0;
// Called when transmitting.
virtual void onTx() = 0;
// Called when receiving.
virtual void onRx() = 0;
inline void enter() {
if (_active) {
// Do nothing. Exceptions not active (for Arduino, I assume?).
//throw MODE_ALREADY_ACTIVE;
USBDEBUG("ERROR - tried to enter mode, but it's already active");
} else {
_active = true;
onEntry();
}
}
inline void exit() {
if (_transmitting) {
// Do nothing. Exceptions not active (for Arduino, I assume?).
//throw MODE_STILL_TRANSMITTING;
USBDEBUG("ERROR - tried to exit mode, but it's transmitting");
} else {
_active = false;
onExit();
}
}
inline bool isActive() { return _active; }
inline bool isInactive() { return !_active; }
inline void tx() {
if (_transmitting) {
// Do nothing. Exceptions not active (for Arduino, I assume?).
//throw MODE_ALREADY_TRANSMITTING;
USBDEBUG("ERROR - tried to start transmitting, but mode already is transmitting");
} else {
_transmitting = true;
onTx();
}
}
inline void rx() {
if (!_transmitting) {
// Do nothing. Exceptions not active (for Arduino, I assume?).
//throw MODE_NOT_TRANSMITTING;
USBDEBUG("ERROR - tried to start receiving, but mode already is receiving");
} else {
_transmitting = false;
onRx();
}
}
inline bool isTx() const { return _transmitting; }
inline bool isRx() const { return !_transmitting; }
virtual void setWideRxFilter() = 0;
virtual void setMediumRxFilter() = 0;
virtual void setNarrowRxFilter() = 0;
private:
IConfig& _config;
RigAudio& _audio;
IFilter& _filter;
bool _active;
bool _transmitting;
};
//======================================================================
// SSBMode
//======================================================================
class SSBMode : public IMode
{
public:
SSBMode(IConfig& c, RigAudio& a, IFilter& f, bool default_mic=true):
IMode(c, a, f), _use_mic(default_mic)
{
}
virtual void onEntry()
{
setWideRxFilter();
audio().unmuteRx();
audio().muteAllTx();
USBDEBUG("SSB mode entered");
}
virtual void onExit() {
audio().muteAllTx();
audio().muteRx();
USBDEBUG("SSB mode exited");
}
virtual void onTx()
{
audio().muteRx();
if (_use_mic) {
audio().unmuteMicIn();
} else {
audio().unmuteLineIn();
}
USBDEBUG("SSB mode transmitting");
}
virtual void onRx()
{
if (_use_mic) {
audio().muteMicIn();
} else {
audio().muteLineIn();
}
audio().unmuteRx();
USBDEBUG("SSB mode receiving");
}
void setMicIn()
{
if (isRx()) {
// can't switch inputs while already transmitting
_use_mic = true;
}
USBDEBUG("SSB mode - Mic In set");
}
void setLineIn()
{
if (isRx()) {
// can't switch inputs while already transmitting
_use_mic = false;
}
USBDEBUG("SSB mode - Line In set");
}
virtual void setWideRxFilter() {
((BPFilter&)filter()).setBand(300.0, 3100.0);
filter().enable();
USBDEBUG("set wide RX SSB filter");
}
virtual void setMediumRxFilter() {
((BPFilter&)filter()).setBand(500.0, 2900.0);
filter().enable();
USBDEBUG("set medium RX SSB filter");
}
virtual void setNarrowRxFilter() {
((BPFilter&)filter()).setBand(700.0, 2500.0);
filter().enable();
USBDEBUG("set narrow RX SSB filter");
}
private:
bool _use_mic;
};
//======================================================================
// DGTMode
//======================================================================
class DGTMode : public IMode
{
public:
DGTMode(IConfig& c, RigAudio& a, IFilter& f):
IMode(c, a, f)
{
}
virtual void onEntry()
{
setWideRxFilter();
audio().unmuteRx();
audio().muteAllTx();
USBDEBUG("DGT mode entered");
}
virtual void onExit() {
audio().muteAllTx();
audio().muteRx();
USBDEBUG("DGT mode exited");
}
virtual void onTx()
{
audio().muteRx();
audio().unmuteUSBIn();
USBDEBUG("DGT mode transmitting");
}
virtual void onRx()
{
audio().muteUSBIn();
audio().unmuteRx();
USBDEBUG("DGT mode receiving");
}
virtual void setWideRxFilter(){
((BPFilter&)filter()).setBand(300.0, 3100.0);
filter().enable();
USBDEBUG("set wide RX DGT filter");
}
virtual void setMediumRxFilter(){
((BPFilter&)filter()).setBand(500.0, 2900.0);
filter().enable();
USBDEBUG("set medium RX DGT filter");
}
virtual void setNarrowRxFilter(){
((BPFilter&)filter()).setCenterAndWidth(1500.0, 500.0);
filter().enable();
USBDEBUG("set narrow RX DGT filter");
}
};
//======================================================================
// CWMode
//======================================================================
class CWMode : public IMode
{
public:
CWMode(IConfig& c, RigAudio& a, IFilter& f):
IMode(c, a, f)
{
}
virtual void onEntry()
{
setWideRxFilter();
audio().unmuteRx();
audio().muteAllTx();
USBDEBUG("CW mode entered");
}
virtual void onExit() {
audio().muteAllTx();
audio().muteRx();
USBDEBUG("CW mode exited");
}
virtual void onTx()
{
// Currently not muting Rx, since the uBITX produces it's own
// sidetone... but I'm probably going to replace that with a S/W-
// generated sidetone.
USBDEBUG("CW mode transmitting");
}
virtual void onRx()
{
USBDEBUG("CW mode receiving");
}
virtual void setWideRxFilter(){
float st = float(((CWConfig&)config()).sidetone);
float width = 1000.0;
float low = st - (width * 0.5);
if (low < 300.0) {
low = 300.0;
}
((BPFilter&)filter()).setBand(low, low + width);
filter().enable();
USBDEBUG("set wide RX CW filter");
}
virtual void setMediumRxFilter(){
float st = float(((CWConfig&)config()).sidetone);
float width = 500.0;
float low = st - (width * 0.5);
if (low < 300.0) {
low = 300.0;
}
((BPFilter&)filter()).setBand(low, low + width);
filter().enable();
USBDEBUG("set medium RX CW filter");
}
virtual void setNarrowRxFilter(){
float st = float(((CWConfig&)config()).sidetone);
float width = 250.0;
float low = st - (width * 0.5);
if (low < 300.0) {
low = 300.0;
}
((BPFilter&)filter()).setBand(low, low + width);
filter().enable();
USBDEBUG("set narrow RX CW filter");
}
};
//======================================================================
// TTMode
//======================================================================
class TTMode : public IMode
{
public:
TTMode(IConfig& c, RigAudio& a, IFilter& f):
IMode(c, a, f)
{
}
virtual void onEntry()
{
setWideRxFilter();
audio().unmuteRx();
audio().muteAllTx();
USBDEBUG("Test (Two-Tone) mode entered");
}
virtual void onExit() {
audio().muteAllTx();
audio().muteRx();
USBDEBUG("Test (Two-Tone) mode exited");
}
virtual void onTx()
{
audio().muteRx();
audio().unmuteTTIn();
USBDEBUG("Test (Two-Tone) mode transmitting");
}
virtual void onRx()
{
audio().muteTTIn();
audio().unmuteRx();
USBDEBUG("Test (Two-Tone) mode receiving");
}
virtual void setWideRxFilter(){
((BPFilter&)filter()).setBand(300.0, 3100.0);
filter().enable();
USBDEBUG("set wide RX TT filter");
}
virtual void setMediumRxFilter(){
((BPFilter&)filter()).setBand(500.0, 2900.0);
filter().enable();
USBDEBUG("set medium RX TT filter");
}
virtual void setNarrowRxFilter(){
((BPFilter&)filter()).setBand(700.0, 2500.0);
filter().enable();
USBDEBUG("set narrow RX TT filter");
}
};
#endif
//======================================================================
// EOF
//======================================================================