From 9f9e64482f0efe73de41793258a26f61760d1cce Mon Sep 17 00:00:00 2001 From: zhaohe Date: Thu, 28 Nov 2024 15:54:41 +0800 Subject: [PATCH] update --- uappbase/bean/appevent.hpp | 15 +++++++++------ uappbase/service/app_event_bus.cpp | 14 ++++++++++++++ uappbase/service/app_event_bus.hpp | 8 ++++---- usrc/service/app_core.cpp | 2 ++ usrc/service/statistics_sync_service.cpp | 2 ++ usrc/uicontroler/ui_controler.cpp | 9 ++++----- usrc/uicontroler/ui_controler.hpp | 5 +++-- 7 files changed, 38 insertions(+), 17 deletions(-) diff --git a/uappbase/bean/appevent.hpp b/uappbase/bean/appevent.hpp index a7ec0b6..e652293 100644 --- a/uappbase/bean/appevent.hpp +++ b/uappbase/bean/appevent.hpp @@ -21,7 +21,10 @@ class AppEvent { public: AppEventType_t type; std::function onfnc = nullptr; - uint8_t buf[sizeof(UIEvent) + 10]; + + private: + uint8_t buf[50]; + UIEvent* uieventpointer = nullptr; public: AppEvent() { memset(buf, 0, sizeof(buf)); } @@ -29,18 +32,18 @@ class AppEvent { public: int getBufSize() { return sizeof(buf); } - void setBleName(const char* name) { strcpy((char*)buf, name); } + void setBleName(const char* name) { strncpy((char*)buf, name, sizeof(buf)); } char* getBleName() { return (char*)buf; } - UIEvent* getUIEvent() { return (UIEvent*)buf; } - void setUIEvent(const UIEvent& event) { memcpy(buf, &event, sizeof(UIEvent)); } - void setPageChangeTo(int32_t page) { *(int32_t*)buf = page; } int32_t getPageChangeTo() { return *(int32_t*)buf; } - void setStateDisplayInfo(const char* info) { strcpy((char*)buf, info); } + void setStateDisplayInfo(const char* info) { strncpy((char*)buf, info, sizeof(buf)); } char* getStateDisplayInfo() { return (char*)buf; } + UIEvent* getUIEvent() { return uieventpointer; } + void setUIEvent(UIEvent* event) { uieventpointer = event; } + AcidStateChangeEvent_t* getAcidStateChangeEvent() { return (AcidStateChangeEvent_t*)buf; } void setOnFnc(std::function fnc) { onfnc = fnc; } diff --git a/uappbase/service/app_event_bus.cpp b/uappbase/service/app_event_bus.cpp index f16d89d..83f03ba 100644 --- a/uappbase/service/app_event_bus.cpp +++ b/uappbase/service/app_event_bus.cpp @@ -54,6 +54,20 @@ void AppEventBus::pushEvent(const AppEvent& event) { } } +void AppEventBus::pushEventBlock(AppEvent* event) { + bool evenProcessed = false; + callFnInEventBus([&]() { + for (int i = 0; i < cbNum; i++) { + m_cbs[i](event); + } + evenProcessed = true; + }); + + while (!evenProcessed) { + osDelay(30); + } +} + void AppEventBus::pushSimpleEvent(AppEventType_t type) { zlock_guard lck(lock); eventtxcache.type = type; diff --git a/uappbase/service/app_event_bus.hpp b/uappbase/service/app_event_bus.hpp index 864c985..b69a1b7 100644 --- a/uappbase/service/app_event_bus.hpp +++ b/uappbase/service/app_event_bus.hpp @@ -28,16 +28,16 @@ class AppEventBus { void regOnEvent(onAppEventCB_t onEvent); void pushEvent(const AppEvent& event); void pushSimpleEvent(AppEventType_t type); - void pushPageChangeEvent(uint8_t toPage); - void callFnInEventBus(function onfnc); - void pushStateDisplayInfoEvent(const char* info); - void pushAcidStatUseEvent(float ch1, float ch2, float ch3, float ch4); void pushAcidStatStorageEvent(uint8_t ch, float chVal); void pushAcidStatDisplayChangeEvent(); + void pushEventBlock(AppEvent* event); + + // + void callFnInEventBus(function onfnc); bool isInAppEventThread(); }; diff --git a/usrc/service/app_core.cpp b/usrc/service/app_core.cpp index 43750ee..8f60b0b 100644 --- a/usrc/service/app_core.cpp +++ b/usrc/service/app_core.cpp @@ -7,6 +7,7 @@ #include "service/pump_ctrl_service.hpp" #include "service/remote_controler.hpp" #include "service/remote_controler_state_sync_service.hpp" +#include "service/statistics_sync_service.hpp" #include "valve_state_ctrl_service.hpp" // #include "ucomponents/zcan/zcan.hpp" @@ -127,6 +128,7 @@ void AppCore::initialize() { ValveStateSyncService::ins()->initialize(ZCAN1::ins()); // 阀门状态同步服务初始化 PumpCtrlService::ins()->initialize(); // 泵控制服务初始化 RemoteControlerStateSyncService::ins()->initialize(); // 遥控器状态同步服务初始化 + StatisticsSyncService::initialize(); // UI初始化 UIControler::ins()->initialize(); diff --git a/usrc/service/statistics_sync_service.cpp b/usrc/service/statistics_sync_service.cpp index 893445e..9d39772 100644 --- a/usrc/service/statistics_sync_service.cpp +++ b/usrc/service/statistics_sync_service.cpp @@ -122,6 +122,7 @@ void StatisticsSyncService::onAddAcidStorage(int ch, float addChVal) { */ GStateMgr::ins()->setAcidRemain(ch, addChVal); DeviceAcidVolume::updateAcidVolumeSync(ch, addChVal); + AppEventBus::ins()->pushAcidStatDisplayChangeEvent(); } void StatisticsSyncService::onUseAcid(float useVal0, float useVal1, float useVal2, float useVal3) { float now0 = GStateMgr::ins()->getAcidUsed(0); @@ -136,6 +137,7 @@ void StatisticsSyncService::onUseAcid(float useVal0, float useVal1, float useVal AcidUseRecordDao::updateLastRecord(now0 + useVal0, now1 + useVal1, now2 + useVal2, now3 + useVal3); m_dataIsDirty = true; + AppEventBus::ins()->pushAcidStatDisplayChangeEvent(); } static void syncTimer(const void* tid) { diff --git a/usrc/uicontroler/ui_controler.cpp b/usrc/uicontroler/ui_controler.cpp index a61a5d3..0ce15fd 100644 --- a/usrc/uicontroler/ui_controler.cpp +++ b/usrc/uicontroler/ui_controler.cpp @@ -68,8 +68,9 @@ void UIControler::pageInitialize() { UIControlerHock_PageInit(); } void UIControler::callUsrEventCb(UIEvent* event) { static AppEvent appEvent; appEvent.type = KAE_UIEvent; - memcpy(appEvent.getUIEvent(), event, sizeof(UIEvent)); - AppEventBus::ins()->pushEvent(appEvent); + appEvent.setUIEvent(event); + + AppEventBus::ins()->pushEventBlock(&appEvent); } void UIControler::startSchedule() { @@ -482,9 +483,7 @@ void UIControler::popPasswdKeyBoard(uint8_t fromPid, uint8_t fromBid, int limitL chpage(pg_keyPasswd, false); } - - -void UIControler::popNumKeyBoard(uint8_t fromPid, uint8_t fromBid, int limitLength, const char* initval,...) { +void UIControler::popNumKeyBoard(uint8_t fromPid, uint8_t fromBid, int limitLength, const char* initval, ...) { zlock_guard lg(m_cmdlock); static char buf[60]; diff --git a/usrc/uicontroler/ui_controler.hpp b/usrc/uicontroler/ui_controler.hpp index 59153bc..8668c13 100644 --- a/usrc/uicontroler/ui_controler.hpp +++ b/usrc/uicontroler/ui_controler.hpp @@ -16,7 +16,6 @@ typedef struct { uint16_t datalen; } tjc_rx_packet_t; - #define UIS UIControler::ins() class UIControler { ZThread m_thread; @@ -99,7 +98,7 @@ class UIControler { void popFullKeyBoard(uint8_t fromPid, uint8_t fromBid, int limitLength, const char* initval); void popPasswdKeyBoard(uint8_t fromPid, uint8_t fromBid, int limitLength); - void popNumKeyBoard(uint8_t fromPid, uint8_t fromBid, int limitLength, const char* initval,...); + void popNumKeyBoard(uint8_t fromPid, uint8_t fromBid, int limitLength, const char* initval, ...); void popKeyBMutSel(uint8_t fromPid, uint8_t fromBid, int selectvalindex, const char** selectvals); void popKeyBMutSel(uint8_t fromPid, uint8_t fromBid, int selectvalindex, const char* selectvals); @@ -126,6 +125,8 @@ class UIControler { private: bool vis(uint16_t bid, int32_t val); // 不支持跨页面隐藏 void setTouchEnableState(uint8_t bid, uint8_t enable); // 不支持跨页面隐藏 + + void placeHolder() {} }; class UILoadingCxt {