ubitx-v5d-xcvr/ubitx_iop/RigMode.h

294 lines
6.8 KiB
C
Raw Normal View History

2020-05-26 00:11:36 -04:00
//======================================================================
// RigMode.h
//======================================================================
#ifndef __RigMode_h__
#define __RigMode_h__
#include "audio.h"
2020-05-26 00:11:36 -04:00
//======================================================================
// basic_mode
2020-05-26 00:11:36 -04:00
//
// A basic rig mode. It can perform actions on_entry() and on_exit(),
// as well as on_tx() and on_rx(). These actions are defined in an
// appropriate subclass. In addition, the basic mode support an audio
// audio band pass filter with wide, medium, and narrow modes.
2020-05-26 00:11:36 -04:00
//======================================================================
class basic_mode {
2020-05-26 00:11:36 -04:00
public:
basic_mode(mode_config& c, RigAudio& a, bp_filter& f) :
config_(c), audio_(a), filter_(f), active_(false), transmitting_(false)
2020-05-26 00:11:36 -04:00
{
}
virtual ~basic_mode() {}
2020-05-26 00:11:36 -04:00
inline mode_config& config() { return config_; }
2020-05-26 00:11:36 -04:00
inline RigAudio& audio() { return audio_; }
2020-05-26 00:11:36 -04:00
inline bp_filter& filter() { return filter_; }
2020-05-26 00:11:36 -04:00
// 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 on_entry() = 0;
2020-05-26 00:11:36 -04:00
// Called upon mode exit. Should clean everything up that it used,
// and not make assumptions about which mode is being entered next.
virtual void on_exit() = 0;
2020-05-26 00:11:36 -04:00
// Called when transmitting.
virtual void on_tx() = 0;
2020-05-26 00:11:36 -04:00
// Called when receiving.
virtual void on_rx() = 0;
2020-05-26 00:11:36 -04:00
inline void enter() {
if (active_) {
2020-05-26 00:11:36 -04:00
// 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;
on_entry();
2020-05-26 00:11:36 -04:00
}
}
inline void exit() {
if (transmitting_) {
2020-05-26 00:11:36 -04:00
// 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;
on_exit();
2020-05-26 00:11:36 -04:00
}
}
inline bool is_active() { return active_; }
inline bool is_inactive() { return !active_; }
2020-05-26 00:11:36 -04:00
inline void tx() {
if (transmitting_) {
2020-05-26 00:11:36 -04:00
// 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;
on_tx();
2020-05-26 00:11:36 -04:00
}
}
inline void rx() {
if (!transmitting_) {
2020-05-26 00:11:36 -04:00
// 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;
on_rx();
2020-05-26 00:11:36 -04:00
}
}
inline bool is_tx() const { return transmitting_; }
inline bool is_rx() const { return !transmitting_; }
2020-05-26 00:11:36 -04:00
inline void set_rx_filter(rx_filter f) {
filter_.disable();
config_.filter = f;
filter_.init(config_.filter_cfg[static_cast<int>(config_.filter)]);
filter_.enable();
#if defined(DEBUG)
switch(config_.filter) {
case rx_filter::wide:
USBDEBUG("selected wide filter");
break;
case rx_filter::medium:
USBDEBUG("selected medium filter");
break;
case rx_filter::narrow:
USBDEBUG("selected narrow filter");
break;
}
#endif
}
2020-05-26 00:11:36 -04:00
private:
mode_config& config_;
RigAudio& audio_;
bp_filter& filter_;
bool active_;
bool transmitting_;
2020-05-26 00:11:36 -04:00
};
//======================================================================
// ssb_mode
2020-05-26 00:11:36 -04:00
//======================================================================
class ssb_mode : public basic_mode
2020-05-26 00:11:36 -04:00
{
public:
ssb_mode(ssb_config& c, RigAudio& a, bp_filter& f, speech_comp& s, bool default_mic=true) :
basic_mode(c, a, f), use_mic_(default_mic), comp_(s) {}
virtual void on_entry()
2020-05-26 00:11:36 -04:00
{
set_rx_filter(config().filter);
if (comp_.is_enabled()) {
enable_comp();
}
2020-05-26 00:11:36 -04:00
audio().unmuteRx();
audio().muteAllTx();
USBDEBUG("SSB mode entered");
}
virtual void on_exit() {
2020-05-26 00:11:36 -04:00
audio().muteAllTx();
audio().muteRx();
disable_comp();
2020-05-26 00:11:36 -04:00
USBDEBUG("SSB mode exited");
}
virtual void on_tx()
2020-05-26 00:11:36 -04:00
{
audio().muteRx();
if (use_mic_) {
2020-05-26 00:11:36 -04:00
audio().unmuteMicIn();
} else {
audio().unmuteLineIn();
}
USBDEBUG("SSB mode transmitting");
}
virtual void on_rx()
2020-05-26 00:11:36 -04:00
{
if (use_mic_) {
2020-05-26 00:11:36 -04:00
audio().muteMicIn();
} else {
audio().muteLineIn();
}
audio().unmuteRx();
USBDEBUG("SSB mode receiving");
}
void set_mic_in()
2020-05-26 00:11:36 -04:00
{
if (is_rx()) {
2020-05-26 00:11:36 -04:00
// can't switch inputs while already transmitting
use_mic_ = true;
2020-05-26 00:11:36 -04:00
}
USBDEBUG("SSB mode - Mic In set");
}
void set_line_in()
2020-05-26 00:11:36 -04:00
{
if (is_rx()) {
2020-05-26 00:11:36 -04:00
// can't switch inputs while already transmitting
use_mic_ = false;
2020-05-26 00:11:36 -04:00
}
USBDEBUG("SSB mode - Line In set");
}
inline void enable_comp() { comp_.enable(); }
inline void disable_comp() { comp_.disable(); }
2020-05-26 00:11:36 -04:00
private:
bool use_mic_;
speech_comp& comp_;
2020-05-26 00:11:36 -04:00
};
//======================================================================
// digi_mode
2020-05-26 00:11:36 -04:00
//======================================================================
class digi_mode : public basic_mode
2020-05-26 00:11:36 -04:00
{
public:
digi_mode(digi_config& c, RigAudio& a, bp_filter& f) :
basic_mode(c, a, f) {}
virtual void on_entry()
2020-05-26 00:11:36 -04:00
{
set_rx_filter(config().filter);
2020-05-26 00:11:36 -04:00
audio().unmuteRx();
audio().muteAllTx();
USBDEBUG("Digi mode entered");
2020-05-26 00:11:36 -04:00
}
virtual void on_exit() {
2020-05-26 00:11:36 -04:00
audio().muteAllTx();
audio().muteRx();
USBDEBUG("Digi mode exited");
2020-05-26 00:11:36 -04:00
}
virtual void on_tx()
2020-05-26 00:11:36 -04:00
{
audio().muteRx();
audio().unmuteUSBIn();
USBDEBUG("Digi mode transmitting");
2020-05-26 00:11:36 -04:00
}
virtual void on_rx()
2020-05-26 00:11:36 -04:00
{
audio().muteUSBIn();
audio().unmuteRx();
USBDEBUG("Digi mode receiving");
}
2020-05-26 00:11:36 -04:00
};
//======================================================================
// cw_mode
2020-05-26 00:11:36 -04:00
//======================================================================
class cw_mode : public basic_mode
2020-05-26 00:11:36 -04:00
{
public:
cw_mode(cw_config& c, RigAudio& a, bp_filter& f):
basic_mode(c, a, f) {}
virtual void on_entry()
2020-05-26 00:11:36 -04:00
{
set_rx_filter(config().filter);
2020-05-26 00:11:36 -04:00
audio().unmuteRx();
audio().muteAllTx();
USBDEBUG("CW mode entered");
}
virtual void on_exit() {
2020-05-26 00:11:36 -04:00
audio().muteAllTx();
audio().muteRx();
USBDEBUG("CW mode exited");
}
virtual void on_tx()
2020-05-26 00:11:36 -04:00
{
// 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 on_rx()
2020-05-26 00:11:36 -04:00
{
USBDEBUG("CW mode receiving");
}
};
#endif
//======================================================================
// EOF
//======================================================================