2020-05-26 00:11:36 -04:00
|
|
|
//======================================================================
|
|
|
|
// RigMode.h
|
|
|
|
//======================================================================
|
|
|
|
|
|
|
|
#ifndef __RigMode_h__
|
|
|
|
#define __RigMode_h__
|
|
|
|
|
2020-05-27 23:45:37 -04:00
|
|
|
#include "audio.h"
|
|
|
|
|
2020-05-26 00:11:36 -04:00
|
|
|
//======================================================================
|
2020-06-14 01:11:18 -04:00
|
|
|
// basic_mode
|
2020-05-26 00:11:36 -04:00
|
|
|
//
|
2020-06-14 01:11:18 -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
|
|
|
//======================================================================
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
class basic_mode {
|
2020-05-26 00:11:36 -04:00
|
|
|
public:
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual ~basic_mode() {}
|
2020-05-26 00:11:36 -04:00
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
inline mode_config& config() { return config_; }
|
2020-05-26 00:11:36 -04:00
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
inline RigAudio& audio() { return audio_; }
|
2020-05-26 00:11:36 -04:00
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
inline bp_filter& filter() { return filter_; }
|
2020-05-27 23:45:37 -04:00
|
|
|
|
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.
|
2020-06-14 01:11:18 -04:00
|
|
|
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.
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_exit() = 0;
|
2020-05-26 00:11:36 -04:00
|
|
|
|
|
|
|
// Called when transmitting.
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_tx() = 0;
|
2020-05-26 00:11:36 -04:00
|
|
|
|
|
|
|
// Called when receiving.
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_rx() = 0;
|
2020-05-26 00:11:36 -04:00
|
|
|
|
|
|
|
inline void enter() {
|
2020-06-14 01:11:18 -04:00
|
|
|
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 {
|
2020-06-14 01:11:18 -04:00
|
|
|
active_ = true;
|
|
|
|
on_entry();
|
2020-05-26 00:11:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void exit() {
|
2020-06-14 01:11:18 -04:00
|
|
|
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 {
|
2020-06-14 01:11:18 -04:00
|
|
|
active_ = false;
|
|
|
|
on_exit();
|
2020-05-26 00:11:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -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() {
|
2020-06-14 01:11:18 -04:00
|
|
|
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 {
|
2020-06-14 01:11:18 -04:00
|
|
|
transmitting_ = true;
|
|
|
|
on_tx();
|
2020-05-26 00:11:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void rx() {
|
2020-06-14 01:11:18 -04:00
|
|
|
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 {
|
2020-06-14 01:11:18 -04:00
|
|
|
transmitting_ = false;
|
|
|
|
on_rx();
|
2020-05-26 00:11:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
inline bool is_tx() const { return transmitting_; }
|
|
|
|
inline bool is_rx() const { return !transmitting_; }
|
2020-05-26 00:11:36 -04:00
|
|
|
|
2020-06-14 01:11:18 -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;
|
2020-05-27 23:45:37 -04:00
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
case rx_filter::medium:
|
|
|
|
USBDEBUG("selected medium filter");
|
|
|
|
break;
|
2020-05-27 23:45:37 -04:00
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
case rx_filter::narrow:
|
|
|
|
USBDEBUG("selected narrow filter");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2020-05-27 23:45:37 -04:00
|
|
|
|
2020-05-26 00:11:36 -04:00
|
|
|
private:
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
mode_config& config_;
|
|
|
|
RigAudio& audio_;
|
|
|
|
bp_filter& filter_;
|
|
|
|
bool active_;
|
|
|
|
bool transmitting_;
|
2020-05-26 00:11:36 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
//======================================================================
|
2020-06-14 01:11:18 -04:00
|
|
|
// ssb_mode
|
2020-05-26 00:11:36 -04:00
|
|
|
//======================================================================
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
class ssb_mode : public basic_mode
|
2020-05-26 00:11:36 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
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) {}
|
2020-06-06 23:28:11 -04:00
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_entry()
|
2020-05-26 00:11:36 -04:00
|
|
|
{
|
2020-06-14 01:11:18 -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");
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_exit() {
|
2020-05-26 00:11:36 -04:00
|
|
|
audio().muteAllTx();
|
|
|
|
audio().muteRx();
|
2020-06-14 01:11:18 -04:00
|
|
|
disable_comp();
|
2020-05-26 00:11:36 -04:00
|
|
|
USBDEBUG("SSB mode exited");
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_tx()
|
2020-05-26 00:11:36 -04:00
|
|
|
{
|
|
|
|
audio().muteRx();
|
2020-06-14 01:11:18 -04:00
|
|
|
if (use_mic_) {
|
2020-05-26 00:11:36 -04:00
|
|
|
audio().unmuteMicIn();
|
|
|
|
} else {
|
|
|
|
audio().unmuteLineIn();
|
|
|
|
}
|
|
|
|
USBDEBUG("SSB mode transmitting");
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_rx()
|
2020-05-26 00:11:36 -04:00
|
|
|
{
|
2020-06-14 01:11:18 -04:00
|
|
|
if (use_mic_) {
|
2020-05-26 00:11:36 -04:00
|
|
|
audio().muteMicIn();
|
|
|
|
} else {
|
|
|
|
audio().muteLineIn();
|
|
|
|
}
|
|
|
|
audio().unmuteRx();
|
|
|
|
USBDEBUG("SSB mode receiving");
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
void set_mic_in()
|
2020-05-26 00:11:36 -04:00
|
|
|
{
|
2020-06-14 01:11:18 -04:00
|
|
|
if (is_rx()) {
|
2020-05-26 00:11:36 -04:00
|
|
|
// can't switch inputs while already transmitting
|
2020-06-14 01:11:18 -04:00
|
|
|
use_mic_ = true;
|
2020-05-26 00:11:36 -04:00
|
|
|
}
|
|
|
|
USBDEBUG("SSB mode - Mic In set");
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
void set_line_in()
|
2020-05-26 00:11:36 -04:00
|
|
|
{
|
2020-06-14 01:11:18 -04:00
|
|
|
if (is_rx()) {
|
2020-05-26 00:11:36 -04:00
|
|
|
// can't switch inputs while already transmitting
|
2020-06-14 01:11:18 -04:00
|
|
|
use_mic_ = false;
|
2020-05-26 00:11:36 -04:00
|
|
|
}
|
|
|
|
USBDEBUG("SSB mode - Line In set");
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
inline void enable_comp() { comp_.enable(); }
|
|
|
|
inline void disable_comp() { comp_.disable(); }
|
2020-05-27 23:45:37 -04:00
|
|
|
|
2020-05-26 00:11:36 -04:00
|
|
|
private:
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
bool use_mic_;
|
|
|
|
speech_comp& comp_;
|
2020-05-26 00:11:36 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
//======================================================================
|
2020-06-14 01:11:18 -04:00
|
|
|
// digi_mode
|
2020-05-26 00:11:36 -04:00
|
|
|
//======================================================================
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
class digi_mode : public basic_mode
|
2020-05-26 00:11:36 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
digi_mode(digi_config& c, RigAudio& a, bp_filter& f) :
|
|
|
|
basic_mode(c, a, f) {}
|
2020-06-06 01:06:45 -04:00
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_entry()
|
2020-05-26 00:11:36 -04:00
|
|
|
{
|
2020-06-14 01:11:18 -04:00
|
|
|
set_rx_filter(config().filter);
|
2020-05-26 00:11:36 -04:00
|
|
|
audio().unmuteRx();
|
|
|
|
audio().muteAllTx();
|
2020-06-14 01:11:18 -04:00
|
|
|
USBDEBUG("Digi mode entered");
|
2020-05-26 00:11:36 -04:00
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_exit() {
|
2020-05-26 00:11:36 -04:00
|
|
|
audio().muteAllTx();
|
|
|
|
audio().muteRx();
|
2020-06-14 01:11:18 -04:00
|
|
|
USBDEBUG("Digi mode exited");
|
2020-05-26 00:11:36 -04:00
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_tx()
|
2020-05-26 00:11:36 -04:00
|
|
|
{
|
|
|
|
audio().muteRx();
|
|
|
|
audio().unmuteUSBIn();
|
2020-06-14 01:11:18 -04:00
|
|
|
USBDEBUG("Digi mode transmitting");
|
2020-05-26 00:11:36 -04:00
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_rx()
|
2020-05-26 00:11:36 -04:00
|
|
|
{
|
|
|
|
audio().muteUSBIn();
|
|
|
|
audio().unmuteRx();
|
2020-06-14 01:11:18 -04:00
|
|
|
USBDEBUG("Digi mode receiving");
|
2020-05-27 23:45:37 -04:00
|
|
|
}
|
2020-05-26 00:11:36 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//======================================================================
|
2020-06-14 01:11:18 -04:00
|
|
|
// cw_mode
|
2020-05-26 00:11:36 -04:00
|
|
|
//======================================================================
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
class cw_mode : public basic_mode
|
2020-05-26 00:11:36 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
cw_mode(cw_config& c, RigAudio& a, bp_filter& f):
|
|
|
|
basic_mode(c, a, f) {}
|
2020-06-06 01:06:45 -04:00
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_entry()
|
2020-05-26 00:11:36 -04:00
|
|
|
{
|
2020-06-14 01:11:18 -04:00
|
|
|
set_rx_filter(config().filter);
|
2020-05-26 00:11:36 -04:00
|
|
|
audio().unmuteRx();
|
|
|
|
audio().muteAllTx();
|
|
|
|
USBDEBUG("CW mode entered");
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_exit() {
|
2020-05-26 00:11:36 -04:00
|
|
|
audio().muteAllTx();
|
|
|
|
audio().muteRx();
|
|
|
|
USBDEBUG("CW mode exited");
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:11:18 -04:00
|
|
|
virtual void on_rx()
|
2020-05-26 00:11:36 -04:00
|
|
|
{
|
|
|
|
USBDEBUG("CW mode receiving");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//======================================================================
|
|
|
|
// EOF
|
|
|
|
//======================================================================
|