Skip to content

Commit

Permalink
feat: Show available inputs when '+' button is tapped on the inputs p…
Browse files Browse the repository at this point in the history
…age (#3332)
  • Loading branch information
philmoz authored Mar 13, 2023
1 parent 3409455 commit 2ea8048
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
48 changes: 27 additions & 21 deletions radio/src/gui/colorlcd/model_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,6 @@ void insertExpo(uint8_t idx, uint8_t input)
storageDirty(EE_MODEL);
}

static bool getFreeInput(uint8_t& input, uint8_t& index)
{
uint8_t chn = 0;
ExpoData* line = g_model.expoData;
for (uint8_t i = 0; i < MAX_EXPOS; i++) {
if (!EXPO_VALID(line) || (line->chn > chn)) {
if (i >= MAX_EXPOS) break;
if (chn >= MAX_INPUTS) break;
index = i;
input = chn;
return true;
}
chn = line->chn + 1;
++line;
}

return false;
}

class InputLineButton : public InputMixButton
{
public:
Expand Down Expand Up @@ -349,6 +330,32 @@ void ModelInputsPage::addLineButton(mixsrc_t src, uint8_t index)
}
}

void ModelInputsPage::newInput()
{
Menu* menu = new Menu(Layer::back());
menu->setTitle(STR_MENU_INPUTS);

uint8_t chn = 0;
ExpoData* line = g_model.expoData;

// search for unused channels
for (uint8_t i = 0; i < MAX_EXPOS; i++) {
if (!EXPO_VALID(line) || (line->chn > chn)) {
if (chn >= MAX_INPUTS) break;
std::string name(getSourceString(chn+1));
menu->addLineBuffered(name.c_str(), [=]() { insertInput(chn, i); });
}
if (EXPO_VALID(line))
chn = line->chn + 1;
else
chn += 1;
++line;
}

menu->updateLines();
}


void ModelInputsPage::editInput(uint8_t input, uint8_t index)
{
_copyMode = 0;
Expand Down Expand Up @@ -473,8 +480,7 @@ void ModelInputsPage::build(FormWindow *window)
}

auto btn = new TextButton(window, rect_t{}, LV_SYMBOL_PLUS, [=]() {
uint8_t input, index;
if (getFreeInput(input, index)) insertInput(input, index);
newInput();
return 0;
});
auto btn_obj = btn->getLvObj();
Expand Down
1 change: 1 addition & 0 deletions radio/src/gui/colorlcd/model_inputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ModelInputsPage : public PageTab
virtual InputMixGroup* createGroup(FormGroup* form, mixsrc_t src);
virtual InputMixButton* createLineButton(InputMixGroup *group, uint8_t index);

void newInput();
void editInput(uint8_t input, uint8_t index);
void insertInput(uint8_t input, uint8_t index);
void deleteInput(uint8_t index);
Expand Down

0 comments on commit 2ea8048

Please sign in to comment.