ubitx-iop/ubitx_iop/rig.h

338 lines
7.9 KiB
C
Raw Normal View History

2020-05-26 04:11:36 +00:00
//======================================================================
// rig.h
//======================================================================
#ifndef __rig_h__
#define __rig_h__
#include <iopcomm.h>
#include "audio.h"
#include "RigMode.h"
//#include "menu.h"
2020-05-26 04:11:36 +00:00
//======================================================================
// Rig class
//======================================================================
class Rig {
public:
//--------------------------------------------------------------------
// Constructor/destructor.
//--------------------------------------------------------------------
2020-06-13 14:59:11 +00:00
Rig(RigConfig& c, RigAudio& a): _config(c), _audio(a), _filter(wide)
2020-05-26 04:11:36 +00:00
{
_modes = new IMode*[c.numModes];
_modesLen = c.numModes;
_modesIndex = c.startMode;
// for (int i = 0; i < 16; i++) { _modeText[i] = ' '; }
// _modeText[16] = '\0';
/* _modes[RIG_MODE_LSB] = new SSBMode(c.lsb, a);
2020-05-26 04:11:36 +00:00
_modes[RIG_MODE_USB] = new SSBMode(c.usb, a);
_modes[RIG_MODE_CWL] = new CWMode(c.cwl, a);
_modes[RIG_MODE_CWU] = new CWMode(c.cwu, a);
_modes[RIG_MODE_DGL] = new DGTMode(c.dgl, a);
_modes[RIG_MODE_DGU] = new DGTMode(c.dgu, a);
_modes[RIG_MODE_TTL] = new TTMode(c.ttl, a);
_modes[RIG_MODE_TTU] = new TTMode(c.ttu, a);*/
2020-05-26 04:11:36 +00:00
/*
2020-06-13 14:59:11 +00:00
_rxFilters = new (IFilter*)[num_rx_filters];
_rxFiltersLen = num_rx_filters;
2020-05-26 04:11:36 +00:00
_rxFiltersIndex = 0; // need to get default filter from current mode...
2020-06-13 14:59:11 +00:00
_rxFilters[wide] = mode()->filterWide();
_rxFilters[medium] = mode()->filterMedium();
_rxFilters[narrow] = mode()->filterNarrow();
2020-05-26 04:11:36 +00:00
*/
}
~Rig()
{
for (unsigned i = 0; i < _modesLen; i++) {
2020-05-26 04:11:36 +00:00
delete _modes[i];
}
delete _modes;
}
void init() {
switchRxFilter(_filter);
}
2020-05-26 04:11:36 +00:00
//--------------------------------------------------------------------
// Mode control.
//--------------------------------------------------------------------
/*
const char* modeText() {
sprintf(_modeText, "%1c- %6s %6s", modeID[_modesIndex],
mode()->rxInfo(), mode()->txInfo());
return _modeText;
}
*/
2020-06-13 14:59:11 +00:00
inline bool isSSBMode() const { return (_modesIndex == usb || _modesIndex == lsb); }
// inline bool isUSBMode() const { return (_modesIndex == usb); }
// inline bool isLSBMode() const { return (_modesIndex == lsb); }
inline bool isDIGMode() const { return (_modesIndex == dig); }
inline bool isCWMode() const { return (_modesIndex == cw || _modesIndex == cwr); }
// inline bool isCWUMode() const { return (_modesIndex == RIG_MODE_CWU); }
// inline bool isCWLMode() const { return (_modesIndex == RIG_MODE_CWL); }
// Assign a pointer to a mode object. Returns true if successful, false otherwise.
2020-06-13 14:59:11 +00:00
bool addNewMode(rig_mode i, IMode* mode) {
if (i > _modesLen) {
return false;
} else {
_modes[i] = mode;
return true;
}
}
2020-05-26 04:11:36 +00:00
// Returns a pointer to the current mode.
inline IMode* mode() const {
return _modes[_modesIndex];
}
// Returns the array index of the current mode.
2020-06-13 14:59:11 +00:00
inline rig_mode modeNum() const {
return _modesIndex;
2020-05-26 04:11:36 +00:00
}
/* // Returns a pointer to the specified mode.
inline IMode* mode(RigMode m) const {
return _modes[m];
}*/
// Switch to the mode specified by the provided index. Returns a
// pointer to the new mode.
2020-06-13 14:59:11 +00:00
IMode* switchMode(rig_mode i) {
2020-05-26 04:11:36 +00:00
// exit the previous mode
mode()->exit(); // NOTE: This could currently occur during TX, which is NOT desirable.
// select the new mode
2020-06-13 14:59:11 +00:00
_modesIndex = rig_mode(i % _modesLen);
2020-05-26 04:11:36 +00:00
//enter the new mode
mode()->enter();
// return a pointer to the new mode
return mode();
}
// Advance to the next (or previous) mode. Returns a pointer to the
// new mode.
IMode* switchMode(bool prev=false) {
// exit the previous mode
mode()->exit();
// select the new mode
if (prev) {
2020-06-13 14:59:11 +00:00
_modesIndex = rig_mode(_modesIndex > 0 ? _modesIndex - 1 : _modesLen - 1);
2020-05-26 04:11:36 +00:00
} else {
2020-06-13 14:59:11 +00:00
_modesIndex = rig_mode((_modesIndex + 1) % _modesLen);
2020-05-26 04:11:36 +00:00
}
// enter the new mode
mode()->enter();
// return a pointer to the new mode
return mode();
}
//--------------------------------------------------------------------
// Transmit/Receive (T/R) control.
//--------------------------------------------------------------------
inline bool isTx() const { return mode()->isTx(); }
inline bool isRx() const { return mode()->isRx(); }
// Enter the transmit state. This is delegated to the mode.
inline void tx() { mode()->tx(); }
// Enter the receive state. This is delegated to the mode.
inline void rx() { mode()->rx(); }
//--------------------------------------------------------------------
// Transmit processor control.
//--------------------------------------------------------------------
void switchProcessor(bool prev=false) {
}
//--------------------------------------------------------------------
// RX filter control.
//--------------------------------------------------------------------
inline void setWideRxFilter() {
2020-06-13 14:59:11 +00:00
_filter = wide;
mode()->setWideRxFilter();
USBDEBUG("selected wide RX filter");
}
inline void setMediumRxFilter() {
2020-06-13 14:59:11 +00:00
_filter = medium;
mode()->setMediumRxFilter();
USBDEBUG("selected medium RX filter");
}
inline void setNarrowRxFilter() {
2020-06-13 14:59:11 +00:00
_filter = narrow;
mode()->setNarrowRxFilter();
USBDEBUG("selected narrow RX filter");
}
2020-06-13 14:59:11 +00:00
void switchRxFilter(rx_filter f) {
switch(f) {
2020-06-13 14:59:11 +00:00
case wide:
setWideRxFilter();
break;
2020-06-13 14:59:11 +00:00
case medium:
setMediumRxFilter();
break;
2020-06-13 14:59:11 +00:00
case narrow:
setNarrowRxFilter();
break;
}
}
void switchRxFilter(bool prev=false) {
2020-06-13 14:59:11 +00:00
rx_filter f;
if (prev) {
2020-06-13 14:59:11 +00:00
f = rx_filter(_filter > 0 ? _filter - 1 : num_rx_filters - 1);
} else {
2020-06-13 14:59:11 +00:00
f = rx_filter((_filter + 1) % num_rx_filters);
}
switchRxFilter(f);
}
// Returns the array index of the current mode.
2020-06-13 14:59:11 +00:00
inline rx_filter filterNum() const {
return _filter;
}
2020-05-26 04:11:36 +00:00
/*
// Returns a pointer to the current RX filter.
IFilter* rxFilter() {
return _rxFilters[_rxFiltersIndex];
}
IFilter* switchRxFilter(bool prev=false) {
if (prev) {
_rxFiltersIndex--;
} else {
_rxFiltersIndex++;
}
_rxFiltersIndex %= _rxFiltersLen;
return _rxFiltersList[_rxFiltersIndex];
}
IFilter* switchRxFilterWide() {
}
IFilter* switchFilterMedium() {
}
IFilter* switchFilterNarrow() {
}
*/
// Audio output control.
inline void muteSpkrOut() const {
_audio.muteSpkrOut();
}
inline void unmuteSpkrOut() const {
_audio.unmuteSpkrOut();
}
inline void muteLineOut() const {
_audio.muteLineOut();
}
inline void unmuteLineOut() const {
_audio.unmuteLineOut();
}
inline void muteUSBOut() const {
_audio.muteUSBOut();
}
inline void unmuteUSBOut() const {
_audio.unmuteUSBOut();
}
// Audio input control.
inline void muteAllTx() const {
_audio.muteAllTx();
}
inline void muteMicIn() const {
_audio.muteMicIn();
}
inline void unmuteMicIn() const {
_audio.unmuteMicIn();
}
inline void muteLineIn() const {
_audio.muteLineIn();
}
inline void unmuteLineIn() const {
_audio.unmuteLineIn();
}
inline void muteUSBIn() const {
_audio.muteUSBIn();
}
inline void unmuteUSBIn() const {
_audio.unmuteUSBOut();
}
inline void muteTTIn() const {
_audio.muteTTIn();
}
inline void unmuteTTIn() const {
_audio.unmuteTTIn();
}
// Update the rig state. This should be called once each time through
// the main loop.
void update()
{
}
private:
RigConfig& _config;
RigAudio& _audio;
IMode** _modes;
2020-06-13 14:59:11 +00:00
rig_mode _modesLen;
rig_mode _modesIndex;
2020-05-26 04:11:36 +00:00
2020-06-13 14:59:11 +00:00
rx_filter _filter;
// char _modeText[17];
2020-05-26 04:11:36 +00:00
/*
IFilter** _rxFilters;
uint8_t _rxFiltersLen;
uint8_t _rxFiltersIndex;
*/
};
#endif
//======================================================================
// EOF
//======================================================================