ubitx-iop/ubitx_iop/rig.h

265 lines
6.7 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"
//======================================================================
// Rig class
//======================================================================
class Rig {
public:
//--------------------------------------------------------------------
// Constructor/destructor.
//--------------------------------------------------------------------
Rig(RigConfig& c, RigAudio& a): _config(c), _audio(a)
{
_modes = new IMode*[NUM_RIG_MODES];
_modesLen = NUM_RIG_MODES;
_modesIndex = c.mode;
_modes[RIG_MODE_LSB] = new SSBMode(c.lsb, a);
_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);
/*
_rxFilters = new (IFilter*)[NUM_RX_FILTERS];
_rxFiltersLen = NUM_RX_FILTERS;
_rxFiltersIndex = 0; // need to get default filter from current mode...
_rxFilters[RX_FILTER_WIDE] = mode()->filterWide();
_rxFilters[RX_FILTER_MEDIUM] = mode()->filterMedium();
_rxFilters[RX_FILTER_NARROW] = mode()->filterNarrow();
*/
}
~Rig()
{
for (int i = 0; i < _modesLen; i++) {
delete _modes[i];
}
delete _modes;
}
//--------------------------------------------------------------------
// Mode control.
//--------------------------------------------------------------------
inline bool isSSBMode() const { return (_modesIndex == RIG_MODE_USB || _modesIndex == RIG_MODE_LSB); }
inline bool isUSBMode() const { return (_modesIndex == RIG_MODE_USB); }
inline bool isLSBMode() const { return (_modesIndex == RIG_MODE_LSB); }
inline bool isDGTMode() const { return (_modesIndex == RIG_MODE_DGU || _modesIndex == RIG_MODE_DGL); }
inline bool isDGUMode() const { return (_modesIndex == RIG_MODE_DGU); }
inline bool isDGLMode() const { return (_modesIndex == RIG_MODE_DGL); }
inline bool isCWMode() const { return (_modesIndex == RIG_MODE_CWU || _modesIndex == RIG_MODE_CWL); }
inline bool isCWUMode() const { return (_modesIndex == RIG_MODE_CWU); }
inline bool isCWLMode() const { return (_modesIndex == RIG_MODE_CWL); }
inline bool isTTMode() const { return (_modesIndex == RIG_MODE_TTU || _modesIndex == RIG_MODE_TTL); }
inline bool isTTUMode() const { return (_modesIndex == RIG_MODE_TTU); }
inline bool isTTLMode() const { return (_modesIndex == RIG_MODE_TTL); }
// Returns a pointer to the current mode.
inline IMode* mode() const {
return _modes[_modesIndex];
}
inline RigMode modeNum() const {
return RigMode(_modesIndex);
}
/* // 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.
IMode* switchMode(RigMode i) {
// exit the previous mode
mode()->exit(); // NOTE: This could currently occur during TX, which is NOT desirable.
// select the new mode
_modesIndex = i % _modesLen; // do I need the modulo?
//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) {
_modesIndex--;
} else {
_modesIndex++;
}
_modesIndex %= _modesLen;
// 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.
//--------------------------------------------------------------------
/*
// 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;
uint8_t _modesLen;
uint8_t _modesIndex;
/*
IFilter** _rxFilters;
uint8_t _rxFiltersLen;
uint8_t _rxFiltersIndex;
*/
};
#endif
//======================================================================
// EOF
//======================================================================