From acea92b0deaa0a0dafe23eb7239f8fedd4a883ac Mon Sep 17 00:00:00 2001 From: stli Date: Sat, 11 Apr 2026 09:46:45 +0800 Subject: [PATCH] Connect APP shell to logic --- KeyBorad/KeyBorad/APP/AppMainWindow.cpp | 27 ++++++++ KeyBorad/KeyBorad/APP/AppMainWindow.h | 8 +++ KeyBorad/KeyBorad/KeyBorad.vcxproj | 14 +++- KeyBorad/KeyBorad/KeyBorad.vcxproj.filters | 30 ++++++++ KeyBorad/KeyBorad/main.cpp | 18 ++--- docs/host_app_rebuild.md | 81 ++++++++++++++++++++++ 6 files changed, 164 insertions(+), 14 deletions(-) create mode 100644 docs/host_app_rebuild.md diff --git a/KeyBorad/KeyBorad/APP/AppMainWindow.cpp b/KeyBorad/KeyBorad/APP/AppMainWindow.cpp index 0bcc897..b91ba6d 100644 --- a/KeyBorad/KeyBorad/APP/AppMainWindow.cpp +++ b/KeyBorad/KeyBorad/APP/AppMainWindow.cpp @@ -5,6 +5,7 @@ #include "APP/AppTheme.h" #include +#include #include namespace APP @@ -29,6 +30,32 @@ App_MainWindow::App_MainWindow(QWidget* p_Parent) appTabWidget->addTab(appSettingsPage, QStringLiteral("Settings")); p_RootLayout->addWidget(appTabWidget); + + appPollTimer = new QTimer(this); + connect(appPollTimer, &QTimer::timeout, this, [this]() + { + if (Lgc_Core_Poll(&appLogic)) + { + App_Func_RefreshFromLogic(); + } + }); + + App_Func_StartLogic(); +} + +void App_MainWindow::App_Func_StartLogic() +{ + Lgc_Core_Init(&appLogic); + Lgc_Core_Start(&appLogic); + App_Func_RefreshFromLogic(); + appPollTimer->start(30); +} + +void App_MainWindow::App_Func_RefreshFromLogic() +{ + const Lgc_State& State = Lgc_Core_GetState(&appLogic); + appSettingsPage->App_Func_SetConnectionText(State.ConnectionText); + appSettingsPage->App_Func_SetLastActionText(State.LastActionText); } App_KeyboardPage* App_MainWindow::App_Func_GetKeyboardPage() const diff --git a/KeyBorad/KeyBorad/APP/AppMainWindow.h b/KeyBorad/KeyBorad/APP/AppMainWindow.h index 6907c05..28d9c90 100644 --- a/KeyBorad/KeyBorad/APP/AppMainWindow.h +++ b/KeyBorad/KeyBorad/APP/AppMainWindow.h @@ -1,8 +1,11 @@ #pragma once +#include "LOGIC/Lgc_Core.h" + #include class QTabWidget; +class QTimer; namespace APP { @@ -19,9 +22,14 @@ public: App_SettingsPage* App_Func_GetSettingsPage() const; private: + void App_Func_StartLogic(); + void App_Func_RefreshFromLogic(); + QTabWidget* appTabWidget = nullptr; App_KeyboardPage* appKeyboardPage = nullptr; App_SettingsPage* appSettingsPage = nullptr; + QTimer* appPollTimer = nullptr; + Lgc_Core appLogic; }; } // namespace APP diff --git a/KeyBorad/KeyBorad/KeyBorad.vcxproj b/KeyBorad/KeyBorad/KeyBorad.vcxproj index 0aa0a86..0f762ce 100644 --- a/KeyBorad/KeyBorad/KeyBorad.vcxproj +++ b/KeyBorad/KeyBorad/KeyBorad.vcxproj @@ -37,12 +37,12 @@ D:\App\Qt\5.13.1\msvc2015_64 - core;serialport + core;serialport;widgets debug D:\App\Qt\5.13.1\msvc2015_64 - core;serialport + core;serialport;widgets release @@ -94,6 +94,14 @@ + + + + + + + + @@ -108,6 +116,8 @@ + + diff --git a/KeyBorad/KeyBorad/KeyBorad.vcxproj.filters b/KeyBorad/KeyBorad/KeyBorad.vcxproj.filters index fbe6f25..216e141 100644 --- a/KeyBorad/KeyBorad/KeyBorad.vcxproj.filters +++ b/KeyBorad/KeyBorad/KeyBorad.vcxproj.filters @@ -23,6 +23,30 @@ + + Source Files + + + Header Files + + + Source Files + + + Header Files + + + Source Files + + + Header Files + + + Source Files + + + Header Files + Header Files @@ -65,6 +89,12 @@ Header Files + + Source Files + + + Header Files + Source Files diff --git a/KeyBorad/KeyBorad/main.cpp b/KeyBorad/KeyBorad/main.cpp index 20b7836..23dd873 100644 --- a/KeyBorad/KeyBorad/main.cpp +++ b/KeyBorad/KeyBorad/main.cpp @@ -1,19 +1,13 @@ -#include -#include +#include -#include "DRI/Dri_Cdc.h" +#include "APP/AppMainWindow.h" int main(int argc, char *argv[]) { - QCoreApplication app(argc, argv); + QApplication App(argc, argv); - Dri_Cdc_Struct_Port Port; - Dri_Cdc_Struct_InitConfig Config; - Config.BaudRate = 115200; + APP::App_MainWindow Window; + Window.show(); - const bool IsInitOk = Dri_Cdc_Init(&Port, Config); - qDebug() << "Dri_Cdc_Init =" << IsInitOk; - - Dri_Cdc_Deinit(&Port); - return 0; + return App.exec(); } diff --git a/docs/host_app_rebuild.md b/docs/host_app_rebuild.md new file mode 100644 index 0000000..28e20df --- /dev/null +++ b/docs/host_app_rebuild.md @@ -0,0 +1,81 @@ +# Host APP Rebuild + +## Goal + +Keep the APP layer suitable for teaching from simple to complex. + +Teaching order: + +1. one button +2. one keyboard page +3. two pages +4. one main window +5. one shared theme + +## Completed Nodes + +### Node 1: theme helpers + +Files: + +- `KeyBorad/KeyBorad/APP/AppTheme.h` +- `KeyBorad/KeyBorad/APP/AppTheme.cpp` + +Design notes: + +- centralize colors and style strings +- keep styling readable +- avoid mixing style text inside every widget + +### Node 2: key button + +Files: + +- `KeyBorad/KeyBorad/APP/AppKeyButton.h` +- `KeyBorad/KeyBorad/APP/AppKeyButton.cpp` + +Design notes: + +- teach one custom button first +- keep state changes explicit +- let one widget own its own text and style refresh + +### Node 3: keyboard page + +Files: + +- `KeyBorad/KeyBorad/APP/AppKeyboardPage.h` +- `KeyBorad/KeyBorad/APP/AppKeyboardPage.cpp` + +Design notes: + +- grow from one button to a full keypad +- keep layout data local and explicit + +### Node 4: settings page + +Files: + +- `KeyBorad/KeyBorad/APP/AppSettingsPage.h` +- `KeyBorad/KeyBorad/APP/AppSettingsPage.cpp` + +Design notes: + +- use a second page early +- give transport status and action feedback one simple home + +### Node 5: main window integration + +Files updated in this step: + +- `KeyBorad/KeyBorad/APP/AppMainWindow.h` +- `KeyBorad/KeyBorad/APP/AppMainWindow.cpp` +- `KeyBorad/KeyBorad/main.cpp` + +Implemented behavior: + +- create the two-page window +- own one `Lgc_Core` +- start handshake on launch +- poll the logic layer with a timer +- refresh settings page texts from logic state