From d89148c5a906d365e47dba641fb0f3f59dbb0ec6 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sat, 31 Aug 2024 23:50:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=89=8B=E6=9F=84=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uappbase/bean/config_index_enum.hpp | 2 ++ uappbase/bean/event.hpp | 2 ++ uappbase/service/config_index.cpp | 2 ++ uappbase/service/config_index.hpp | 2 +- usrc/project_configs.h | 1 + usrc/service/app_core.cpp | 20 +++++++++--- usrc/service/page/submenu/Page_muSettings.cpp | 37 ++++++++++++++++++++++- usrc/service/page/submenu/Page_muSettings.hpp | 1 + usrc/service/remote_controler_event_processer.cpp | 9 +++++- 9 files changed, 68 insertions(+), 8 deletions(-) diff --git a/uappbase/bean/config_index_enum.hpp b/uappbase/bean/config_index_enum.hpp index 94a0988..7cb5c21 100644 --- a/uappbase/bean/config_index_enum.hpp +++ b/uappbase/bean/config_index_enum.hpp @@ -86,6 +86,8 @@ typedef enum { kcfg_m2irun, // 电机2 irun kcfg_m3irun, // 电机3 irun + kcfg_bleClientName, + kcfg_max, } config_index_t; diff --git a/uappbase/bean/event.hpp b/uappbase/bean/event.hpp index 1db552f..b068511 100644 --- a/uappbase/bean/event.hpp +++ b/uappbase/bean/event.hpp @@ -11,6 +11,7 @@ typedef enum { kAppEvent_RemoterConnectStateChangeEvent, kAppEvent_PumpWorkStateChangeEvent, kAppEvent_ConfigChangeEvent, + kAppEvent_BleConnectEvent, } AppEventType_t; /** @@ -26,6 +27,7 @@ typedef struct { union event { uint32_t placeholder; config_index_t configIndex; + char bleName[20]; } d; } AppEvent_t; diff --git a/uappbase/service/config_index.cpp b/uappbase/service/config_index.cpp index 16de9aa..70946cb 100644 --- a/uappbase/service/config_index.cpp +++ b/uappbase/service/config_index.cpp @@ -88,6 +88,8 @@ static cfg_iterm_info_t cfg_iterm_infos[] = { CFG_ITERM(kcfg_m2irun, kcfgt_int32, "20"), // CFG_ITERM(kcfg_m3irun, kcfgt_int32, "20"), // + CFG_ITERM(kcfg_bleClientName, kcfgt_str, ""), // + /*********************************************************************************************************************** * 回流参数配置 * ***********************************************************************************************************************/ diff --git a/uappbase/service/config_index.hpp b/uappbase/service/config_index.hpp index b9c039d..3a2d693 100644 --- a/uappbase/service/config_index.hpp +++ b/uappbase/service/config_index.hpp @@ -28,7 +28,7 @@ typedef struct { const char *initval; } cfg_iterm_info_t; -#define CFG_MAX_INDEX 54 +#define CFG_MAX_INDEX 55 const char *cfgName(int32_t index); cfg_iterm_type_t cfgType(int32_t index); diff --git a/usrc/project_configs.h b/usrc/project_configs.h index b0604b4..2b064b1 100644 --- a/usrc/project_configs.h +++ b/usrc/project_configs.h @@ -20,3 +20,4 @@ #define HARDWARE_VERSION 1 // 硬件版本 #define PROJECT "hand_acid_main_board" // 工程名称 #define APP_VERSION "101" +#define BLENAME "AciDisp" \ No newline at end of file diff --git a/usrc/service/app_core.cpp b/usrc/service/app_core.cpp index f4dee0f..935583e 100644 --- a/usrc/service/app_core.cpp +++ b/usrc/service/app_core.cpp @@ -112,11 +112,21 @@ void AppCore::appsetup() { UIS->chpage(pg_login); osDelay(100); - for (size_t i = 0;; i++) { - if (i != 0) ZLOGI(TAG, "re start scan %s %d", "AciDisp00000", i); - bool suc = RCTRL->startScan("AciDisp00000", true); - if (suc) { - break; + CfgItermCache bleNameCache; + const char* bleName = CS->getStr(kcfg_bleClientName, &bleNameCache); + if (strlen(bleName) != 0) { + ZLOGI(TAG, "start scan :%s", bleName); + for (size_t i = 0;; i++) { + if (i != 0) ZLOGI(TAG, "re start scan %s %d", bleName, i); + bool suc = RCTRL->startScan(bleName, true); + if (suc) break; + } + } else { + ZLOGI(TAG, "start scan %s", "XXXXXXXXX"); + for (size_t i = 0;; i++) { + if (i != 0) ZLOGI(TAG, "re start scan %s %d", "XXXXXXXX", i); + bool suc = RCTRL->startScan("XXXXXXXXX", false); // 输入一个错误的设备名,当作不扫描 + if (suc) break; } } } diff --git a/usrc/service/page/submenu/Page_muSettings.cpp b/usrc/service/page/submenu/Page_muSettings.cpp index 549a496..a04735d 100644 --- a/usrc/service/page/submenu/Page_muSettings.cpp +++ b/usrc/service/page/submenu/Page_muSettings.cpp @@ -1,4 +1,6 @@ #include "Page_muSettings.hpp" + +#include "service/remote_controler.hpp" using namespace iflytop; /** @@ -10,10 +12,28 @@ using namespace iflytop; #define TAG "Page_muSettings" static CfgItermCache cfgcache; +static bool m_scaning; + +// RCTRL->regOnReport([this](uint8_t* rx, int32_t len) { +// zble_proto_packet_t* packet = (zble_proto_packet_t*)rx; +// logevent(rx, len); +// if (packet->cmd == kzble_app_report_key_event) { +// int32_t keyEvent = *(int32_t*)packet->data; +// processKeyEventFromRemoter((hand_acid_remoter_key_event_t)keyEvent); +// return; +// } + +// if (packet->cmd == kzble_report_connected_event) { +// GSM->setRemoterS(true); +// } else if (packet->cmd == kzble_report_disconnect_event) { +// GSM->setRemoterS(false); +// } +// }); + bool Page_muSettings::isBelongThisPage(int page) { return page == PAGE; } void Page_muSettings::updatePage() { - UIS->setVal(PAGE, ob_muSettings_bleCliName, "testData"); + UIS->setVal(PAGE, ob_muSettings_bleCliName, getCfgStr(kcfg_bleClientName)); UIS->setVal(PAGE, ob_muSettings_irun0, zitoa(getMxIRun(0))); UIS->setVal(PAGE, ob_muSettings_irun1, zitoa(getMxIRun(1))); UIS->setVal(PAGE, ob_muSettings_irun2, zitoa(getMxIRun(2))); @@ -32,6 +52,14 @@ void Page_muSettings::updatePage() { void Page_muSettings::OnPageLoad(OnPageLoadContext* cxt) { // updatePage(); }; +void Page_muSettings::OnAppEvent(AppEvent_t* event) { + if (event->type == kAppEvent_BleConnectEvent) { + ZLOGI(TAG, "ble connect success"); + UIS->setVal(PAGE, ob_muSettings_bleCliName, "绑定成功"); + CS->setcfg(kcfg_bleClientName, event->d.bleName); + m_scaning = false; + } +} void Page_muSettings::OnInputFieldContentChange(uint8_t bid, const char* text) { /*********************************************************************************************************************** @@ -109,8 +137,15 @@ void Page_muSettings::OnButton(uint8_t bid, uint8_t val) { ZLOGI(TAG, "bid:%d", bid); if (bid == ob_muSettings_bak) { UIS->chpage(GSM->getMenuPage()); + if (m_scaning) { + RCTRL->startScan("XXXXXXXXX", false); // 相当于停止扫描 + } + } else if (bid == ob_muSettings_bleScan) { ZLOGI(TAG, "bleScan"); + bool suc = RCTRL->startScan(BLENAME, true); + if (suc) UIS->setVal(PAGE, ob_muSettings_bleCliName, "扫描中..."); + m_scaning = true; } }; diff --git a/usrc/service/page/submenu/Page_muSettings.hpp b/usrc/service/page/submenu/Page_muSettings.hpp index 7e6a286..59a194e 100644 --- a/usrc/service/page/submenu/Page_muSettings.hpp +++ b/usrc/service/page/submenu/Page_muSettings.hpp @@ -20,6 +20,7 @@ class Page_muSettings : public IPageProcesser { virtual void OnPageLoad(OnPageLoadContext*cxt) override; virtual void OnInputFieldContentChange(uint8_t bid, const char* text) override; virtual void OnButton(uint8_t bid, uint8_t val) override; + virtual void OnAppEvent(AppEvent_t* event) override; private: void updatePage(); diff --git a/usrc/service/remote_controler_event_processer.cpp b/usrc/service/remote_controler_event_processer.cpp index a5f3936..0caf521 100644 --- a/usrc/service/remote_controler_event_processer.cpp +++ b/usrc/service/remote_controler_event_processer.cpp @@ -23,6 +23,7 @@ void RemoteControlerEventProcesser::initialize() { RCTRL->regOnReport([this](uint8_t* rx, int32_t len) { zble_proto_packet_t* packet = (zble_proto_packet_t*)rx; logevent(rx, len); + if (packet->cmd == kzble_app_report_key_event) { int32_t keyEvent = *(int32_t*)packet->data; processKeyEventFromRemoter((hand_acid_remoter_key_event_t)keyEvent); @@ -30,7 +31,12 @@ void RemoteControlerEventProcesser::initialize() { } if (packet->cmd == kzble_report_connected_event) { + zble_connected_event_t* event = (zble_connected_event_t*)packet->data; GSM->setRemoterS(true); + AppEvent_t appevent; + appevent.type = kAppEvent_BleConnectEvent; + strncpy(appevent.d.bleName, event->blename, sizeof(appevent.d.bleName)); + AppEventBus::ins()->pushEvent(appevent); } else if (packet->cmd == kzble_report_disconnect_event) { GSM->setRemoterS(false); } @@ -87,7 +93,8 @@ void RemoteControlerEventProcesser::processKeyEventFromRemoter(hand_acid_remoter ZLOGW(TAG, "now page is in pump test, remote key event process by pumpTestPage"); return; } - if (UIS->getNowPage() == pg_login || UIS->getNowPage() == pg_pStart) { + + if (UIS->getNowPage() == pg_login || UIS->getNowPage() == pg_pStart || UIS->getNowPage() == pg_muSettings) { return; }