Browse Source

实现手柄绑定程序

sunlight
zhaohe 11 months ago
parent
commit
d89148c5a9
  1. 2
      uappbase/bean/config_index_enum.hpp
  2. 2
      uappbase/bean/event.hpp
  3. 2
      uappbase/service/config_index.cpp
  4. 2
      uappbase/service/config_index.hpp
  5. 1
      usrc/project_configs.h
  6. 20
      usrc/service/app_core.cpp
  7. 37
      usrc/service/page/submenu/Page_muSettings.cpp
  8. 1
      usrc/service/page/submenu/Page_muSettings.hpp
  9. 9
      usrc/service/remote_controler_event_processer.cpp

2
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;

2
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;

2
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, ""), //
/***********************************************************************************************************************
* »ØÁ÷²ÎÊýÅäÖà *
***********************************************************************************************************************/

2
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);

1
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"

20
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;
}
}
}

37
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;
}
};

1
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();

9
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;
}

Loading…
Cancel
Save