Trainer setup fixes

This commit is contained in:
Raphael Coeffic
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent 4953d7442d
commit 0a486931ba
+30 -49
View File
@@ -34,8 +34,6 @@
#include "bluetooth.h"
#endif
class TrChoice;
class TrainerModuleWindow : public FormGroup
{
public:
@@ -45,10 +43,10 @@ class TrainerModuleWindow : public FormGroup
void update();
protected:
TrChoice *trainerChoice = nullptr;
// TrChoice *trainerChoice = nullptr;
NumberEdit *channelStart = nullptr;
NumberEdit *channelEnd = nullptr;
bool trChoiceOpen = false;
// bool trChoiceOpen = false;
#if defined(BLUETOOTH)
StaticText *btChannelEnd = nullptr;
StaticText *btDistAddress = nullptr;
@@ -67,29 +65,6 @@ class TrainerModuleWindow : public FormGroup
#endif
};
class TrChoice : public Choice
{
public:
TrChoice(FormGroup *parent, const rect_t &rect, const char **values, int vmin,
int vmax, std::function<int()> getValue,
std::function<void(int)> setValue = nullptr,
bool *menuOpen = nullptr) :
Choice(parent, rect, values, vmin, vmax, getValue, setValue),
menuOpen(menuOpen)
{
}
protected:
void openMenu()
{
if (menuOpen) *menuOpen = true;
Choice::openMenu();
}
private:
bool *menuOpen;
};
TrainerModuleWindow::TrainerModuleWindow(FormWindow *parent,
const rect_t &rect) :
FormGroup(parent, rect, FORWARD_SCROLL | NO_FOCUS | FORM_FORWARD_FOCUS)
@@ -127,27 +102,6 @@ void TrainerModuleWindow::update()
FormGridLayout grid;
clear();
new StaticText(this, grid.getLabelSlot(true), STR_MODE, 0,
COLOR_THEME_PRIMARY1);
trainerChoice = new TrChoice(
this, grid.getFieldSlot(), STR_VTRAINERMODES, 0, TRAINER_MODE_MAX(),
GET_DEFAULT(g_model.trainerData.mode),
[=](int32_t newValue) {
#if defined(BLUETOOTH)
memclear(bluetooth.distantAddr, sizeof(bluetooth.distantAddr));
bluetooth.state = BLUETOOTH_STATE_OFF;
#endif
g_model.trainerData.mode = newValue;
SET_DIRTY();
update();
trainerChoice->setFocus(SET_FOCUS_DEFAULT);
trChoiceOpen = false;
},
&trChoiceOpen);
trainerChoice->setAvailableHandler(isTrainerModeAvailable);
grid.nextLine();
if (g_model.isTrainerTraineeEnable()) {
#if defined(BLUETOOTH)
if (g_model.trainerData.mode == TRAINER_MODE_MASTER_BLUETOOTH) {
@@ -334,5 +288,32 @@ TrainerPage::TrainerPage() : Page(ICON_MODEL_SETUP)
PAGE_LINE_HEIGHT},
STR_TRAINER, 0, COLOR_THEME_PRIMARY2);
new TrainerModuleWindow(&body, {0, 0, width(), 0});
FormGridLayout grid;
new StaticText(&body, grid.getLabelSlot(true), STR_MODE, 0,
COLOR_THEME_PRIMARY1);
auto trainerChoice = new Choice(
&body, grid.getFieldSlot(), STR_VTRAINERMODES, 0, TRAINER_MODE_MAX(),
GET_DEFAULT(g_model.trainerData.mode));
trainerChoice->setAvailableHandler(isTrainerModeAvailable);
grid.nextLine();
coord_t y = grid.getWindowHeight();
coord_t h = body.height() - y;
coord_t w = body.width();
auto trainerModule = new TrainerModuleWindow(&body, {0, y, w, h});
TrainerModuleData* tr = &g_model.trainerData;
trainerChoice->setSetValueHandler([=](int32_t newValue) {
#if defined(BLUETOOTH)
memclear(bluetooth.distantAddr, sizeof(bluetooth.distantAddr));
bluetooth.state = BLUETOOTH_STATE_OFF;
#endif
tr->mode = newValue;
trainerModule->update();
SET_DIRTY();
});
}