diff --git a/ubitx_iop/RigMode.h b/ubitx_iop/RigMode.h index 7a4c3d2..2b1e89d 100644 --- a/ubitx_iop/RigMode.h +++ b/ubitx_iop/RigMode.h @@ -37,9 +37,6 @@ class IMode { inline IFilter& filter() { return _filter; } - virtual const char* rxInfo() = 0; - virtual const char* txInfo() = 0; - // 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. @@ -132,10 +129,7 @@ class SSBMode : public IMode IMode(c, a, f), _use_mic(default_mic) { } - - virtual const char* rxInfo() { return _rx_info; }; - virtual const char* txInfo() { return _tx_info; }; - + virtual void onEntry() { setWideRxFilter(); @@ -191,21 +185,18 @@ class SSBMode : public IMode } virtual void setWideRxFilter() { - _rx_info = "R:2.8k"; ((BPFilter&)filter()).setBand(300.0, 3100.0); filter().enable(); USBDEBUG("set wide RX SSB filter"); } virtual void setMediumRxFilter() { - _rx_info = "R:2.4k"; ((BPFilter&)filter()).setBand(500.0, 2900.0); filter().enable(); USBDEBUG("set medium RX SSB filter"); } virtual void setNarrowRxFilter() { - _rx_info = "R:1.8k"; ((BPFilter&)filter()).setBand(700.0, 2500.0); filter().enable(); USBDEBUG("set narrow RX SSB filter"); @@ -214,8 +205,6 @@ class SSBMode : public IMode private: bool _use_mic; - const char* _rx_info; - const char* _tx_info; }; //====================================================================== @@ -228,12 +217,9 @@ class DGTMode : public IMode DGTMode(IConfig& c, RigAudio& a, IFilter& f): IMode(c, a, f) - { + { } - virtual const char* rxInfo() { return _rx_info; }; - virtual const char* txInfo() { return _tx_info; }; - virtual void onEntry() { setWideRxFilter(); @@ -263,29 +249,23 @@ class DGTMode : public IMode } virtual void setWideRxFilter(){ - _rx_info = "R:2.8k"; ((BPFilter&)filter()).setBand(300.0, 3100.0); filter().enable(); USBDEBUG("set wide RX DGT filter"); } virtual void setMediumRxFilter(){ - _rx_info = "R:2.4k"; ((BPFilter&)filter()).setBand(500.0, 2900.0); filter().enable(); USBDEBUG("set medium RX DGT filter"); } virtual void setNarrowRxFilter(){ - _rx_info = "R:500 "; ((BPFilter&)filter()).setCenterAndWidth(1500.0, 500.0); filter().enable(); USBDEBUG("set narrow RX DGT filter"); } - private: - const char* _rx_info; - const char* _tx_info; }; @@ -302,9 +282,6 @@ class CWMode : public IMode { } - virtual const char* rxInfo() { return _rx_info; }; - virtual const char* txInfo() { return _tx_info; }; - virtual void onEntry() { setWideRxFilter(); @@ -341,7 +318,6 @@ class CWMode : public IMode } ((BPFilter&)filter()).setBand(low, low + width); filter().enable(); - _rx_info = "R:1.0k"; USBDEBUG("set wide RX CW filter"); } @@ -354,7 +330,6 @@ class CWMode : public IMode } ((BPFilter&)filter()).setBand(low, low + width); filter().enable(); - _rx_info = "R:500 "; USBDEBUG("set medium RX CW filter"); } @@ -367,13 +342,9 @@ class CWMode : public IMode } ((BPFilter&)filter()).setBand(low, low + width); filter().enable(); - _rx_info = "R:250 "; USBDEBUG("set narrow RX CW filter"); } - private: - const char* _rx_info; - const char* _tx_info; }; //====================================================================== @@ -389,9 +360,6 @@ class TTMode : public IMode { } - virtual const char* rxInfo() { return _rx_info; }; - virtual const char* txInfo() { return _tx_info; }; - virtual void onEntry() { setWideRxFilter(); @@ -421,29 +389,23 @@ class TTMode : public IMode } virtual void setWideRxFilter(){ - _rx_info = "R:2.8k"; ((BPFilter&)filter()).setBand(300.0, 3100.0); filter().enable(); USBDEBUG("set wide RX TT filter"); } virtual void setMediumRxFilter(){ - _rx_info = "R:2.4k"; ((BPFilter&)filter()).setBand(500.0, 2900.0); filter().enable(); USBDEBUG("set medium RX TT filter"); } virtual void setNarrowRxFilter(){ - _rx_info = "R:1.8k"; ((BPFilter&)filter()).setBand(700.0, 2500.0); filter().enable(); USBDEBUG("set narrow RX TT filter"); } - private: - const char* _rx_info; - const char* _tx_info; }; #endif diff --git a/ubitx_iop/menu.h b/ubitx_iop/menu.h index e1a6d8e..590be0c 100644 --- a/ubitx_iop/menu.h +++ b/ubitx_iop/menu.h @@ -14,6 +14,7 @@ class MenuItem { public: virtual ~MenuItem() {} + //virtual const char* text() = 0; virtual void update() = 0; virtual MenuItem* select() = 0; virtual MenuItem* altSelect() = 0; @@ -22,21 +23,42 @@ class MenuItem { virtual MenuItem* next() = 0; }; +const char modeID[] = {'s', 'S', 'c', 'C', 'd', 'D', 't', 'T'}; +const char* const filterID[NUM_RIG_MODES][NUM_RX_FILTERS] = { + {"2.8", "2.4", "1.8"}, // LSB + {"2.8", "2.4", "1.8"}, // USB + {"1.0", "500", "250"}, // CWL + {"1.0", "500", "250"}, // CWU + {"2.8", "2.4", "500"}, // DGL + {"2.8", "2.4", "500"}, // DGU + {"2.8", "2.4", "1.8"}, // TTL + {"2.8", "2.4", "1.8"}, // TTU +}; + class TopMenu : public MenuItem { public: - TopMenu(Rig& rig): _rig(rig), _visible(false), _adjust_tx(false) {} + TopMenu(Rig& rig): _rig(rig), _visible(false), _adjust_tx(false) { + strcpy(_text0, "R: T: "); + strcpy(_text1, "0123456789ABCDEF"); + } + +/* virtual const char* text() { + sprintf(_buffer, "%1c-%1c%6s%1c6s", modeID[rig.modeNum], + return _buffer; + }*/ virtual void update() { - strcpy(_buffer, _rig.modeText()); - if (_adjust_tx) { - _buffer[2] = MENU_SELECTED_CHAR; - } else { - _buffer[9] = MENU_SELECTED_CHAR; - } - if (_visible) { - sendIOPMenuDisplay(_buffer, 0); - } else { - sendIOPMenuDisplay(_buffer, -1); + sprintf(_text0, "%1cR:%3s %1cT: ", + _adjust_tx ? ' ' : MENU_SELECTED_CHAR, + filterID[_rig.modeNum()][_rig.filterNum()], + _adjust_tx ? MENU_SELECTED_CHAR : ' '); + if (strcmp(_text0, _text1) != 0) { + if (_visible) { + sendIOPMenuDisplay(_text0, 0); + } else { + sendIOPMenuDisplay(_text0, -1); + } + strncpy(_text1, _text0, MAX_TEXT_LEN); } } @@ -83,7 +105,8 @@ class TopMenu : public MenuItem { Rig& _rig; bool _visible; bool _adjust_tx; - char _buffer[MAX_TEXT_LEN+1]; + char _text0[MAX_TEXT_LEN+1]; + char _text1[MAX_TEXT_LEN+1]; }; /* diff --git a/ubitx_iop/rig.h b/ubitx_iop/rig.h index 99e7162..878574e 100644 --- a/ubitx_iop/rig.h +++ b/ubitx_iop/rig.h @@ -14,8 +14,6 @@ // Rig class //====================================================================== -const char * const modeID[] = {"s", "S", "c", "C", "d", "D", "t", "T"}; - class Rig { public: @@ -28,6 +26,9 @@ class Rig { _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); _modes[RIG_MODE_USB] = new SSBMode(c.usb, a); _modes[RIG_MODE_CWL] = new CWMode(c.cwl, a); @@ -61,14 +62,13 @@ class Rig { //-------------------------------------------------------------------- // Mode control. //-------------------------------------------------------------------- - +/* const char* modeText() { - strcpy(&_modeText[0], modeID[_modesIndex]); - strcpy(&_modeText[3], mode()->rxInfo()); - strcpy(&_modeText[10], mode()->txInfo()); + sprintf(_modeText, "%1c- %6s %6s", modeID[_modesIndex], + mode()->rxInfo(), mode()->txInfo()); return _modeText; } - +*/ 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); } @@ -132,7 +132,7 @@ class Rig { // select the new mode if (prev) { - _modesIndex = RigMode((_modesIndex > 0 ? _modesIndex - 1 : _modesLen - 1)); + _modesIndex = RigMode(_modesIndex > 0 ? _modesIndex - 1 : _modesLen - 1); } else { _modesIndex = RigMode((_modesIndex + 1) % _modesLen); } @@ -172,20 +172,23 @@ class Rig { inline void setWideRxFilter() { _filter = RX_FILTER_WIDE; mode()->setWideRxFilter(); + USBDEBUG("selected wide RX filter"); } inline void setMediumRxFilter() { _filter = RX_FILTER_MEDIUM; mode()->setMediumRxFilter(); + USBDEBUG("selected medium RX filter"); } inline void setNarrowRxFilter() { _filter = RX_FILTER_NARROW; mode()->setNarrowRxFilter(); + USBDEBUG("selected narrow RX filter"); } - void switchRxFilter(RxFilter i) { - switch(i) { + void switchRxFilter(RxFilter f) { + switch(f) { case RX_FILTER_WIDE: setWideRxFilter(); break; @@ -201,13 +204,20 @@ class Rig { } void switchRxFilter(bool prev=false) { + RxFilter f; if (prev) { - _filter = RxFilter((_filter - 1) % NUM_RX_FILTERS); + f = RxFilter(_filter > 0 ? _filter - 1 : NUM_RX_FILTERS - 1); } else { - _filter = RxFilter((_filter + 1) % NUM_RX_FILTERS); - } + f = RxFilter((_filter + 1) % NUM_RX_FILTERS); + } + switchRxFilter(f); } - + + // Returns the array index of the current mode. + inline RxFilter filterNum() const { + return _filter; + } + /* // Returns a pointer to the current RX filter. IFilter* rxFilter() { @@ -316,7 +326,7 @@ class Rig { RxFilter _filter; - char _modeText[17]; +// char _modeText[17]; /* IFilter** _rxFilters; diff --git a/ubitx_iop/ubitx_iop.ino b/ubitx_iop/ubitx_iop.ino index 7fbe6a3..14efd30 100644 --- a/ubitx_iop/ubitx_iop.ino +++ b/ubitx_iop/ubitx_iop.ino @@ -44,6 +44,7 @@ elapsedMillis btnMillis; TopMenu topMenu(rig); MenuItem* menu = &topMenu; +elapsedMillis menuUpdateMillis; elapsedMillis frameMillis; unsigned frameTime; unsigned frameCounter; @@ -78,6 +79,8 @@ void setup() { frameCounter = 0; frameMillis = 0; + menuUpdateMillis = 0; + knob.write(0); btn.attach(ENCODER_SW_PIN, INPUT_PULLUP); @@ -101,6 +104,7 @@ void setup() { void loop() { static char frame_status[100]; + static char old_mode_text[17] = " "; static bool paddle_loop = false; // long oldPos = knobPos; @@ -162,6 +166,7 @@ void loop() serviceCAT(); +/* // send current status @ 10 Hz //if (frame10Hz > 100) { if ((rig.modeNum() != oldRigMode)) { // || (rxFilter != oldRxFilter)) { @@ -209,7 +214,7 @@ void loop() } //frame10Hz = 0; } - +*/ btn.update(); if (btn.fell()) { //sendIOPMenuDisplay("PRESSED ", 2); @@ -220,17 +225,18 @@ void loop() // long press - exit //sendIOPMenuDisplay("REL-LONG ", 2); menu->exit(); - USBDEBUG("button released - long"); + USBDEBUG("button released - long (exit)"); } if (btnMillis > 500) { // medium press - altSelect menu->altSelect(); + USBDEBUG("button released - medium (altSelect)"); } else { // short press - select //sendIOPMenuDisplay("REL-SHORT ", 2); menu->select(); - USBDEBUG("button released - short"); + USBDEBUG("button released - short (select)"); } - menu->update(); +// menu->update(); } knobPos = knob.read(); @@ -240,18 +246,29 @@ void loop() // left //sendIOPMenuDisplay("LEFT ", 5); menu->prev(); - menu->update(); +// menu->update(); knob.write(0); USBDEBUG("knob turned left"); } else if (knobPos < -3) { // right //sendIOPMenuDisplay("RIGHT ", 5); menu->next(); - menu->update(); +// menu->update(); knob.write(0); USBDEBUG("knob turned right"); } +// if (strcmp(old_mode_text, rig.modeText())) { +// menu->update(); +// strcpy(old_mode_text, rig.modeText()); +// } + + // update the menu at a 10 Hz rate + if (menuUpdateMillis > 100) { + menu->update(); + menuUpdateMillis = 0; + } + if (frameMillis > 5000) { #if defined(DEBUG) frameTime = frameMillis;