More robust menu system, slightly. But still doesn't get correctly

displayed on the Raduino.  See most recently Raduino (ubitx-v5d) commit.
This commit is contained in:
Rob French 2020-06-06 22:28:11 -05:00
parent e27c15d56a
commit c27e2eddd6
4 changed files with 85 additions and 73 deletions

View File

@ -37,9 +37,6 @@ class IMode {
inline IFilter& filter() { return _filter; } 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 // 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 // "clean", i.e. that it still needs to enable anything it needs for
// use in the mode. // use in the mode.
@ -133,9 +130,6 @@ class SSBMode : public IMode
{ {
} }
virtual const char* rxInfo() { return _rx_info; };
virtual const char* txInfo() { return _tx_info; };
virtual void onEntry() virtual void onEntry()
{ {
setWideRxFilter(); setWideRxFilter();
@ -191,21 +185,18 @@ class SSBMode : public IMode
} }
virtual void setWideRxFilter() { virtual void setWideRxFilter() {
_rx_info = "R:2.8k";
((BPFilter&)filter()).setBand(300.0, 3100.0); ((BPFilter&)filter()).setBand(300.0, 3100.0);
filter().enable(); filter().enable();
USBDEBUG("set wide RX SSB filter"); USBDEBUG("set wide RX SSB filter");
} }
virtual void setMediumRxFilter() { virtual void setMediumRxFilter() {
_rx_info = "R:2.4k";
((BPFilter&)filter()).setBand(500.0, 2900.0); ((BPFilter&)filter()).setBand(500.0, 2900.0);
filter().enable(); filter().enable();
USBDEBUG("set medium RX SSB filter"); USBDEBUG("set medium RX SSB filter");
} }
virtual void setNarrowRxFilter() { virtual void setNarrowRxFilter() {
_rx_info = "R:1.8k";
((BPFilter&)filter()).setBand(700.0, 2500.0); ((BPFilter&)filter()).setBand(700.0, 2500.0);
filter().enable(); filter().enable();
USBDEBUG("set narrow RX SSB filter"); USBDEBUG("set narrow RX SSB filter");
@ -214,8 +205,6 @@ class SSBMode : public IMode
private: private:
bool _use_mic; bool _use_mic;
const char* _rx_info;
const char* _tx_info;
}; };
//====================================================================== //======================================================================
@ -231,9 +220,6 @@ class DGTMode : public IMode
{ {
} }
virtual const char* rxInfo() { return _rx_info; };
virtual const char* txInfo() { return _tx_info; };
virtual void onEntry() virtual void onEntry()
{ {
setWideRxFilter(); setWideRxFilter();
@ -263,29 +249,23 @@ class DGTMode : public IMode
} }
virtual void setWideRxFilter(){ virtual void setWideRxFilter(){
_rx_info = "R:2.8k";
((BPFilter&)filter()).setBand(300.0, 3100.0); ((BPFilter&)filter()).setBand(300.0, 3100.0);
filter().enable(); filter().enable();
USBDEBUG("set wide RX DGT filter"); USBDEBUG("set wide RX DGT filter");
} }
virtual void setMediumRxFilter(){ virtual void setMediumRxFilter(){
_rx_info = "R:2.4k";
((BPFilter&)filter()).setBand(500.0, 2900.0); ((BPFilter&)filter()).setBand(500.0, 2900.0);
filter().enable(); filter().enable();
USBDEBUG("set medium RX DGT filter"); USBDEBUG("set medium RX DGT filter");
} }
virtual void setNarrowRxFilter(){ virtual void setNarrowRxFilter(){
_rx_info = "R:500 ";
((BPFilter&)filter()).setCenterAndWidth(1500.0, 500.0); ((BPFilter&)filter()).setCenterAndWidth(1500.0, 500.0);
filter().enable(); filter().enable();
USBDEBUG("set narrow RX DGT filter"); 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() virtual void onEntry()
{ {
setWideRxFilter(); setWideRxFilter();
@ -341,7 +318,6 @@ class CWMode : public IMode
} }
((BPFilter&)filter()).setBand(low, low + width); ((BPFilter&)filter()).setBand(low, low + width);
filter().enable(); filter().enable();
_rx_info = "R:1.0k";
USBDEBUG("set wide RX CW filter"); USBDEBUG("set wide RX CW filter");
} }
@ -354,7 +330,6 @@ class CWMode : public IMode
} }
((BPFilter&)filter()).setBand(low, low + width); ((BPFilter&)filter()).setBand(low, low + width);
filter().enable(); filter().enable();
_rx_info = "R:500 ";
USBDEBUG("set medium RX CW filter"); USBDEBUG("set medium RX CW filter");
} }
@ -367,13 +342,9 @@ class CWMode : public IMode
} }
((BPFilter&)filter()).setBand(low, low + width); ((BPFilter&)filter()).setBand(low, low + width);
filter().enable(); filter().enable();
_rx_info = "R:250 ";
USBDEBUG("set narrow RX CW filter"); 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() virtual void onEntry()
{ {
setWideRxFilter(); setWideRxFilter();
@ -421,29 +389,23 @@ class TTMode : public IMode
} }
virtual void setWideRxFilter(){ virtual void setWideRxFilter(){
_rx_info = "R:2.8k";
((BPFilter&)filter()).setBand(300.0, 3100.0); ((BPFilter&)filter()).setBand(300.0, 3100.0);
filter().enable(); filter().enable();
USBDEBUG("set wide RX TT filter"); USBDEBUG("set wide RX TT filter");
} }
virtual void setMediumRxFilter(){ virtual void setMediumRxFilter(){
_rx_info = "R:2.4k";
((BPFilter&)filter()).setBand(500.0, 2900.0); ((BPFilter&)filter()).setBand(500.0, 2900.0);
filter().enable(); filter().enable();
USBDEBUG("set medium RX TT filter"); USBDEBUG("set medium RX TT filter");
} }
virtual void setNarrowRxFilter(){ virtual void setNarrowRxFilter(){
_rx_info = "R:1.8k";
((BPFilter&)filter()).setBand(700.0, 2500.0); ((BPFilter&)filter()).setBand(700.0, 2500.0);
filter().enable(); filter().enable();
USBDEBUG("set narrow RX TT filter"); USBDEBUG("set narrow RX TT filter");
} }
private:
const char* _rx_info;
const char* _tx_info;
}; };
#endif #endif

View File

@ -14,6 +14,7 @@
class MenuItem { class MenuItem {
public: public:
virtual ~MenuItem() {} virtual ~MenuItem() {}
//virtual const char* text() = 0;
virtual void update() = 0; virtual void update() = 0;
virtual MenuItem* select() = 0; virtual MenuItem* select() = 0;
virtual MenuItem* altSelect() = 0; virtual MenuItem* altSelect() = 0;
@ -22,21 +23,42 @@ class MenuItem {
virtual MenuItem* next() = 0; 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 { class TopMenu : public MenuItem {
public: 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() { virtual void update() {
strcpy(_buffer, _rig.modeText()); sprintf(_text0, "%1cR:%3s %1cT: ",
if (_adjust_tx) { _adjust_tx ? ' ' : MENU_SELECTED_CHAR,
_buffer[2] = MENU_SELECTED_CHAR; filterID[_rig.modeNum()][_rig.filterNum()],
} else { _adjust_tx ? MENU_SELECTED_CHAR : ' ');
_buffer[9] = MENU_SELECTED_CHAR; if (strcmp(_text0, _text1) != 0) {
}
if (_visible) { if (_visible) {
sendIOPMenuDisplay(_buffer, 0); sendIOPMenuDisplay(_text0, 0);
} else { } else {
sendIOPMenuDisplay(_buffer, -1); sendIOPMenuDisplay(_text0, -1);
}
strncpy(_text1, _text0, MAX_TEXT_LEN);
} }
} }
@ -83,7 +105,8 @@ class TopMenu : public MenuItem {
Rig& _rig; Rig& _rig;
bool _visible; bool _visible;
bool _adjust_tx; bool _adjust_tx;
char _buffer[MAX_TEXT_LEN+1]; char _text0[MAX_TEXT_LEN+1];
char _text1[MAX_TEXT_LEN+1];
}; };
/* /*

View File

@ -14,8 +14,6 @@
// Rig class // Rig class
//====================================================================== //======================================================================
const char * const modeID[] = {"s", "S", "c", "C", "d", "D", "t", "T"};
class Rig { class Rig {
public: public:
@ -28,6 +26,9 @@ class Rig {
_modes = new IMode*[c.numModes]; _modes = new IMode*[c.numModes];
_modesLen = c.numModes; _modesLen = c.numModes;
_modesIndex = c.startMode; _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_LSB] = new SSBMode(c.lsb, a);
_modes[RIG_MODE_USB] = new SSBMode(c.usb, a); _modes[RIG_MODE_USB] = new SSBMode(c.usb, a);
_modes[RIG_MODE_CWL] = new CWMode(c.cwl, a); _modes[RIG_MODE_CWL] = new CWMode(c.cwl, a);
@ -61,14 +62,13 @@ class Rig {
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// Mode control. // Mode control.
//-------------------------------------------------------------------- //--------------------------------------------------------------------
/*
const char* modeText() { const char* modeText() {
strcpy(&_modeText[0], modeID[_modesIndex]); sprintf(_modeText, "%1c- %6s %6s", modeID[_modesIndex],
strcpy(&_modeText[3], mode()->rxInfo()); mode()->rxInfo(), mode()->txInfo());
strcpy(&_modeText[10], mode()->txInfo());
return _modeText; return _modeText;
} }
*/
inline bool isSSBMode() const { return (_modesIndex == RIG_MODE_USB || _modesIndex == RIG_MODE_LSB); } inline bool isSSBMode() const { return (_modesIndex == RIG_MODE_USB || _modesIndex == RIG_MODE_LSB); }
inline bool isUSBMode() const { return (_modesIndex == RIG_MODE_USB); } inline bool isUSBMode() const { return (_modesIndex == RIG_MODE_USB); }
inline bool isLSBMode() const { return (_modesIndex == RIG_MODE_LSB); } inline bool isLSBMode() const { return (_modesIndex == RIG_MODE_LSB); }
@ -132,7 +132,7 @@ class Rig {
// select the new mode // select the new mode
if (prev) { if (prev) {
_modesIndex = RigMode((_modesIndex > 0 ? _modesIndex - 1 : _modesLen - 1)); _modesIndex = RigMode(_modesIndex > 0 ? _modesIndex - 1 : _modesLen - 1);
} else { } else {
_modesIndex = RigMode((_modesIndex + 1) % _modesLen); _modesIndex = RigMode((_modesIndex + 1) % _modesLen);
} }
@ -172,20 +172,23 @@ class Rig {
inline void setWideRxFilter() { inline void setWideRxFilter() {
_filter = RX_FILTER_WIDE; _filter = RX_FILTER_WIDE;
mode()->setWideRxFilter(); mode()->setWideRxFilter();
USBDEBUG("selected wide RX filter");
} }
inline void setMediumRxFilter() { inline void setMediumRxFilter() {
_filter = RX_FILTER_MEDIUM; _filter = RX_FILTER_MEDIUM;
mode()->setMediumRxFilter(); mode()->setMediumRxFilter();
USBDEBUG("selected medium RX filter");
} }
inline void setNarrowRxFilter() { inline void setNarrowRxFilter() {
_filter = RX_FILTER_NARROW; _filter = RX_FILTER_NARROW;
mode()->setNarrowRxFilter(); mode()->setNarrowRxFilter();
USBDEBUG("selected narrow RX filter");
} }
void switchRxFilter(RxFilter i) { void switchRxFilter(RxFilter f) {
switch(i) { switch(f) {
case RX_FILTER_WIDE: case RX_FILTER_WIDE:
setWideRxFilter(); setWideRxFilter();
break; break;
@ -201,11 +204,18 @@ class Rig {
} }
void switchRxFilter(bool prev=false) { void switchRxFilter(bool prev=false) {
RxFilter f;
if (prev) { if (prev) {
_filter = RxFilter((_filter - 1) % NUM_RX_FILTERS); f = RxFilter(_filter > 0 ? _filter - 1 : NUM_RX_FILTERS - 1);
} else { } 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;
} }
/* /*
@ -316,7 +326,7 @@ class Rig {
RxFilter _filter; RxFilter _filter;
char _modeText[17]; // char _modeText[17];
/* /*
IFilter** _rxFilters; IFilter** _rxFilters;

View File

@ -44,6 +44,7 @@ elapsedMillis btnMillis;
TopMenu topMenu(rig); TopMenu topMenu(rig);
MenuItem* menu = &topMenu; MenuItem* menu = &topMenu;
elapsedMillis menuUpdateMillis;
elapsedMillis frameMillis; elapsedMillis frameMillis;
unsigned frameTime; unsigned frameTime;
unsigned frameCounter; unsigned frameCounter;
@ -78,6 +79,8 @@ void setup() {
frameCounter = 0; frameCounter = 0;
frameMillis = 0; frameMillis = 0;
menuUpdateMillis = 0;
knob.write(0); knob.write(0);
btn.attach(ENCODER_SW_PIN, INPUT_PULLUP); btn.attach(ENCODER_SW_PIN, INPUT_PULLUP);
@ -101,6 +104,7 @@ void setup() {
void loop() void loop()
{ {
static char frame_status[100]; static char frame_status[100];
static char old_mode_text[17] = " ";
static bool paddle_loop = false; static bool paddle_loop = false;
// long oldPos = knobPos; // long oldPos = knobPos;
@ -162,6 +166,7 @@ void loop()
serviceCAT(); serviceCAT();
/*
// send current status @ 10 Hz // send current status @ 10 Hz
//if (frame10Hz > 100) { //if (frame10Hz > 100) {
if ((rig.modeNum() != oldRigMode)) { // || (rxFilter != oldRxFilter)) { if ((rig.modeNum() != oldRigMode)) { // || (rxFilter != oldRxFilter)) {
@ -209,7 +214,7 @@ void loop()
} }
//frame10Hz = 0; //frame10Hz = 0;
} }
*/
btn.update(); btn.update();
if (btn.fell()) { if (btn.fell()) {
//sendIOPMenuDisplay("PRESSED ", 2); //sendIOPMenuDisplay("PRESSED ", 2);
@ -220,17 +225,18 @@ void loop()
// long press - exit // long press - exit
//sendIOPMenuDisplay("REL-LONG ", 2); //sendIOPMenuDisplay("REL-LONG ", 2);
menu->exit(); menu->exit();
USBDEBUG("button released - long"); USBDEBUG("button released - long (exit)");
} if (btnMillis > 500) { } if (btnMillis > 500) {
// medium press - altSelect // medium press - altSelect
menu->altSelect(); menu->altSelect();
USBDEBUG("button released - medium (altSelect)");
} else { } else {
// short press - select // short press - select
//sendIOPMenuDisplay("REL-SHORT ", 2); //sendIOPMenuDisplay("REL-SHORT ", 2);
menu->select(); menu->select();
USBDEBUG("button released - short"); USBDEBUG("button released - short (select)");
} }
menu->update(); // menu->update();
} }
knobPos = knob.read(); knobPos = knob.read();
@ -240,18 +246,29 @@ void loop()
// left // left
//sendIOPMenuDisplay("LEFT ", 5); //sendIOPMenuDisplay("LEFT ", 5);
menu->prev(); menu->prev();
menu->update(); // menu->update();
knob.write(0); knob.write(0);
USBDEBUG("knob turned left"); USBDEBUG("knob turned left");
} else if (knobPos < -3) { } else if (knobPos < -3) {
// right // right
//sendIOPMenuDisplay("RIGHT ", 5); //sendIOPMenuDisplay("RIGHT ", 5);
menu->next(); menu->next();
menu->update(); // menu->update();
knob.write(0); knob.write(0);
USBDEBUG("knob turned right"); 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 (frameMillis > 5000) {
#if defined(DEBUG) #if defined(DEBUG)
frameTime = frameMillis; frameTime = frameMillis;