feat(color): move model notes to model setup group in quick menu (#6737)

This commit is contained in:
philmoz
2025-10-30 16:23:37 +10:00
committed by GitHub
parent 5202c5c283
commit 4101d3fe0b
9 changed files with 315 additions and 270 deletions
@@ -34,6 +34,7 @@ SwitchWarnDialog::SwitchWarnDialog() :
void SwitchWarnDialog::delayedInit() void SwitchWarnDialog::delayedInit()
{ {
FullScreenDialog::delayedInit();
lv_label_set_long_mode(messageLabel->getLvObj(), LV_LABEL_LONG_WRAP); lv_label_set_long_mode(messageLabel->getLvObj(), LV_LABEL_LONG_WRAP);
AUDIO_ERROR_MESSAGE(AU_SWITCH_ALERT); AUDIO_ERROR_MESSAGE(AU_SWITCH_ALERT);
} }
@@ -103,6 +104,7 @@ ThrottleWarnDialog::ThrottleWarnDialog(const char* msg) :
void ThrottleWarnDialog::delayedInit() void ThrottleWarnDialog::delayedInit()
{ {
FullScreenDialog::delayedInit();
lv_label_set_long_mode(messageLabel->getLvObj(), LV_LABEL_LONG_WRAP); lv_label_set_long_mode(messageLabel->getLvObj(), LV_LABEL_LONG_WRAP);
AUDIO_ERROR_MESSAGE(AU_THROTTLE_ALERT); AUDIO_ERROR_MESSAGE(AU_THROTTLE_ALERT);
} }
@@ -49,11 +49,14 @@ FullScreenDialog::FullScreenDialog(
bringToTop(); bringToTop();
build();
delayLoad(); delayLoad();
} }
void FullScreenDialog::delayedInit()
{
build();
}
void FullScreenDialog::build() void FullScreenDialog::build()
{ {
auto div = new Window(this, {0, ALERT_FRAME_TOP, LCD_W, ALERT_FRAME_HEIGHT}); auto div = new Window(this, {0, ALERT_FRAME_TOP, LCD_W, ALERT_FRAME_HEIGHT});
@@ -86,4 +86,6 @@ class FullScreenDialog : public Window
StaticText* messageLabel; StaticText* messageLabel;
void build(); void build();
void delayedInit() override;
}; };
+142 -91
View File
@@ -27,7 +27,7 @@
#include "fullscreen_dialog.h" #include "fullscreen_dialog.h"
#include "lib_file.h" #include "lib_file.h"
// Used on startup to block until checlist is closed. // Used on startup to block until checklist is closed.
static bool checkListOpen = false; static bool checkListOpen = false;
// Check Box // Check Box
@@ -67,72 +67,45 @@ static lv_obj_t* checkbox_create(lv_obj_t* parent)
constexpr int maxTxtBuffSize = 64 * 1024; constexpr int maxTxtBuffSize = 64 * 1024;
ViewTextWindow::ViewTextWindow(const std::string path, const std::string name, class TextViewer
EdgeTxIcon icon) :
Page(icon, PAD_ZERO), path(std::move(path)), name(std::move(name))
{ {
fullPath = this->path + std::string(PATH_SEPARATOR) + this->name; public:
TextViewer(const std::string path, const std::string name) : name(std::move(name))
{
fullPath = path + std::string(PATH_SEPARATOR) + name;
extractNameSansExt(); extractNameSansExt();
header->setTitle(this->name);
delayLoad();
};
void ViewTextWindow::delayedInit()
{
if (buffer == nullptr) buildBody(body);
} }
void ViewTextWindow::onCancel() ~TextViewer()
{ {
Page::onCancel();
checkListOpen = false;
}
void ViewTextWindow::extractNameSansExt()
{
uint8_t nameLength;
uint8_t extLength;
const char* ext =
getFileExtension(name.c_str(), 0, 0, &nameLength, &extLength);
extension = std::string(ext);
openFromEnd = !strcmp(ext, LOGS_EXT);
}
bool ViewTextWindow::openFile()
{
FILINFO info;
if (buffer) { if (buffer) {
free(buffer); free(buffer);
buffer = nullptr; buffer = nullptr;
bufSize = 0;
}
auto res = f_stat((TCHAR*)fullPath.c_str(), &info);
if (res == FR_OK) {
fileLength = int(info.fsize);
bufSize = std::min(fileLength, maxTxtBuffSize) + 1;
buffer = (char*)malloc(bufSize);
if (buffer) {
offset =
std::max(int(openFromEnd ? int(info.fsize) - bufSize + 1 : 0), 0);
TRACE("info.fsize=%d\tbufSize=%d\toffset=%d", info.fsize, bufSize,
int(info.fsize) - bufSize + 1);
if (sdReadTextFileBlock(bufSize, offset) == FR_OK) {
return true;
}
} }
} }
return false; void onEvent(event_t event)
{
#if defined(HARDWARE_KEYS)
if (int(bufSize) < fileLength) {
if (event == EVT_KEY_BREAK(KEY_PAGEDN)) {
offset += bufSize;
} }
void ViewTextWindow::buildBody(Window* window) if (event == EVT_KEY_BREAK(KEY_PAGEUP)) {
offset -= bufSize;
}
offset = std::max(offset, 0);
offset = std::min(offset, fileLength - (int)bufSize);
sdReadTextFileBlock(bufSize, offset);
lv_label_set_text_static(lb, buffer);
}
#endif
}
void build(Window* window)
{ {
if (openFile()) { if (openFile()) {
auto obj = window->getLvObj(); auto obj = window->getLvObj();
@@ -159,8 +132,57 @@ void ViewTextWindow::buildBody(Window* window)
} }
} }
FRESULT ViewTextWindow::sdReadTextFileBlock(const uint32_t bufSize, protected:
const uint32_t offset) std::string name;
std::string fullPath;
lv_obj_t* lb;
int offset = 0;
char* buffer = nullptr;
size_t bufSize = 0;
int fileLength = 0;
bool openFromEnd;
void extractNameSansExt()
{
uint8_t nameLength;
uint8_t extLength;
const char* ext =
getFileExtension(name.c_str(), 0, 0, &nameLength, &extLength);
openFromEnd = !strcmp(ext, LOGS_EXT);
}
bool openFile()
{
FILINFO info;
if (buffer) {
free(buffer);
buffer = nullptr;
bufSize = 0;
}
auto res = f_stat((TCHAR*)fullPath.c_str(), &info);
if (res == FR_OK) {
fileLength = int(info.fsize);
bufSize = std::min(fileLength, maxTxtBuffSize) + 1;
buffer = (char*)malloc(bufSize);
if (buffer) {
offset = std::max(int(openFromEnd ? int(info.fsize) - bufSize + 1 : 0), 0);
if (sdReadTextFileBlock(bufSize, offset) == FR_OK) {
return true;
}
}
}
return false;
}
FRESULT sdReadTextFileBlock(const uint32_t bufSize, const uint32_t offset)
{ {
FIL file; FIL file;
char escape_chars[4]; char escape_chars[4];
@@ -222,43 +244,59 @@ FRESULT ViewTextWindow::sdReadTextFileBlock(const uint32_t bufSize,
} }
return res; return res;
} }
};
ViewTextWindow::ViewTextWindow(const std::string path, const std::string name,
EdgeTxIcon icon) :
Page(icon, PAD_ZERO)
{
textViewer = new TextViewer(path, name);
header->setTitle(name);
delayLoad();
};
void ViewTextWindow::delayedInit()
{
textViewer->build(body);
}
void ViewTextWindow::onCancel()
{
if (textViewer) delete textViewer;
Page::onCancel();
checkListOpen = false;
}
void ViewTextWindow::onEvent(event_t event) void ViewTextWindow::onEvent(event_t event)
{ {
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
if (int(bufSize) < fileLength) { if (textViewer) textViewer->onEvent(event);
TRACE("BEFORE offset=%d", offset);
if (event == EVT_KEY_BREAK(KEY_PAGEDN)) {
offset += bufSize;
TRACE("event=DOWN");
}
if (event == EVT_KEY_BREAK(KEY_PAGEUP)) {
TRACE("event=UP");
offset -= bufSize;
}
offset = std::max(offset, 0);
offset = std::min(offset, fileLength - (int)bufSize);
TRACE("AFTER offset=%d", offset);
sdReadTextFileBlock(bufSize, offset);
lv_label_set_text_static(lb, buffer);
}
if (event == EVT_KEY_BREAK(KEY_EXIT)) onCancel(); if (event == EVT_KEY_BREAK(KEY_EXIT)) onCancel();
#endif #endif
} }
class ViewChecklistWindow : public ViewTextWindow class ViewChecklistWindow : public Page, public TextViewer
{ {
public: public:
ViewChecklistWindow(const std::string path, const std::string name, ViewChecklistWindow(const std::string path, const std::string name,
EdgeTxIcon icon) : EdgeTxIcon icon) :
ViewTextWindow(path, name, icon) Page(icon, PAD_ZERO), TextViewer(path, name)
{ {
header->setTitle(g_model.header.name); header->setTitle(g_model.header.name);
header->setTitle2(STR_PREFLIGHT); header->setTitle2(STR_PREFLIGHT);
fullPath = path + std::string(PATH_SEPARATOR) + name;
extractNameSansExt();
delayLoad();
}
void delayedInit() override
{
if (buffer == nullptr) buildBody(body);
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
@@ -267,7 +305,10 @@ class ViewChecklistWindow : public ViewTextWindow
void onCancel() override void onCancel() override
{ {
if (allChecked()) ViewTextWindow::onCancel(); if (allChecked()) {
Page::onCancel();
checkListOpen = false;
}
} }
protected: protected:
@@ -330,7 +371,7 @@ class ViewChecklistWindow : public ViewTextWindow
if (vtw) vtw->updateCheckboxes(); if (vtw) vtw->updateCheckboxes();
} }
void buildBody(Window* window) override void buildBody(Window* window)
{ {
if (openFile()) { if (openFile()) {
auto obj = window->getLvObj(); auto obj = window->getLvObj();
@@ -456,9 +497,10 @@ static std::string getModelNotesFile()
return std::string(""); return std::string("");
} }
static bool openNotes(std::string modelNotesName, void readModelNotes(bool fromMenu)
bool fromMenu = false)
{ {
std::string modelNotesName = getModelNotesFile();
if (!modelNotesName.empty()) {
std::string fullPath = std::string(MODELS_PATH) + PATH_SEPARATOR + modelNotesName; std::string fullPath = std::string(MODELS_PATH) + PATH_SEPARATOR + modelNotesName;
if (isFileAvailable(fullPath.c_str())) { if (isFileAvailable(fullPath.c_str())) {
@@ -466,18 +508,9 @@ static bool openNotes(std::string modelNotesName,
new ViewTextWindow(std::string(MODELS_PATH), modelNotesName, ICON_MODEL); new ViewTextWindow(std::string(MODELS_PATH), modelNotesName, ICON_MODEL);
else else
new ViewChecklistWindow(std::string(MODELS_PATH), modelNotesName, ICON_MODEL); new ViewChecklistWindow(std::string(MODELS_PATH), modelNotesName, ICON_MODEL);
return true;
} else { } else {
return false;
} }
} }
void readModelNotes(bool fromMenu)
{
std::string modelNotesName = getModelNotesFile();
if (!modelNotesName.empty()) {
openNotes(modelNotesName, fromMenu);
}
} }
class CheckListDialog : public FullScreenDialog class CheckListDialog : public FullScreenDialog
@@ -500,8 +533,10 @@ class CheckListDialog : public FullScreenDialog
bool warningInactive() bool warningInactive()
{ {
if (!checkListOpen) if (!checkListOpen) {
LED_ERROR_END(); LED_ERROR_END();
deleteLater();
}
return !checkListOpen; return !checkListOpen;
} }
}; };
@@ -515,3 +550,19 @@ void readChecklist()
dialog->runForever(); dialog->runForever();
} }
} }
ModelNotesPage::ModelNotesPage(PageDef& pageDef) : PageGroupItem(pageDef, PAD_ZERO)
{
}
void ModelNotesPage::build(Window* window)
{
if (!textViewer) textViewer = new TextViewer(MODELS_PATH, getModelNotesFile());
if (textViewer) textViewer->build(window);
}
void ModelNotesPage::cleanup()
{
if (textViewer) delete textViewer;
textViewer = nullptr;
}
+21 -27
View File
@@ -20,8 +20,11 @@
#pragma once #pragma once
#include "ff.h"
#include "page.h" #include "page.h"
#include "pagegroup.h"
#include "gui_common.h"
class TextViewer;
class ViewTextWindow : public Page class ViewTextWindow : public Page
{ {
@@ -32,42 +35,33 @@ class ViewTextWindow : public Page
FRESULT sdReadTextFileBlock(const uint32_t bufSize, FRESULT sdReadTextFileBlock(const uint32_t bufSize,
const uint32_t offset); const uint32_t offset);
~ViewTextWindow()
{
if (buffer) {
free(buffer);
buffer = nullptr;
}
}
void onCancel() override; void onCancel() override;
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override { return "ViewTextWindow"; }; std::string getName() const override { return "ViewTextWindow"; };
#endif #endif
void delayedInit() override;
protected: protected:
std::string path; TextViewer* textViewer = nullptr;
std::string name;
std::string fullPath;
std::string extension;
lv_obj_t* lb;
int offset = 0;
char* buffer = nullptr;
size_t bufSize = 0;
int fileLength = 0;
bool openFromEnd;
void extractNameSansExt(void);
virtual void buildBody(Window* window);
bool openFile();
void onEvent(event_t event) override; void onEvent(event_t event) override;
};
void delayedInit() override; class ModelNotesPage : public PageGroupItem
{
public:
ModelNotesPage(PageDef& pageDef);
bool isVisible() const override { return modelHasNotes(); }
void build(Window* window) override;
void cleanup() override;
protected:
TextViewer* textViewer = nullptr;
}; };
void readModelNotes(bool fromMenu = false); void readModelNotes(bool fromMenu = false);
@@ -33,6 +33,7 @@
#include "model_setup.h" #include "model_setup.h"
#include "model_telemetry.h" #include "model_telemetry.h"
#include "special_functions.h" #include "special_functions.h"
#include "view_text.h"
PageDef modelMenuItems[] = { PageDef modelMenuItems[] = {
{ ICON_MODEL_SETUP, STR_QM_GEN_SETTINGS, STR_MAIN_MENU_SETTINGS, PAGE_CREATE, QuickMenu::MODEL_SETUP, [](PageDef& pageDef) { return new ModelSetupPage(pageDef); }}, { ICON_MODEL_SETUP, STR_QM_GEN_SETTINGS, STR_MAIN_MENU_SETTINGS, PAGE_CREATE, QuickMenu::MODEL_SETUP, [](PageDef& pageDef) { return new ModelSetupPage(pageDef); }},
@@ -52,5 +53,6 @@ PageDef modelMenuItems[] = {
{ ICON_MODEL_LUA_SCRIPTS, STR_QM_CUSTOM_LUA, STR_MENUCUSTOMSCRIPTS, PAGE_CREATE, QuickMenu::MODEL_SCRIPTS, [](PageDef& pageDef) { return new ModelMixerScriptsPage(pageDef); }, modelCustomScriptsEnabled}, { ICON_MODEL_LUA_SCRIPTS, STR_QM_CUSTOM_LUA, STR_MENUCUSTOMSCRIPTS, PAGE_CREATE, QuickMenu::MODEL_SCRIPTS, [](PageDef& pageDef) { return new ModelMixerScriptsPage(pageDef); }, modelCustomScriptsEnabled},
#endif #endif
{ ICON_MODEL_TELEMETRY, STR_QM_TELEM, STR_MENUTELEMETRY, PAGE_CREATE, QuickMenu::MODEL_TELEMETRY, [](PageDef& pageDef) { return new ModelTelemetryPage(pageDef); }, modelTelemetryEnabled}, { ICON_MODEL_TELEMETRY, STR_QM_TELEM, STR_MENUTELEMETRY, PAGE_CREATE, QuickMenu::MODEL_TELEMETRY, [](PageDef& pageDef) { return new ModelTelemetryPage(pageDef); }, modelTelemetryEnabled},
{ ICON_MODEL_NOTES, STR_MAIN_MENU_MODEL_NOTES, STR_MAIN_MENU_MODEL_NOTES, PAGE_CREATE, QuickMenu::MODEL_NOTES, [](PageDef& pageDef) { return new ModelNotesPage(pageDef); }, modelHasNotes},
{ EDGETX_ICONS_COUNT } { EDGETX_ICONS_COUNT }
}; };
@@ -25,7 +25,6 @@
#include "edgetx.h" #include "edgetx.h"
#include "quick_menu_group.h" #include "quick_menu_group.h"
#include "etx_lv_theme.h" #include "etx_lv_theme.h"
#include "view_text.h"
#include "view_main.h" #include "view_main.h"
#include "screen_setup.h" #include "screen_setup.h"
#include "theme_manager.h" #include "theme_manager.h"
@@ -245,16 +244,6 @@ QuickMenu::QuickMenu() :
sub = new QuickSubMenu(box, this, ICON_RADIO_TOOLS, STR_QM_TOOLS, STR_QM_TOOLS, toolsMenuItems); sub = new QuickSubMenu(box, this, ICON_RADIO_TOOLS, STR_QM_TOOLS, STR_QM_TOOLS, toolsMenuItems);
sub->addButton(); sub->addButton();
subMenus.emplace_back(sub); subMenus.emplace_back(sub);
mainMenu->addButton(ICON_MODEL_NOTES, STR_MAIN_MENU_MODEL_NOTES,
[=]() -> uint8_t {
onSelect(true);
readModelNotes(true);
return 0;
},
[=]() -> bool {
return modelHasNotes();
});
} }
void QuickMenu::deleteLater(bool detach, bool trash) void QuickMenu::deleteLater(bool detach, bool trash)
@@ -288,7 +277,7 @@ void QuickMenu::openQM(std::function<void()> cancelHandler,
setFocus(curPage); setFocus(curPage);
} else { } else {
pageGroup = nullptr; pageGroup = nullptr;
if (curPage > QuickMenu::MANAGE_MODELS) { if (curPage >= QuickMenu::FIRST_SUB_MENU_ITEM) {
mainMenu->setDisabled(false); mainMenu->setDisabled(false);
mainMenu->clearFocus(); mainMenu->clearFocus();
setFocus(curPage); setFocus(curPage);
@@ -45,8 +45,9 @@ class QuickMenu : public NavWindow
enum SubMenu { enum SubMenu {
NONE = 0, NONE = 0,
MANAGE_MODELS, MANAGE_MODELS,
FIRST_SUB_MENU_ITEM,
// Model menu // Model menu
MODEL_SETUP, MODEL_SETUP = FIRST_SUB_MENU_ITEM,
MODEL_HELI, MODEL_HELI,
MODEL_FLIGHTMODES, MODEL_FLIGHTMODES,
MODEL_INPUTS, MODEL_INPUTS,
@@ -58,6 +59,7 @@ class QuickMenu : public NavWindow
MODEL_SF, MODEL_SF,
MODEL_SCRIPTS, MODEL_SCRIPTS,
MODEL_TELEMETRY, MODEL_TELEMETRY,
MODEL_NOTES,
// Radio menu // Radio menu
RADIO_SETUP, RADIO_SETUP,
RADIO_GF, RADIO_GF,