Fix access settings pop-ups

This commit is contained in:
Raphael Coeffic
2022-08-18 12:38:35 +10:00
committed by Peter Feerick
parent 6028c24f36
commit 647d19bbc9
7 changed files with 222 additions and 170 deletions
+167 -147
View File
@@ -123,14 +123,24 @@ bool BindRxChoiceMenu::onTouchEnd(coord_t x, coord_t y)
} }
#endif #endif
static const lv_coord_t line_col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1),
LV_GRID_TEMPLATE_LAST};
static const lv_coord_t line_row_dsc[] = {LV_GRID_CONTENT,
LV_GRID_TEMPLATE_LAST};
BindWaitDialog::BindWaitDialog(Window* parent, uint8_t moduleIdx, BindWaitDialog::BindWaitDialog(Window* parent, uint8_t moduleIdx,
uint8_t receiverIdx) : uint8_t receiverIdx) :
Dialog(parent, STR_BIND, {50, 73, LCD_W - 100, LCD_H - 146}), Dialog(parent, STR_BIND, rect_t{}),
moduleIdx(moduleIdx), moduleIdx(moduleIdx),
receiverIdx(receiverIdx) receiverIdx(receiverIdx)
{ {
new StaticText(&content->form, {0, height() / 2, width(), PAGE_LINE_HEIGHT}, setCloseWhenClickOutside(true);
STR_WAITING_FOR_RX, 0, CENTERED | COLOR_THEME_PRIMARY1); auto form = &content->form;
new StaticText(form, rect_t{}, STR_WAITING_FOR_RX, 0, COLOR_THEME_PRIMARY1);
content->setWidth(LCD_W * 0.8);
content->updateSize();
setCloseHandler([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; }); setCloseHandler([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; });
} }
@@ -144,6 +154,8 @@ void BindWaitDialog::checkEvents()
{ {
auto& bindInfo = getPXX2BindInformationBuffer(); auto& bindInfo = getPXX2BindInformationBuffer();
auto form = &content->form;
if (moduleState[moduleIdx].mode == MODULE_MODE_NORMAL) { if (moduleState[moduleIdx].mode == MODULE_MODE_NORMAL) {
// returned to normal after bind // returned to normal after bind
@@ -217,7 +229,6 @@ uint8_t ReceiverButton::pressBind()
return 0; return 0;
}); });
menu->addLine(STR_OPTIONS, [=]() { menu->addLine(STR_OPTIONS, [=]() {
// pushMenu(menuModelReceiverOptions);
new RxOptions(this, moduleIdx, receiverIdx); new RxOptions(this, moduleIdx, receiverIdx);
return 0; return 0;
}); });
@@ -243,7 +254,7 @@ uint8_t ReceiverButton::pressBind()
memclear(&modSetup, sizeof(modSetup)); memclear(&modSetup, sizeof(modSetup));
modSetup.resetReceiverIndex = receiverIdx; modSetup.resetReceiverIndex = receiverIdx;
modSetup.resetReceiverFlags = 0xFF; modSetup.resetReceiverFlags = 0xFF;
new ConfirmDialog(parent, STR_RECEIVER, STR_RECEIVER_DELETE, [=]() { new ConfirmDialog(parent, STR_RECEIVER, STR_RECEIVER_RESET, [=]() {
moduleState[moduleIdx].mode = MODULE_MODE_RESET; moduleState[moduleIdx].mode = MODULE_MODE_RESET;
removePXX2Receiver(moduleIdx, receiverIdx); removePXX2Receiver(moduleIdx, receiverIdx);
}); });
@@ -299,50 +310,58 @@ void ReceiverButton::checkEvents()
} }
RegisterDialog::RegisterDialog(Window* parent, uint8_t moduleIdx) : RegisterDialog::RegisterDialog(Window* parent, uint8_t moduleIdx) :
Dialog(parent, STR_REGISTER, {50, 73, LCD_W - 100, 0}), moduleIdx(moduleIdx) Dialog(parent, STR_REGISTER, rect_t{}), moduleIdx(moduleIdx)
{ {
FormGroup* form = &content->form; setCloseWhenClickOutside(true);
FormGridLayout grid(content->form.width()); auto form = &content->form;
grid.setLabelWidth(150);
grid.spacer(PAGE_PADDING); FlexGridLayout grid(line_col_dsc, line_row_dsc);
// Register ID // Register ID
new StaticText(form, grid.getLabelSlot(), STR_REG_ID, 0, auto line = form->newLine(&grid);
COLOR_THEME_PRIMARY1); new StaticText(line, rect_t{}, STR_REG_ID, 0, COLOR_THEME_PRIMARY1);
auto edit = reg_id = new ModelTextEdit(line, rect_t{}, g_model.modelRegistrationID,
new ModelTextEdit(form, grid.getFieldSlot(), g_model.modelRegistrationID, sizeof(g_model.modelRegistrationID));
sizeof(g_model.modelRegistrationID));
grid.nextLine();
// UID // UID
new StaticText(form, grid.getLabelSlot(), "UID", 0, COLOR_THEME_PRIMARY1); line = form->newLine(&grid);
uid = new NumberEdit( new StaticText(line, rect_t{}, "UID", 0, COLOR_THEME_PRIMARY1);
form, grid.getFieldSlot(), 0, 2,
GET_SET_DEFAULT(getPXX2ModuleSetupBuffer().registerLoopIndex)); auto* modSetup = &(getPXX2ModuleSetupBuffer());
grid.nextLine(); uid = new NumberEdit(line, rect_t{}, 0, 2, GET_SET_DEFAULT(modSetup->registerLoopIndex));
// RX name // RX name
new StaticText(form, grid.getLabelSlot(), STR_RX_NAME, 0, line = form->newLine(&grid);
COLOR_THEME_PRIMARY1); new StaticText(line, rect_t{}, STR_RX_NAME, 0, COLOR_THEME_PRIMARY1);
waiting = new StaticText(form, grid.getFieldSlot(), STR_WAITING_FOR_RX, 0,
COLOR_THEME_PRIMARY1);
grid.nextLine();
grid.spacer(6);
// Buttons start(); // clears registration data buffer
exitButton = rx_name = new ModelTextEdit(line, rect_t{}, modSetup->registerRxName, PXX2_LEN_RX_NAME);
new TextButton(form, grid.getLabelSlot(), "EXIT", [=]() -> int8_t { //lv_textarea_set_text(rx_name->getLvObj(), STR_WAITING_FOR_RX);
this->deleteLater(); lv_obj_add_state(rx_name->getLvObj(), LV_STATE_DISABLED);
return 0;
});
// exitButton->setFocus(SET_FOCUS_DEFAULT);
grid.nextLine();
grid.spacer(PAGE_PADDING);
form->setHeight(grid.getWindowHeight()); // Status
content->adjustHeight(); // line = form->newLine(&grid);
// new StaticText(line, rect_t{}, STR_STATUS, 0, COLOR_THEME_PRIMARY1);
// status = new StaticText(line, rect_t{}, STR_WAITING_FOR_RX, 0, COLOR_THEME_PRIMARY1);
start(); auto box = new FormGroup(form, rect_t{});
box->setFlexLayout(LV_FLEX_FLOW_ROW_WRAP, lv_dpx(8));
lv_obj_set_style_flex_main_place(box->getLvObj(), LV_FLEX_ALIGN_SPACE_EVENLY, 0);
box->padAll(lv_dpx(8));
new TextButton(box, rect_t{}, STR_CANCEL, [=]() -> int8_t {
this->deleteLater();
return 0;
});
btn_ok = new TextButton(box, rect_t{}, STR_SAVE, [=]() -> int8_t {
modSetup->registerStep = REGISTER_RX_NAME_SELECTED;
return 0;
});
lv_obj_add_flag(btn_ok->getLvObj(), LV_OBJ_FLAG_HIDDEN);
content->setWidth(LCD_W * 0.8);
content->updateSize();
setCloseHandler([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; }); setCloseHandler([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; });
} }
@@ -352,40 +371,53 @@ void RegisterDialog::start()
auto& pxx2Setup = getPXX2ModuleSetupBuffer(); auto& pxx2Setup = getPXX2ModuleSetupBuffer();
memclear(&pxx2Setup, sizeof(pxx2Setup)); memclear(&pxx2Setup, sizeof(pxx2Setup));
moduleState[moduleIdx].mode = MODULE_MODE_REGISTER; moduleState[moduleIdx].mode = MODULE_MODE_REGISTER;
old_registerStep = REGISTER_INIT;
} }
void RegisterDialog::checkEvents() void RegisterDialog::checkEvents()
{ {
auto& modSetup = getPXX2ModuleSetupBuffer(); auto& modSetup = getPXX2ModuleSetupBuffer();
if (!rxName && modSetup.registerStep >= REGISTER_RX_NAME_RECEIVED) {
rect_t rect = waiting->getRect();
waiting->deleteLater();
rxName = new ModelTextEdit(&content->form, rect, modSetup.registerRxName, #if defined(SIMU)
PXX2_LEN_RX_NAME); if (modSetup.registerStep == REGISTER_INIT) {
rect = exitButton->getRect(); memcpy(modSetup.registerRxName, "SimuRx ", PXX2_LEN_RX_NAME);
auto okButton = new TextButton(&content->form, rect, "OK", [=]() -> int8_t { modSetup.registerStep = REGISTER_RX_NAME_RECEIVED;
auto& modSetup = getPXX2ModuleSetupBuffer(); } else if (modSetup.registerStep == REGISTER_RX_NAME_SELECTED) {
modSetup.registerStep = REGISTER_RX_NAME_SELECTED; modSetup.registerStep = REGISTER_OK;
return 0; moduleState[moduleIdx].mode = MODULE_MODE_NORMAL;
}); }
exitButton->setLeft(left() + rect.w + 10); #endif
} else if (modSetup.registerStep == REGISTER_OK) {
deleteLater(); if (old_registerStep != modSetup.registerStep) {
POPUP_INFORMATION(STR_REG_OK); old_registerStep = modSetup.registerStep;
if (modSetup.registerStep == REGISTER_RX_NAME_RECEIVED) {
lv_obj_clear_state(rx_name->getLvObj(), LV_STATE_DISABLED);
lv_obj_clear_flag(btn_ok->getLvObj(), LV_OBJ_FLAG_HIDDEN);
// lv_obj_add_flag(status->getLvObj(), LV_OBJ_FLAG_HIDDEN);
rx_name->update();
} else if (modSetup.registerStep == REGISTER_OK) {
deleteLater();
POPUP_INFORMATION(STR_REG_OK);
// pop-up call garbage collector,
// so that the dialog is alread destroyed
return;
}
} }
Dialog::checkEvents(); Dialog::checkEvents();
} }
ModuleOptions::ModuleOptions(Window* parent, uint8_t moduleIdx): ModuleOptions::ModuleOptions(Window* parent, uint8_t moduleIdx):
Dialog(parent, STR_MODULE_OPTIONS, {50, 73, LCD_W - 100, LCD_H - 146}), Dialog(parent, STR_MODULE_OPTIONS, rect_t{}),
moduleIdx(moduleIdx) moduleIdx(moduleIdx)
{ {
setCloseWhenClickOutside(true); setCloseWhenClickOutside(true);
auto form = &content->form; auto form = &content->form;
new StaticText(form, {0, height() / 2, width(), PAGE_LINE_HEIGHT}, new StaticText(form, rect_t{}, STR_WAITING_FOR_MODULE, COLOR_THEME_PRIMARY1);
STR_WAITING_FOR_MODULE, CENTERED | VCENTERED | COLOR_THEME_PRIMARY1);
content->setWidth(LCD_W * 0.8);
content->updateSize();
#if defined(SIMU) #if defined(SIMU)
auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
@@ -395,7 +427,6 @@ ModuleOptions::ModuleOptions(Window* parent, uint8_t moduleIdx):
state = MO_ReadModuleSettings; state = MO_ReadModuleSettings;
#endif #endif
setCloseHandler([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; }); setCloseHandler([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; });
// setFocus();
} }
void ModuleOptions::checkEvents() void ModuleOptions::checkEvents()
@@ -477,22 +508,23 @@ void ModuleOptions::update()
getPXX2ModuleOptions(modelId) & getPXX2ModuleOptions(modelId) &
((1 << MODULE_OPTION_EXTERNAL_ANTENNA) | (1 << MODULE_OPTION_POWER)); ((1 << MODULE_OPTION_EXTERNAL_ANTENNA) | (1 << MODULE_OPTION_POWER));
FormGridLayout grid(content->form.width(), 10); FlexGridLayout grid(line_col_dsc, line_row_dsc, 2);
grid.setLabelWidth(width() / 3);
new StaticText(form, grid.getLabelSlot(), STR_MODULE); auto line = form->newLine(&grid);
new StaticText(form, grid.getFieldSlot(), getPXX2ModuleName(modelId)); new StaticText(line, rect_t{}, STR_MODULE);
grid.nextLine(); new StaticText(line, rect_t{}, getPXX2ModuleName(modelId));
if (!optionsAvailable) { if (!optionsAvailable) {
// no options available // no options available
new StaticText(form, grid.getCenteredSlot(), STR_NO_TX_OPTIONS, 0, CENTERED); line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_NO_TX_OPTIONS, 0);
} else { } else {
// some options available // some options available
if (optionsAvailable & (1 << MODULE_OPTION_EXTERNAL_ANTENNA)) { if (optionsAvailable & (1 << MODULE_OPTION_EXTERNAL_ANTENNA)) {
new StaticText(form, grid.getLabelSlot(), STR_EXT_ANTENNA, 0,
COLOR_THEME_PRIMARY1); line = form->newLine(&grid);
new CheckBox(form, grid.getFieldSlot(), new StaticText(line, rect_t{}, STR_EXT_ANTENNA, 0, COLOR_THEME_PRIMARY1);
new CheckBox(line, rect_t{},
[]() { []() {
const auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); const auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
return hwSettings.moduleSettings.externalAntenna; return hwSettings.moduleSettings.externalAntenna;
@@ -501,16 +533,15 @@ void ModuleOptions::update()
auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
hwSettings.moduleSettings.externalAntenna = val; hwSettings.moduleSettings.externalAntenna = val;
}); });
grid.nextLine();
} }
if (optionsAvailable & (1 << MODULE_OPTION_POWER)) { if (optionsAvailable & (1 << MODULE_OPTION_POWER)) {
// TODO: use isTelemetryAvailable() to check if rebind is necessary // TODO: use isTelemetryAvailable() to check if rebind is necessary
new StaticText(form, grid.getLabelSlot(), STR_POWER, 0, line = form->newLine(&grid);
COLOR_THEME_PRIMARY1); new StaticText(line, rect_t{}, STR_POWER, 0, COLOR_THEME_PRIMARY1);
auto txPower = new Choice( auto txPower = new Choice(
form, grid.getFieldSlot(), 0, 30, line, rect_t{}, 0, 30,
[]() { []() {
const auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); const auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
return hwSettings.moduleSettings.txPower; return hwSettings.moduleSettings.txPower;
@@ -544,33 +575,30 @@ void ModuleOptions::update()
const auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); const auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
return isPXX2PowerAvailable(hwSettings.modules[moduleIdx].information, val); return isPXX2PowerAvailable(hwSettings.modules[moduleIdx].information, val);
}); });
grid.nextLine();
} }
} }
new DynamicText(form, grid.getFieldSlot(), [=]() { return statusText; }); line = form->newLine(&grid);
grid.setLabelWidth(15); new DynamicText(line, rect_t{}, [=]() { return statusText; });
grid.setMarginRight(15);
grid.nextLine();
auto exitButton = line = form->newLine(&grid);
new TextButton(form, grid.getFieldSlot(2, 0), STR_EXIT, [=]() -> int8_t {
this->deleteLater();
return 0;
});
new TextButton(form, grid.getFieldSlot(2, 1), STR_OK, [=]() -> int8_t { auto box = new FormGroup(form, rect_t{});
box->setFlexLayout(LV_FLEX_FLOW_ROW_WRAP, lv_dpx(8));
lv_obj_set_style_flex_main_place(box->getLvObj(), LV_FLEX_ALIGN_SPACE_EVENLY, 0);
box->padAll(lv_dpx(8));
new TextButton(box, rect_t{}, STR_CANCEL, [=]() -> int8_t {
this->deleteLater();
return 0;
});
new TextButton(box, rect_t{}, STR_SAVE, [=]() -> int8_t {
this->writeSettings(); this->writeSettings();
return 0; return 0;
}); });
// exitButton->setFocus(SET_FOCUS_DEFAULT); content->updateSize();
grid.nextLine();
grid.spacer(PAGE_PADDING);
content->adjustHeight();
content->setWindowCentered();
} }
void ModuleOptions::writeSettings() void ModuleOptions::writeSettings()
@@ -582,17 +610,16 @@ void ModuleOptions::writeSettings()
} }
RxOptions::RxOptions(Window* parent, uint8_t moduleIdx, uint8_t rxIdx): RxOptions::RxOptions(Window* parent, uint8_t moduleIdx, uint8_t rxIdx):
Dialog(parent, STR_RECEIVER_OPTIONS, {50, 73, LCD_W - 100, LCD_H - 146}), Dialog(parent, STR_RECEIVER_OPTIONS, rect_t{}),
moduleIdx(moduleIdx), moduleIdx(moduleIdx),
receiverIdx(rxIdx) receiverIdx(rxIdx)
{ {
setCloseWhenClickOutside(true); setCloseWhenClickOutside(true);
auto form = &content->form; auto form = &content->form;
new StaticText( new StaticText(form, rect_t{}, STR_WAITING_FOR_RX, 0, COLOR_THEME_PRIMARY1);
form,
{0, static_cast<coord_t>(form->height() / 2 - PAGE_LINE_HEIGHT), content->setWidth(LCD_W * 0.8);
form->width(), PAGE_LINE_HEIGHT}, content->updateSize();
STR_WAITING_FOR_RX, 0, CENTERED | VCENTERED | COLOR_THEME_PRIMARY1);
#if defined(SIMU) #if defined(SIMU)
auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
@@ -609,7 +636,6 @@ RxOptions::RxOptions(Window* parent, uint8_t moduleIdx, uint8_t rxIdx):
} }
#endif #endif
setCloseHandler([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; }); setCloseHandler([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; });
// setFocus();
} }
void RxOptions::checkEvents() void RxOptions::checkEvents()
@@ -716,19 +742,18 @@ void RxOptions::update()
uint8_t receiverVariant = rxInfo.variant; uint8_t receiverVariant = rxInfo.variant;
uint8_t capabilities = rxInfo.capabilities; uint8_t capabilities = rxInfo.capabilities;
FormGridLayout grid(content->form.width(), 10); FlexGridLayout grid(line_col_dsc, line_row_dsc, 2);
grid.setLabelWidth(width() / 3);
new StaticText(form, grid.getLabelSlot(), STR_RECEIVER); auto line = form->newLine(&grid);
new StaticText(form, grid.getFieldSlot(), new StaticText(line, rect_t{}, STR_RECEIVER);
new StaticText(line, rect_t{},
g_model.moduleData[moduleIdx].pxx2.receiverName[receiverIdx]); g_model.moduleData[moduleIdx].pxx2.receiverName[receiverIdx]);
grid.nextLine();
// PWM rate // PWM rate
new StaticText(form, grid.getLabelSlot(), line = form->newLine(&grid);
isModuleR9MAccess(moduleIdx) ? "6.67ms PWM" : "7ms PWM"); new StaticText(line, rect_t{}, isModuleR9MAccess(moduleIdx) ? "6.67ms PWM" : "7ms PWM");
new CheckBox( new CheckBox(
form, grid.getFieldSlot(), line, rect_t{},
[]() { []() {
auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
return hwSettings.receiverSettings.pwmRate; return hwSettings.receiverSettings.pwmRate;
@@ -737,12 +762,12 @@ void RxOptions::update()
auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
hwSettings.receiverSettings.pwmRate = val; hwSettings.receiverSettings.pwmRate = val;
}); });
grid.nextLine();
// telemetry disabled // telemetry disabled
new StaticText(form, grid.getLabelSlot(), STR_TELEMETRY_DISABLED); line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_TELEMETRY_DISABLED);
auto tele25mw = new CheckBox( auto tele25mw = new CheckBox(
form, grid.getFieldSlot(), line, rect_t{},
[]() { []() {
auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
return hwSettings.receiverSettings.telemetryDisabled; return hwSettings.receiverSettings.telemetryDisabled;
@@ -757,13 +782,13 @@ void RxOptions::update()
// read only field in this case // read only field in this case
tele25mw->disable(); tele25mw->disable();
} }
grid.nextLine();
if (capabilities & (1 << RECEIVER_CAPABILITY_TELEMETRY_25MW)) { if (capabilities & (1 << RECEIVER_CAPABILITY_TELEMETRY_25MW)) {
// telemetry 25 mW // telemetry 25 mW
new StaticText(form, grid.getLabelSlot(), "25mw Tele"); line = form->newLine(&grid);
new StaticText(line, rect_t{}, "25mw Tele");
new CheckBox( new CheckBox(
form, grid.getFieldSlot(), line, rect_t{},
[]() { []() {
auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
return hwSettings.receiverSettings.telemetry25mw; return hwSettings.receiverSettings.telemetry25mw;
@@ -772,16 +797,16 @@ void RxOptions::update()
auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
hwSettings.receiverSettings.telemetry25mw = val; hwSettings.receiverSettings.telemetry25mw = val;
}); });
grid.nextLine();
} }
if (capabilities & if (capabilities &
((1 << RECEIVER_CAPABILITY_FPORT) | (1 << RECEIVER_CAPABILITY_FPORT2))) { ((1 << RECEIVER_CAPABILITY_FPORT) | (1 << RECEIVER_CAPABILITY_FPORT2))) {
// SPORT modes // SPORT modes
new StaticText(form, grid.getLabelSlot(), STR_PROTOCOL); line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_PROTOCOL);
auto sportModes = new Choice( auto sportModes = new Choice(
form, grid.getFieldSlot(2, 0), STR_SPORT_MODES, 0, 2, line, rect_t{}, STR_SPORT_MODES, 0, 2,
[]() { []() {
const auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); const auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
const auto& rxSettings = hwSettings.receiverSettings; const auto& rxSettings = hwSettings.receiverSettings;
@@ -803,13 +828,13 @@ void RxOptions::update()
} }
return true; return true;
}); });
grid.nextLine();
} }
auto outputsCount = min<uint8_t>(16, hwSettings.receiverSettings.outputsCount); auto outputsCount = min<uint8_t>(16, hwSettings.receiverSettings.outputsCount);
for (uint8_t i = 0; i < outputsCount; i++) { for (uint8_t i = 0; i < outputsCount; i++) {
line = form->newLine(&grid);
std::string i_str = std::to_string(i+1); std::string i_str = std::to_string(i+1);
new StaticText(form, grid.getLabelSlot(), std::string(STR_PIN) + i_str); new StaticText(line, rect_t{}, std::string(STR_PIN) + i_str);
uint8_t channelsMax = sentModuleChannels(moduleIdx) - 1; uint8_t channelsMax = sentModuleChannels(moduleIdx) - 1;
uint8_t selectionMax = channelsMax; uint8_t selectionMax = channelsMax;
@@ -821,15 +846,16 @@ void RxOptions::update()
uint8_t mapping = hwSettings.receiverSettings.outputsMapping[i]; uint8_t mapping = hwSettings.receiverSettings.outputsMapping[i];
uint8_t channel = getShiftedChannel(moduleIdx, mapping); uint8_t channel = getShiftedChannel(moduleIdx, mapping);
auto r = grid.getFieldSlot(2, 1); // TODO
if (r.h > BAR_HEIGHT) { // auto r = grid.getFieldSlot(2, 1);
r.y += (r.h - BAR_HEIGHT)/2; // if (r.h > BAR_HEIGHT) {
r.h = BAR_HEIGHT; // r.y += (r.h - BAR_HEIGHT)/2;
} // r.h = BAR_HEIGHT;
auto chBar = new OutputChannelBar(form, r, channel); // }
// auto chBar = new OutputChannelBar(form, r, channel);
auto chDn = new Choice( auto chDn = new Choice(
form, grid.getFieldSlot(2, 0), 0, selectionMax, line, rect_t{}, 0, selectionMax,
[=]() { [=]() {
auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
return hwSettings.receiverSettings.outputsMapping[i]; return hwSettings.receiverSettings.outputsMapping[i];
@@ -837,42 +863,36 @@ void RxOptions::update()
[=](int val) { [=](int val) {
auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
hwSettings.receiverSettings.outputsMapping[i] = val; hwSettings.receiverSettings.outputsMapping[i] = val;
if (val <= channelsMax) { // if (val <= channelsMax) {
chBar->setChannel(getShiftedChannel(moduleIdx, val)); // chBar->setChannel(getShiftedChannel(moduleIdx, val));
lv_obj_clear_flag(chBar->getLvObj(), LV_OBJ_FLAG_HIDDEN); // lv_obj_clear_flag(chBar->getLvObj(), LV_OBJ_FLAG_HIDDEN);
} else { // } else {
lv_obj_add_flag(chBar->getLvObj(), LV_OBJ_FLAG_HIDDEN); // lv_obj_add_flag(chBar->getLvObj(), LV_OBJ_FLAG_HIDDEN);
} // }
}); });
chDn->setTextHandler( chDn->setTextHandler(
[=](int val) { return getChannelText(moduleIdx, i, val); }); [=](int val) { return getChannelText(moduleIdx, i, val); });
grid.nextLine();
} }
new DynamicText(form, grid.getFieldSlot(), [=]() { return statusText; }); line = form->newLine(&grid);
grid.setLabelWidth(15); new DynamicText(line, rect_t{}, [=]() { return statusText; });
grid.setMarginRight(15);
grid.nextLine();
auto exitButton = auto box = new FormGroup(form, rect_t{});
new TextButton(form, grid.getFieldSlot(2, 0), STR_EXIT, [=]() -> int8_t { box->setFlexLayout(LV_FLEX_FLOW_ROW_WRAP, lv_dpx(8));
this->deleteLater(); lv_obj_set_style_flex_main_place(box->getLvObj(), LV_FLEX_ALIGN_SPACE_EVENLY, 0);
return 0; box->padAll(lv_dpx(8));
});
new TextButton(form, grid.getFieldSlot(2, 1), STR_OK, [=]() -> int8_t { new TextButton(box, rect_t{}, STR_CANCEL, [=]() -> int8_t {
this->deleteLater();
return 0;
});
new TextButton(box, rect_t{}, STR_SAVE, [=]() -> int8_t {
this->writeSettings(); this->writeSettings();
return 0; return 0;
}); });
// exitButton->setFocus(SET_FOCUS_DEFAULT); content->updateSize();
grid.nextLine();
grid.spacer(PAGE_PADDING);
content->adjustHeight();
content->setWindowCentered();
} }
void RxOptions::writeSettings() void RxOptions::writeSettings()
+6 -4
View File
@@ -82,10 +82,12 @@ class RegisterDialog : public Dialog
protected: protected:
uint8_t moduleIdx; uint8_t moduleIdx;
NumberEdit* uid; uint8_t old_registerStep = 0;
StaticText* waiting; Window* reg_id = nullptr;
TextEdit* rxName = nullptr; Window* uid = nullptr;
TextButton* exitButton; TextEdit* rx_name = nullptr;
StaticText* status = nullptr;
Window* btn_ok = nullptr;
}; };
class ModuleOptions : public Dialog class ModuleOptions : public Dialog
+11 -2
View File
@@ -302,13 +302,17 @@ void ModuleWindow::updateModule()
if (isModuleRFAccess(moduleIdx)) { if (isModuleRFAccess(moduleIdx)) {
auto line = newLine(&grid); auto line = newLine(&grid);
new StaticText(line, rect_t{}, STR_MODULE, 0, COLOR_THEME_PRIMARY1); new StaticText(line, rect_t{}, STR_MODULE, 0, COLOR_THEME_PRIMARY1);
registerButton = new TextButton(line, rect_t{}, STR_REGISTER);
auto box = new FormGroup(line, rect_t{});
box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8));
registerButton = new TextButton(box, rect_t{}, STR_REGISTER);
registerButton->setPressHandler([=]() -> uint8_t { registerButton->setPressHandler([=]() -> uint8_t {
new pxx2::RegisterDialog(Layer::back(), moduleIdx); new pxx2::RegisterDialog(Layer::back(), moduleIdx);
return 0; return 0;
}); });
rangeButton = new TextButton(line, rect_t{}, STR_MODULE_RANGE); rangeButton = new TextButton(box, rect_t{}, STR_MODULE_RANGE);
rangeButton->setPressHandler([=]() -> uint8_t { rangeButton->setPressHandler([=]() -> uint8_t {
if (moduleState[moduleIdx].mode == MODULE_MODE_RANGECHECK) { if (moduleState[moduleIdx].mode == MODULE_MODE_RANGECHECK) {
moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; moduleState[moduleIdx].mode = MODULE_MODE_NORMAL;
@@ -416,6 +420,11 @@ void ModuleWindow::updateSubType()
lv_obj_add_flag(fsLine->getLvObj(), LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(fsLine->getLvObj(), LV_OBJ_FLAG_HIDDEN);
} }
} }
// TODO: ISRM
// - ACCESS "Register" vs D16 "Bind"
// - ACCESS module options
// - ACCESS Rx list
} }
#if defined(PCBNV14) #if defined(PCBNV14)
-5
View File
@@ -120,11 +120,6 @@ void ModuleState::startBind(BindInformation* destination,
bindInformation = destination; bindInformation = destination;
callback = bindCallback; callback = bindCallback;
mode = MODULE_MODE_BIND; mode = MODULE_MODE_BIND;
#if defined(SIMU)
bindInformation->candidateReceiversCount = 2;
strcpy(bindInformation->candidateReceiversNames[0], "SimuRX1");
strcpy(bindInformation->candidateReceiversNames[1], "SimuRX2");
#endif
} }
void ModuleState::readModuleInformation(ModuleInformation* destination, void ModuleState::readModuleInformation(ModuleInformation* destination,
+35 -11
View File
@@ -236,19 +236,42 @@ void Pxx2Pulses::setupRegisterFrame(uint8_t module)
{ {
addFrameType(PXX2_TYPE_C_MODULE, PXX2_TYPE_ID_REGISTER); addFrameType(PXX2_TYPE_C_MODULE, PXX2_TYPE_ID_REGISTER);
if (reusableBuffer.moduleSetup.pxx2.registerStep == REGISTER_RX_NAME_SELECTED) { auto& modSetup = getPXX2ModuleSetupBuffer();
if (modSetup.registerStep == REGISTER_RX_NAME_SELECTED) {
Pxx2Transport::addByte(0x01); Pxx2Transport::addByte(0x01);
for (uint8_t i=0; i<PXX2_LEN_RX_NAME; i++) { for (uint8_t i=0; i<PXX2_LEN_RX_NAME; i++) {
Pxx2Transport::addByte(reusableBuffer.moduleSetup.pxx2.registerRxName[i]); Pxx2Transport::addByte(modSetup.registerRxName[i]);
} }
for (uint8_t i=0; i<PXX2_LEN_REGISTRATION_ID; i++) { for (uint8_t i=0; i<PXX2_LEN_REGISTRATION_ID; i++) {
Pxx2Transport::addByte(g_model.modelRegistrationID[i]); Pxx2Transport::addByte(g_model.modelRegistrationID[i]);
} }
Pxx2Transport::addByte(reusableBuffer.moduleSetup.pxx2.registerLoopIndex); Pxx2Transport::addByte(modSetup.registerLoopIndex);
} }
else { else {
Pxx2Transport::addByte(0); Pxx2Transport::addByte(0);
} }
#if defined(SIMU)
if (modSetup.registerStep == REGISTER_INIT) {
memcpy(modSetup.registerRxName, "SimuRx ", PXX2_LEN_RX_NAME);
modSetup.registerStep = REGISTER_RX_NAME_RECEIVED;
} else if (modSetup.registerStep == REGISTER_RX_NAME_SELECTED) {
modSetup.registerStep = REGISTER_OK;
moduleState[module].mode = MODULE_MODE_NORMAL;
}
#endif
}
void Pxx2Pulses::setupBindFrame(uint8_t module)
{
if ((g_model.moduleData[module].type == MODULE_TYPE_ISRM_PXX2 &&
g_model.moduleData[module].subType !=
MODULE_SUBTYPE_ISRM_PXX2_ACCESS) ||
(g_model.moduleData[module].type == MODULE_TYPE_XJT_LITE_PXX2)) {
setupAccstBindFrame(module);
} else {
setupAccessBindFrame(module);
}
} }
void Pxx2Pulses::setupModuleSettingsFrame(uint8_t module, int16_t* channels, uint8_t nChannels) void Pxx2Pulses::setupModuleSettingsFrame(uint8_t module, int16_t* channels, uint8_t nChannels)
@@ -363,6 +386,14 @@ void Pxx2Pulses::setupAccessBindFrame(uint8_t module)
Pxx2Transport::addByte(g_model.modelRegistrationID[i]); Pxx2Transport::addByte(g_model.modelRegistrationID[i]);
} }
} }
#if defined(SIMU)
if (moduleState[module].mode == MODULE_MODE_BIND) {
destination->candidateReceiversCount = 2;
strcpy(destination->candidateReceiversNames[0], "SimuRX1");
strcpy(destination->candidateReceiversNames[1], "SimuRX2");
}
#endif
} }
void Pxx2Pulses::setupResetFrame(uint8_t module) void Pxx2Pulses::setupResetFrame(uint8_t module)
@@ -483,14 +514,7 @@ bool Pxx2Pulses::setupFrame(uint8_t module, int16_t* channels, uint8_t nChannels
setupRegisterFrame(module); setupRegisterFrame(module);
break; break;
case MODULE_MODE_BIND: case MODULE_MODE_BIND:
if ((g_model.moduleData[module].type == MODULE_TYPE_ISRM_PXX2 && setupBindFrame(module);
g_model.moduleData[module].subType !=
MODULE_SUBTYPE_ISRM_PXX2_ACCESS) ||
(g_model.moduleData[module].type == MODULE_TYPE_XJT_LITE_PXX2)) {
setupAccstBindFrame(module);
} else {
setupAccessBindFrame(module);
}
break; break;
case MODULE_MODE_RESET: case MODULE_MODE_RESET:
setupResetFrame(module); setupResetFrame(module);
+2
View File
@@ -472,6 +472,8 @@ class Pxx2Pulses: public Pxx2Transport {
void setupRegisterFrame(uint8_t module); void setupRegisterFrame(uint8_t module);
void setupBindFrame(uint8_t module);
void setupAccstBindFrame(uint8_t module); void setupAccstBindFrame(uint8_t module);
void setupAccessBindFrame(uint8_t module); void setupAccessBindFrame(uint8_t module);