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; }
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.
@ -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()
{
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;
};
//======================================================================
@ -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()
{
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

View File

@ -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];
};
/*

View File

@ -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,11 +204,18 @@ 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;
}
/*
@ -316,7 +326,7 @@ class Rig {
RxFilter _filter;
char _modeText[17];
// char _modeText[17];
/*
IFilter** _rxFilters;

View File

@ -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;