diff --git a/stm32components b/stm32components index cc5597a..c955b97 160000 --- a/stm32components +++ b/stm32components @@ -1 +1 @@ -Subproject commit cc5597a95943486264bea7f036a06790e0bbcdf3 +Subproject commit c955b971d3fc803929f014f0cf3b0f9257eda65b diff --git a/uappbase/bean/dbtype/user.hpp b/uappbase/bean/dbtype/user.hpp index 3e3458e..b8bcac0 100644 --- a/uappbase/bean/dbtype/user.hpp +++ b/uappbase/bean/dbtype/user.hpp @@ -6,12 +6,12 @@ namespace iflytop { typedef struct { - uint8_t id; - char name[MAX_USR_NAME_SIZE]; - char passwd[6]; - uint8_t role; - bool effective; - bool builtIn; + uint32_t id; + char name[MAX_USR_NAME_SIZE]; + char passwd[6]; + uint8_t role; + bool effective; + bool builtIn; } user_t; } // namespace iflytop diff --git a/uappbase/bean/dbtype/user_role_enum.cpp b/uappbase/bean/dbtype/user_role_enum.cpp index cef400c..6d0732b 100644 --- a/uappbase/bean/dbtype/user_role_enum.cpp +++ b/uappbase/bean/dbtype/user_role_enum.cpp @@ -2,11 +2,11 @@ namespace iflytop { -UserRole UserRole::admin = UserRole(kadmin, "admin", "管理员"); -UserRole UserRole::storekeeper = UserRole(kstorekeeper, "storekeeper", "仓库管理员"); -UserRole UserRole::user = UserRole(kuser, "user", "用户"); +const UserRole UserRole::admin = UserRole(kadmin, "admin", "管理员"); +const UserRole UserRole::storekeeper = UserRole(kstorekeeper, "storekeeper", "仓库管理员"); +const UserRole UserRole::user = UserRole(kuser, "user", "用户"); -UserRole* UserRole::table[3] = {&admin, &storekeeper, &user}; -int UserRole::tableNum = 3; +const UserRole* UserRole::table[3] = {&admin, &storekeeper, &user}; +const int UserRole::tableNum = 3; } // namespace iflytop diff --git a/uappbase/bean/dbtype/user_role_enum.hpp b/uappbase/bean/dbtype/user_role_enum.hpp index 1950e8d..a285766 100644 --- a/uappbase/bean/dbtype/user_role_enum.hpp +++ b/uappbase/bean/dbtype/user_role_enum.hpp @@ -16,21 +16,21 @@ class UserRole : public ZEnum { UserRole(const UserRole& role) : ZEnum(role.val, role.name, role.chName) {} public: - static UserRole admin; - static UserRole storekeeper; - static UserRole user; + const static UserRole admin; + const static UserRole storekeeper; + const static UserRole user; - static UserRole* table[3]; - static int tableNum; + const static UserRole* table[3]; + const static int tableNum; - static UserRole& of(int val) { + static const UserRole* of(int val) { for (int i = 0; i < tableNum; i++) { if (table[i]->val == val) { - return *table[i]; + return table[i]; } } static UserRole unknown(-1, "unknown", "未知"); - return unknown; + return &unknown; } }; diff --git a/uappbase/zhdb/zhdb.cpp b/uappbase/zhdb/zhdb.cpp index e590d9d..ecb5d94 100644 --- a/uappbase/zhdb/zhdb.cpp +++ b/uappbase/zhdb/zhdb.cpp @@ -59,6 +59,8 @@ zhdb_table_t* ZHDB::allocTable(const char* name, size_t size) { table_add_off += size; table_num++; + ZLOGI("ZHDB", "alloc table %s add %p size %d", name, table->add, size); + return table; } void ZHDB::storageData(uint8_t* data, size_t size) { diff --git a/ui/hand_acid_mainboard_ui.HMI b/ui/hand_acid_mainboard_ui.HMI index a8100d9..00be1bb 100644 Binary files a/ui/hand_acid_mainboard_ui.HMI and b/ui/hand_acid_mainboard_ui.HMI differ diff --git a/ui/ui.h b/ui/ui.h index eab727c..786e712 100644 --- a/ui/ui.h +++ b/ui/ui.h @@ -19,6 +19,7 @@ #define pg_keybdB 17 #define pg_keybdAP 18 #define pg_keyPasswd 19 +#define pg_keybMutiSel 20 //gvar.objs #define ob_gvar_gvar 0 #define ob_gvar_edit 1 @@ -177,13 +178,14 @@ #define ob_muUsrMgr_passwd 35 #define ob_muUsrMgr_indexVal 36 #define ob_muUsrMgr_usrNameVal 37 -#define ob_muUsrMgr_roleVal 38 -#define ob_muUsrMgr_del 39 -#define ob_muUsrMgr_save 40 -#define ob_muUsrMgr_isEdited 41 -#define ob_muUsrMgr_editAreaMask 42 -#define ob_muUsrMgr_editAreaLable 43 -#define ob_muUsrMgr_passwdInfo 44 +#define ob_muUsrMgr_del 38 +#define ob_muUsrMgr_save 39 +#define ob_muUsrMgr_isEdited 40 +#define ob_muUsrMgr_editAreaLable 41 +#define ob_muUsrMgr_passwdInfo 42 +#define ob_muUsrMgr_delButMask 43 +#define ob_muUsrMgr_roleVal 44 +#define ob_muUsrMgr_editAreaMask 45 //muDateMgr.objs #define ob_muDateMgr_muDateMgr 0 #define ob_muDateMgr_year 1 @@ -582,3 +584,15 @@ #define ob_keyPasswd_loadcmname 25 #define ob_keyPasswd_m0 26 #define ob_keyPasswd_clear 27 +//keybMutiSel.objs +#define ob_keybMutiSel_keybMutiSel 0 +#define ob_keybMutiSel_loadpageid 1 +#define ob_keybMutiSel_loadcmpid 2 +#define ob_keybMutiSel_loadcmname 3 +#define ob_keybMutiSel_p0 4 +#define ob_keybMutiSel_t0 5 +#define ob_keybMutiSel_canclekey 6 +#define ob_keybMutiSel_confirmkey 7 +#define ob_keybMutiSel_frompage 8 +#define ob_keybMutiSel_title 9 +#define ob_keybMutiSel_ctent 10 diff --git a/usrc/db/dao/user_dao.cpp b/usrc/db/dao/user_dao.cpp index f8581cf..75b14fc 100644 --- a/usrc/db/dao/user_dao.cpp +++ b/usrc/db/dao/user_dao.cpp @@ -9,36 +9,51 @@ using namespace iflytop; /*********************************************************************************************************************** * MARCO * ***********************************************************************************************************************/ -#define TABLE_VERSION (TABLE_BASE_VERSION + 2) +#define TABLE_VERSION (TABLE_BASE_VERSION + 4) #define TABLE_NAME "user_table" /*********************************************************************************************************************** * STATIC VAR * ***********************************************************************************************************************/ -static zhdb_table_t* table; -static bool module_inited; -static struct { +typedef struct { uint32_t version; uint32_t maxid; user_t user[MAX_USR_NUM]; uint32_t end; -}* tabledata; +} user_table_t; + +static zhdb_table_t* table; +static bool module_inited; +static user_table_t* usr_table_data; /*********************************************************************************************************************** * FUNCTION * ***********************************************************************************************************************/ -static void storgeTableData() { ZHDB::storageData((uint8_t*)tabledata, sizeof(*tabledata)); } +static void storgeTableData() { ZHDB::storageData((uint8_t*)usr_table_data, sizeof(*usr_table_data)); } + +static void cpyUsr(user_t* dst, user_t* src) { memcpy(dst, src, sizeof(user_t)); } static void sortUsr() { + // + for (int i = 0; i < MAX_USR_NUM; i++) { + if (!usr_table_data->user[i].effective) { + usr_table_data->user[i].id = UINT32_MAX; + } + } + // 按照ID顺序排序 for (int i = 0; i < MAX_USR_NUM; i++) { for (int j = i + 1; j < MAX_USR_NUM; j++) { - if (tabledata->user[i].id > tabledata->user[j].id) { - user_t tmp = tabledata->user[i]; - tabledata->user[i] = tabledata->user[j]; - tabledata->user[j] = tmp; + if (usr_table_data->user[i].id > usr_table_data->user[j].id) { + // user_t tmp = usr_table_data->user[i]; + // usr_table_data->user[i] = usr_table_data->user[j]; + // usr_table_data->user[j] = tmp; + user_t tmp; + cpyUsr(&tmp, &usr_table_data->user[i]); + cpyUsr(&usr_table_data->user[i], &usr_table_data->user[j]); + cpyUsr(&usr_table_data->user[j], &tmp); } } } @@ -46,44 +61,44 @@ static void sortUsr() { // void UserDao::init() { // - table = ZHDB::allocTable(TABLE_NAME, sizeof(*tabledata)); + table = ZHDB::allocTable(TABLE_NAME, sizeof(*usr_table_data)); ASSERT(table != NULL, "alloc table failed"); - tabledata = (decltype(tabledata))table->add; + usr_table_data = (decltype(usr_table_data))table->add; - if (TABLE_VERSION != tabledata->version || TABLE_VERSION != tabledata->end) { + if (TABLE_VERSION != usr_table_data->version || TABLE_VERSION != usr_table_data->end) { ZLOGI(TAG, "%s table version not match, reset table", TABLE_NAME); - tabledata->version = TABLE_VERSION; - tabledata->end = TABLE_VERSION; + usr_table_data->version = TABLE_VERSION; + usr_table_data->end = TABLE_VERSION; - tabledata->maxid = 0; + usr_table_data->maxid = 0; for (int i = 0; i < MAX_USR_NUM; i++) { - tabledata->user[i].effective = false; - tabledata->user[i].id = 0; + usr_table_data->user[i].effective = false; + usr_table_data->user[i].id = 0; } // User0 默认管理员 - tabledata->user[0].id = tabledata->maxid++; - tabledata->user[0].effective = true; - strcpy(tabledata->user[0].name, "admin"); - strcpy(tabledata->user[0].passwd, "888888"); - tabledata->user[0].role = kadmin; - tabledata->user[0].builtIn = true; + usr_table_data->user[0].id = usr_table_data->maxid++; + usr_table_data->user[0].effective = true; + strcpy(usr_table_data->user[0].name, "admin"); + strcpy(usr_table_data->user[0].passwd, "888888"); + usr_table_data->user[0].role = kadmin; + usr_table_data->user[0].builtIn = true; // User1 默认仓库管理员 - // tabledata->user[1].id = tabledata->maxid++; - // tabledata->user[1].effective = true; - // strcpy(tabledata->user[1].name, "manager"); - // strcpy(tabledata->user[1].passwd, "888888"); - // tabledata->user[1].role = kstorekeeper; - // tabledata->user[1].builtIn = true; + usr_table_data->user[1].id = usr_table_data->maxid++; + usr_table_data->user[1].effective = true; + strcpy(usr_table_data->user[1].name, "manager"); + strcpy(usr_table_data->user[1].passwd, "888888"); + usr_table_data->user[1].role = kstorekeeper; + usr_table_data->user[1].builtIn = false; // User2 默认操作员 - // tabledata->user[2].id = tabledata->maxid++; - // tabledata->user[2].effective = true; - // strcpy(tabledata->user[2].name, "用户"); - // strcpy(tabledata->user[2].passwd, "888888"); - // tabledata->user[2].role = kuser; - // tabledata->user[2].builtIn = false; + usr_table_data->user[2].id = usr_table_data->maxid++; + usr_table_data->user[2].effective = true; + strcpy(usr_table_data->user[2].name, "用户"); + strcpy(usr_table_data->user[2].passwd, "888888"); + usr_table_data->user[2].role = kuser; + usr_table_data->user[2].builtIn = false; } storgeTableData(); module_inited = true; @@ -92,21 +107,21 @@ void UserDao::init() { // } void UserDao::getUsers(user_t** user, int* numUser) { - *user = tabledata->user; + *user = usr_table_data->user; int count = 0; for (int i = 0; i < MAX_USR_NUM; i++) { - if (tabledata->user[i].effective) { + if (usr_table_data->user[i].effective) { count++; } } *numUser = count; } -user_t* UserDao::getUsersTable() { return tabledata->user; } +user_t* UserDao::getUsersTable() { return usr_table_data->user; } int UserDao::getUsersTableNum() { int count = 0; for (int i = 0; i < MAX_USR_NUM; i++) { - if (tabledata->user[i].effective) { + if (usr_table_data->user[i].effective) { count++; } } @@ -116,8 +131,8 @@ int UserDao::getUsersTableNum() { user_t* UserDao::getUserByName(const char* name) { ZASSERT_INFO(module_inited, "user dao not inited"); for (int i = 0; i < MAX_USR_NUM; i++) { - if (tabledata->user[i].effective && strcmp(tabledata->user[i].name, name) == 0) { - return &tabledata->user[i]; + if (usr_table_data->user[i].effective && strcmp(usr_table_data->user[i].name, name) == 0) { + return &usr_table_data->user[i]; } } return nullptr; @@ -125,8 +140,8 @@ user_t* UserDao::getUserByName(const char* name) { user_t* UserDao::getUserById(int32_t id) { ZASSERT_INFO(module_inited, "user dao not inited"); for (int i = 0; i < MAX_USR_NUM; i++) { - if (tabledata->user[i].effective && tabledata->user[i].id == id) { - return &tabledata->user[i]; + if (usr_table_data->user[i].effective && usr_table_data->user[i].id == id) { + return &usr_table_data->user[i]; } } return nullptr; @@ -144,8 +159,8 @@ Errno UserDao::addUser(const char* name, const char* passwd, user_role_t role) { } for (int i = 0; i < MAX_USR_NUM; i++) { - if (!tabledata->user[i].effective) { - user = &tabledata->user[i]; + if (!usr_table_data->user[i].effective) { + user = &usr_table_data->user[i]; break; } } @@ -153,12 +168,15 @@ Errno UserDao::addUser(const char* name, const char* passwd, user_role_t role) { ZLOGE(TAG, "no space for new user"); return Errno::ERR_USER_SPACE_FULL; } - user->id = tabledata->maxid++; + user->id = usr_table_data->maxid++; user->effective = true; + user->builtIn = false; strcpy(user->name, name); strcpy(user->passwd, passwd); user->role = role; + ZLOGI(TAG, "add user %s %d", name, user->id); + sortUsr(); storgeTableData(); return Errno::OK; @@ -179,11 +197,12 @@ const char* createNewUsrName() { Errno UserDao::addUser() { return UserDao::addUser(createNewUsrName(), "888888", kuser); } void UserDao::delUser(uint8_t userId) { + ZLOGI(TAG, "del user %d", userId); ZASSERT_INFO(module_inited, "user dao not inited"); for (int i = 0; i < MAX_USR_NUM; i++) { - if (tabledata->user[i].effective && tabledata->user[i].id == userId) { - tabledata->user[i].effective = false; + if (usr_table_data->user[i].effective && usr_table_data->user[i].id == userId) { + usr_table_data->user[i].effective = false; break; } } @@ -196,8 +215,8 @@ void UserDao::updateUser(uint8_t userId, const char* name, const char* passwd, u user_t* user = nullptr; for (int i = 0; i < MAX_USR_NUM; i++) { - if (tabledata->user[i].effective && tabledata->user[i].id == userId) { - user = &tabledata->user[i]; + if (usr_table_data->user[i].effective && usr_table_data->user[i].id == userId) { + user = &usr_table_data->user[i]; break; } } diff --git a/usrc/service/app_core.cpp b/usrc/service/app_core.cpp index 3fa8c94..daa439d 100644 --- a/usrc/service/app_core.cpp +++ b/usrc/service/app_core.cpp @@ -26,14 +26,7 @@ using namespace iflytop; static ZThread ledthread; -static const char* zhex2str(uint8_t* data, size_t len) { - static char buf[256]; - memset(buf, 0, sizeof(buf)); - for (size_t i = 0; i < len; i++) { - sprintf(buf + i * 2, "%02X", data[i]); - } - return buf; -} + static void debuglegInit() { // 启动调试指示灯功能 diff --git a/usrc/uicontroler/base/page_processer.cpp b/usrc/uicontroler/base/page_processer.cpp index f0975eb..51323e0 100644 --- a/usrc/uicontroler/base/page_processer.cpp +++ b/usrc/uicontroler/base/page_processer.cpp @@ -39,6 +39,8 @@ void IPageProcesser::initialize() { onClickRelease(event->d.uiEvent.bid, event->d.uiEvent.val, event->d.uiEvent.text); } else if (event->d.uiEvent.eventId == kpt_page_back_event) { onBackKey(); + } else if (event->d.uiEvent.eventId == kpt_inputfield_content_change_event) { + onInputFieldContentChange(event->d.uiEvent.bid, event->d.uiEvent.val, event->d.uiEvent.text); } // } else { diff --git a/usrc/uicontroler/base/page_processer.hpp b/usrc/uicontroler/base/page_processer.hpp index 4a01587..b94f20b 100644 --- a/usrc/uicontroler/base/page_processer.hpp +++ b/usrc/uicontroler/base/page_processer.hpp @@ -34,7 +34,7 @@ class IPageProcesser { virtual void onPageLoad(OnPageLoadContext* cxt) { return; }; virtual void onAppEvent(AppEvent_t* event) { return; }; - virtual void onInputFieldContentChange(uint8_t bid, const char* text) { return; }; + virtual void onInputFieldContentChange(uint8_t bid, uint8_t slecId, const char* text) { return; }; virtual void onBackKey() { return; }; virtual void onClickRelease(uint8_t bid, uint8_t val, const char* text) { return; }; @@ -62,10 +62,13 @@ class IPageProcesser { } void visBySetAph(uint8_t bid, bool val) { UIControler::ins()->setAph(pageId, bid, val ? 127 : 0); } void visEx(uint8_t bid, bool val) { UIControler::ins()->visEx(pageId, bid, val); } + bool movePicToXY(uint8_t bid, int32_t x, int32_t y) { UIControler::ins()->movePicToXY(pageId, bid, x, y); return true; } + bool movePicTo(uint8_t bid, uint8_t toBid) { UIControler::ins()->movePicTo(pageId, bid, toBid); return true;} + bool movePicOutOfScreen(uint8_t bid) { UIControler::ins()->movePicOutOfScreen(pageId, bid); return true; } void popFullKeyBoard(uint8_t fromBid, int limitLength, const char* initval) { UIControler::ins()->popFullKeyBoard(pageId, fromBid, limitLength, initval); } void popPasswdKeyBoard(uint8_t fromBid, int limitLength) { UIControler::ins()->popPasswdKeyBoard(pageId, fromBid, limitLength); } void popNumKeyBoard(uint8_t fromBid, int limitLength, const char* initval) { UIControler::ins()->popNumKeyBoard(pageId, fromBid, limitLength, initval); } }; -} // namespace iflytop \ No newline at end of file +} // namespace iflytop diff --git a/usrc/uicontroler/event_proceesser/inputfield_content_selected_change_event_processer.cpp b/usrc/uicontroler/event_proceesser/inputfield_content_selected_change_event_processer.cpp new file mode 100644 index 0000000..70feee5 --- /dev/null +++ b/usrc/uicontroler/event_proceesser/inputfield_content_selected_change_event_processer.cpp @@ -0,0 +1,26 @@ +#include "inputfield_content_selected_change_event_processer.hpp" + +using namespace iflytop; +void InputfieldContentSelectedChangeEventProcesser::process(uint8_t* indata, size_t len, UIEvent* result) { + /** + * @brief + * + * printh AD + * prints loadpageid.val,1 + * prints loadcmpid.val,1 + * prints slec.val,4 + * prints p[loadpageid.val].b[loadcmpid.val].txt,0 + * printh 00 + * printh FF FF FF + * page loadpageid.val + * + */ + // ZLOGI(TAG, "processInputfieldContentChangeEvent1"); + result->eventId = indata[0]; + result->pid = indata[1]; + result->bid = indata[2]; + result->val = indata[3]; + const char* strbegin = (const char*)&indata[4]; + strbegin = TJCStrUtils::cpystr(result->text, strbegin, sizeof(*result->text)); + result->butEventType = kbutton_release; +} diff --git a/usrc/uicontroler/event_proceesser/inputfield_content_selected_change_event_processer.hpp b/usrc/uicontroler/event_proceesser/inputfield_content_selected_change_event_processer.hpp new file mode 100644 index 0000000..9a66203 --- /dev/null +++ b/usrc/uicontroler/event_proceesser/inputfield_content_selected_change_event_processer.hpp @@ -0,0 +1,11 @@ +#pragma once +#include "if/i_tjc_ui_event_processer.hpp" +namespace iflytop { + +class InputfieldContentSelectedChangeEventProcesser : public iTjcUiEventProcesser { + public: + InputfieldContentSelectedChangeEventProcesser(/* args */) : iTjcUiEventProcesser(kpt_inputfield_content_selected_change_event) {} + virtual void process(uint8_t* indata, size_t len, UIEvent* result) override; +}; + +} // namespace iflytop diff --git a/usrc/uicontroler/page/demo/demo_page_cpp b/usrc/uicontroler/page/demo/demo_page_cpp index e0538e4..4b4d138 100644 --- a/usrc/uicontroler/page/demo/demo_page_cpp +++ b/usrc/uicontroler/page/demo/demo_page_cpp @@ -27,7 +27,7 @@ class MuIntervalPage : public IPageProcesser { private: virtual void OnPageLoad(OnPageLoadContext* cxt) { return; }; virtual void OnBackKey() { return; }; - virtual void OnInputFieldContentChange(uint8_t bid, const char* text) { return; }; + virtual void OnInputFieldContentChange(uint8_t bid, uint8_t slecId, const char* text) { return; }; virtual void OnButton(uint8_t bid, uint8_t val) { return; }; virtual void OnDoubleStateButton(uint8_t bid, uint8_t val) { return; }; virtual void OnAppEvent(AppEvent_t* event) { return; }; diff --git a/usrc/uicontroler/page/home_page.cpp b/usrc/uicontroler/page/home_page.cpp index f545d2d..b3b318a 100644 --- a/usrc/uicontroler/page/home_page.cpp +++ b/usrc/uicontroler/page/home_page.cpp @@ -38,7 +38,7 @@ class HomePage : public IPageProcesser { syncState(); } virtual void onBackKey() override {} - virtual void onInputFieldContentChange(uint8_t bid, const char* text) override { + virtual void onInputFieldContentChange(uint8_t bid, uint8_t slecId, const char* text) override { if (bid == ob_home_acideval0) { AcidChCfgDao::updateAcidEachDistriVal(0, atof(text)); } else if (bid == ob_home_acideval1) { diff --git a/usrc/uicontroler/page/login_page.cpp b/usrc/uicontroler/page/login_page.cpp index c56f2a8..4a43557 100644 --- a/usrc/uicontroler/page/login_page.cpp +++ b/usrc/uicontroler/page/login_page.cpp @@ -22,7 +22,7 @@ class LoginPage : public IPageProcesser { private: virtual void onPageLoad(OnPageLoadContext* cxt) override {} virtual void onBackKey() override {} - virtual void onInputFieldContentChange(uint8_t bid, const char* text) override { + virtual void onInputFieldContentChange(uint8_t bid, uint8_t slecId, const char* text) override { if (bid == ob_login_uName) { UIS->setTxt(pageId, ob_login_uName, text); // strcpy(userName, text); // diff --git a/usrc/uicontroler/page/mupage/muInterval_page.cpp b/usrc/uicontroler/page/mupage/muInterval_page.cpp index 6896eb7..1f9d9ac 100644 --- a/usrc/uicontroler/page/mupage/muInterval_page.cpp +++ b/usrc/uicontroler/page/mupage/muInterval_page.cpp @@ -33,7 +33,7 @@ class MuIntervalPage : public IPageProcesser { */ virtual void OnBackKey() { UIControler::ins()->chpage(pg_navi); }; - virtual void OnInputFieldContentChange(uint8_t bid, const char* text) { + virtual void OnInputFieldContentChange(uint8_t bid, uint8_t slecId, const char* text) { if (bid == ob_muInterval_stAcidInte) { float distrIntervalSSecond = atof(text); if (distrIntervalSSecond <= 0) { diff --git a/usrc/uicontroler/page/mupage/muUsrMgr_page.cpp b/usrc/uicontroler/page/mupage/muUsrMgr_page.cpp index 64c4d61..4f252e8 100644 --- a/usrc/uicontroler/page/mupage/muUsrMgr_page.cpp +++ b/usrc/uicontroler/page/mupage/muUsrMgr_page.cpp @@ -23,18 +23,18 @@ typedef struct { int userNameBid; int cfgButtonBid; - uint8_t usrId; - char userName[32]; - UserRole& role = UserRole::user; - bool enable = false; + uint8_t usrId; + char userName[32]; + const UserRole* role = &UserRole::user; + bool enable = false; } UIUsrTableIterm; typedef struct { - bool enable; - int index; - char name[32]; - UserRole role; - bool resetPasswd; + bool enable; + int index; + char name[32]; + const UserRole* role; + bool resetPasswd; bool editDirty; } EditContext_t; @@ -50,7 +50,15 @@ static UIUsrTableIterm m_uiUsrTable[MAX_USR_NUM] = { {.index = 8, .indexBid = ob_muUsrMgr_index7, .userNameBid = ob_muUsrMgr_uName7, .cfgButtonBid = ob_muUsrMgr_cfg7}, // 8 }; -static EditContext_t m_editContext = {false, -1, "", UserRole::user, false, false}; +static void resetUiUsrTable() { + for (int i = 0; i < MAX_USR_NUM; i++) { + m_uiUsrTable[i].enable = false; + m_uiUsrTable[i].role = nullptr; + m_uiUsrTable[i].usrId = 0; + } +} + +static EditContext_t m_editContext = {false, -1, "", &UserRole::user, false, false}; class MuUsrMgr : public IPageProcesser { private: @@ -60,23 +68,15 @@ class MuUsrMgr : public IPageProcesser { virtual void initialize() override { IPageProcesser::initialize(); - // visEx(ob_muUsrMgr_save, false); + // movePicTo(ob_muUsrMgr_editAreaMask, ob_muUsrMgr_editAreaLable); - - // // 初始化状态信息 + // 同步列表 fillUsrStateUICache(); syncUIUsrTableState(); + // 同步编辑框 fillEditContext(-1); syncEditContext(); - - // // 填充部分UI组件内容 - UIControler::ins()->sendcmd("p[%d].b[%d].path=\"%s\n%s\n%s\"", pageId, ob_muUsrMgr_roleVal, // - UserRole::admin.chName, // - UserRole::storekeeper.chName, // - UserRole::user.chName); - // 同步UI状态 - // syncUIUsrTableState(); } private: @@ -129,7 +129,8 @@ class MuUsrMgr : public IPageProcesser { */ if (bid == ob_muUsrMgr_roleVal) { // 修改用户角色 - m_editContext.role = UserRole::of(val); + UserRole::of(val); + m_editContext.role = &UserRole::admin; m_editContext.editDirty = true; syncEditContext(); } else if (bid == ob_muUsrMgr_usrName) { @@ -154,7 +155,7 @@ class MuUsrMgr : public IPageProcesser { } } - virtual void onInputFieldContentChange(uint8_t bid, const char* text) { + virtual void onInputFieldContentChange(uint8_t bid, uint8_t slecId, const char* text) { if (bid == ob_muUsrMgr_usrName) { if (strlen(text) == 0) { return; @@ -187,19 +188,27 @@ class MuUsrMgr : public IPageProcesser { void delUsr() { ZLOGI(TAG, "delUsr"); // 删除用户 - user_t* user = UserDao::getUserById(m_uiUsrTable[m_editContext.index].usrId); - if (user == nullptr) { - ZLOGE(TAG, "user not exist ,find by id %d", m_uiUsrTable[m_editContext.index].usrId); - UIControler::ins()->popWarningWin("用户不存在"); - return; - } + do { + user_t* user = UserDao::getUserById(m_uiUsrTable[m_editContext.index].usrId); + if (user == nullptr) { + ZLOGE(TAG, "user not exist ,find by id %d", m_uiUsrTable[m_editContext.index].usrId); + UIControler::ins()->popWarningWin("用户不存在"); + break; + } - if (user->builtIn) { - UIControler::ins()->popWarningWin("内置管理员用户不能删除"); - return; - } + if (user->builtIn) { + ZLOGE(TAG, "user is builtIn ,find by id %d", m_uiUsrTable[m_editContext.index].usrId); + UIControler::ins()->popWarningWin("内置管理员用户不能删除"); + break; + } + UserDao::delUser(user->id); + } while (false); - UserDao::delUser(user->id); + fillUsrStateUICache(); + syncUIUsrTableState(); + + fillEditContext(-1); + syncEditContext(); } void saveUsr() { @@ -218,15 +227,15 @@ class MuUsrMgr : public IPageProcesser { return; } - if (user->builtIn && !m_editContext.role.isEq(&UserRole::admin)) { + if (user->builtIn && !m_editContext.role->isEq(UserRole::admin)) { UIControler::ins()->popWarningWin("内置管理员用户不能修改普用户类型"); return; } if (m_editContext.resetPasswd) { - UserDao::updateUser(user->id, m_editContext.name, DEFAULT_PASSWD, (user_role_t)m_editContext.role.val); + UserDao::updateUser(user->id, m_editContext.name, DEFAULT_PASSWD, (user_role_t)m_editContext.role->val); } else { - UserDao::updateUser(user->id, m_editContext.name, NULL, (user_role_t)m_editContext.role.val); + UserDao::updateUser(user->id, m_editContext.name, NULL, (user_role_t)m_editContext.role->val); } fillUsrStateUICache(); @@ -251,18 +260,15 @@ class MuUsrMgr : public IPageProcesser { int numUser = UserDao::getUsersTableNum(); // 填充 m_uiUsrTable - for (int i = 0; i < MAX_USR_NUM; i++) { - if (i >= numUser) { - m_uiUsrTable[i].enable = false; - continue; - } - + resetUiUsrTable(); + for (int i = 0; i < numUser; i++) { user_t* user = &users[i]; + ZLOGI(TAG, "fill index:%d user(%d) %s", i, user->id, user->name); + strcpy(m_uiUsrTable[i].userName, user->name); m_uiUsrTable[i].role = UserRole::of(user->role); m_uiUsrTable[i].enable = true; m_uiUsrTable[i].usrId = user->id; - m_uiUsrTable[i].index = i; } } @@ -319,20 +325,24 @@ class MuUsrMgr : public IPageProcesser { if (m_editContext.enable) { setText(ob_muUsrMgr_indexVal, "%d", m_editContext.index); setText(ob_muUsrMgr_usrNameVal, "%s", m_editContext.name); - setVal(ob_muUsrMgr_roleVal, m_editContext.role.val); + setText(ob_muUsrMgr_roleVal, m_editContext.role->chName); setPicturePicNumFG(ob_muUsrMgr_passwdRest, m_editContext.resetPasswd ? ob_gvar_stateSwitch1 : ob_gvar_stateSwitch0); setPicturePicNumFG(ob_muUsrMgr_isEdited, m_editContext.editDirty ? ob_gvar_editDirty : ob_gvar_edit); - visEx(ob_muUsrMgr_save, true); - visEx(ob_muUsrMgr_del, true); + movePicOutOfScreen(ob_muUsrMgr_editAreaMask); // 移走蒙板 + if (strcmp(m_editContext.name, GStateMgr::ins()->getLoginUsr()) != 0) { + movePicOutOfScreen(ob_muUsrMgr_delButMask); // 移走蒙板 + } else { + movePicTo(ob_muUsrMgr_delButMask, ob_muUsrMgr_del); // 给删除按钮加蒙板 + } + } else { setText(ob_muUsrMgr_indexVal, ""); setText(ob_muUsrMgr_usrNameVal, ""); setText(ob_muUsrMgr_roleVal, ""); setPicturePicNumFG(ob_muUsrMgr_isEdited, ob_gvar_edit); - visEx(ob_muUsrMgr_save, false); - visEx(ob_muUsrMgr_del, false); + movePicTo(ob_muUsrMgr_editAreaMask, ob_muUsrMgr_editAreaLable); // } } }; diff --git a/usrc/uicontroler/page/popwin_page.cpp b/usrc/uicontroler/page/popwin_page.cpp index 6951228..4186e9b 100644 --- a/usrc/uicontroler/page/popwin_page.cpp +++ b/usrc/uicontroler/page/popwin_page.cpp @@ -41,7 +41,7 @@ class PopWinPage : public IPageProcesser { private: virtual void onPageLoad(OnPageLoadContext* cxt) override {} virtual void onBackKey() override {} - virtual void onInputFieldContentChange(uint8_t bid, const char* text) override {} + virtual void onInputFieldContentChange(uint8_t bid, uint8_t slecId, const char* text) override {} virtual void onClickRelease(uint8_t bid, uint8_t val, const char* text) override { // int num = UIPublicState::getPopInfoNum(); diff --git a/usrc/uicontroler/tjc/tjc_base_type.h b/usrc/uicontroler/tjc/tjc_base_type.h index a63cca8..47f0e65 100644 --- a/usrc/uicontroler/tjc/tjc_base_type.h +++ b/usrc/uicontroler/tjc/tjc_base_type.h @@ -71,7 +71,8 @@ typedef enum { */ kpt_ack = 0xAA, // - kpt_inputfield_content_change_event = 0xAC, // 跨页面键盘输入事件 + kpt_inputfield_content_change_event = 0xAC, // 跨页面键盘输入事件 + kpt_inputfield_content_selected_change_event = 0xAD, // 跨页面多选框输入事件 kpt_page_back_event = 0xB0, // 回退按键事件 kpt_usr_def_clik_release_event = 0xB1, // 用户自定义按键释放事件 @@ -98,7 +99,7 @@ typedef struct { uint8_t bid; // content - button_event_t butEventType; - uint8_t val; - char text[TJC_MAX_PACKET_SIZE]; + button_event_t butEventType; // 按键事件类型 + uint8_t val; // 数值相关 + char text[TJC_MAX_PACKET_SIZE]; // 文本相关 } UIEvent; \ No newline at end of file diff --git a/usrc/uicontroler/tjc_event_processer_mgr.cpp b/usrc/uicontroler/tjc_event_processer_mgr.cpp index 804ab93..f4da5c9 100644 --- a/usrc/uicontroler/tjc_event_processer_mgr.cpp +++ b/usrc/uicontroler/tjc_event_processer_mgr.cpp @@ -2,6 +2,7 @@ // #include "event_proceesser/button_event_processer.hpp" #include "event_proceesser/inputfield_content_change_event_processer.hpp" +#include "event_proceesser/inputfield_content_selected_change_event_processer.hpp" #include "event_proceesser/page_back_event_processer.hpp" #include "event_proceesser/sys_event_page_id_processer.hpp" #include "event_proceesser/usr_def_clik_release_with_val_event_processer.hpp" @@ -11,18 +12,20 @@ using namespace iflytop; /*********************************************************************************************************************** * EVENT_PROCESSER_LIST * ***********************************************************************************************************************/ -static UsrDefClikReleaseWithValEventProcesser usrDefClikReleaseWithValEventProcesser; -static InputFieldContentChangeEventProcesser inputFieldContentChangeEventProcesser; -static PageBackEventProcesser pageBackEventProcesser; -static SysEventPageIdProcesser sysEventPageIdProcesser; -static ButtonEventProcesser buttonEventProcesser; +static UsrDefClikReleaseWithValEventProcesser usrDefClikReleaseWithValEventProcesser; +static InputFieldContentChangeEventProcesser inputFieldContentChangeEventProcesser; +static PageBackEventProcesser pageBackEventProcesser; +static SysEventPageIdProcesser sysEventPageIdProcesser; +static ButtonEventProcesser buttonEventProcesser; +static InputfieldContentSelectedChangeEventProcesser inputfieldContentSelectedChangeEventProcesser; static iTjcUiEventProcesser* m_eventProcessers[] = { - &usrDefClikReleaseWithValEventProcesser, // - &inputFieldContentChangeEventProcesser, // - &pageBackEventProcesser, // - &sysEventPageIdProcesser, // - &buttonEventProcesser, // + &usrDefClikReleaseWithValEventProcesser, // + &inputFieldContentChangeEventProcesser, // + &pageBackEventProcesser, // + &sysEventPageIdProcesser, // + &buttonEventProcesser, // + &inputfieldContentSelectedChangeEventProcesser, // }; /*********************************************************************************************************************** diff --git a/usrc/uicontroler/ui_controler.cpp b/usrc/uicontroler/ui_controler.cpp index e8cf2e4..f1c5edf 100644 --- a/usrc/uicontroler/ui_controler.cpp +++ b/usrc/uicontroler/ui_controler.cpp @@ -12,7 +12,7 @@ using namespace iflytop; #define TAG "UIScheduler" -#define MODULE_DEBUG 1 +#define MODULE_DEBUG 0 #define UART_RX_OVERTIME 5 #define CMD_OVERTIME 50 @@ -314,8 +314,9 @@ void UIControler::sendcmd(const char* format, ...) { void UIControler::sendcmd(const char* format, va_list args) { static char buf[128]; vsprintf(buf, format, args); - +#if MODULE_DEBUG ZLOGI(TAG, "tx:%s", buf); +#endif uint8_t len = strlen(buf); if (len > (128 - 3)) { @@ -370,28 +371,43 @@ bool UIControler::visEx(uint8_t pid, uint8_t bid, bool val) { bool suc = true; do { + if (!component->isPosInited) { + suc = readFiledAsInt(pid, bid, "x", &component->oldPosX); + if (!suc) break; + suc = readFiledAsInt(pid, bid, "y", &component->oldPosY); + if (!suc) break; + } + if (val) { - if (component->isVis) { - break; - } // 显示 sendcmd("p[%d].b[%d].x=%d", pid, bid, component->oldPosX); sendcmd("p[%d].b[%d].y=%d", pid, bid, component->oldPosY); + component->isVis = true; } else { - // 隐藏 - if (!component->isPosInited) { - suc = readFiledAsInt(pid, bid, "x", &component->oldPosX); - if (!suc) break; - suc = readFiledAsInt(pid, bid + 1, "y", &component->oldPosY); - if (!suc) break; - component->isPosInited = true; - component->isVis = false; - - sendcmd("p[%d].b[%d].x=%d", pid, bid, -2000); - sendcmd("p[%d].b[%d].y=%d", pid, bid, -2000); - } + component->isPosInited = true; + component->isVis = false; + sendcmd("p[%d].b[%d].x=%d", pid, bid, -2000); + sendcmd("p[%d].b[%d].y=%d", pid, bid, -2000); } } while (false); return suc; } + +bool UIControler::movePicToXY(uint8_t pid, uint8_t bid, int32_t x, int32_t y) { + sendcmd("p[%d].b[%d].x=%d", pid, bid, x); + sendcmd("p[%d].b[%d].y=%d", pid, bid, y); + return true; +} + +bool UIControler::movePicTo(uint8_t pid, uint8_t bid, uint8_t toBid) { + sendcmd("p[%d].b[%d].x=p[%d].b[%d].x", pid, bid, pid, toBid); + sendcmd("p[%d].b[%d].y=p[%d].b[%d].y", pid, bid, pid, toBid); + return true; +} + +bool UIControler::movePicOutOfScreen(uint8_t pid, uint8_t bid) { + sendcmd("p[%d].b[%d].x=%d", pid, bid, -2000); + sendcmd("p[%d].b[%d].y=%d", pid, bid, -2000); + return true; +} diff --git a/usrc/uicontroler/ui_controler.hpp b/usrc/uicontroler/ui_controler.hpp index a10a9d3..6f6daa6 100644 --- a/usrc/uicontroler/ui_controler.hpp +++ b/usrc/uicontroler/ui_controler.hpp @@ -81,32 +81,45 @@ class UIControler { */ void popFullKeyBoard(uint8_t fromPid, uint8_t fromBid, int limitLength, const char* initval) { - sendcmd("p[%d].b[%d].loadpageid.val=%d", pg_keybdAP, ob_keybdAP_loadpageid, fromPid); - sendcmd("p[%d].b[%d].loadcmpid.val=%d", pg_keybdAP, ob_keybdAP_loadcmpid, fromBid); - sendcmd("p[%d].b[%d].show.txt=%s", pg_keybdAP, ob_keybdAP_show, initval); - sendcmd("p[%d].b[%d].show.pw=0", pg_keybdAP, ob_keybdAP_show); - sendcmd("p[%d].b[%d].inputlenth.val=%d", pg_keybdAP, ob_keybdAP_inputlenth, limitLength); + sendcmd("p[%d].b[%d].val=%d", pg_keybdAP, ob_keybdAP_loadpageid, fromPid); + sendcmd("p[%d].b[%d].val=%d", pg_keybdAP, ob_keybdAP_loadcmpid, fromBid); + sendcmd("p[%d].b[%d].txt=%s", pg_keybdAP, ob_keybdAP_show, initval); + sendcmd("p[%d].b[%d].pw=0", pg_keybdAP, ob_keybdAP_show); + sendcmd("p[%d].b[%d].val=%d", pg_keybdAP, ob_keybdAP_inputlenth, limitLength); chpage(pg_keybdAP); } void popPasswdKeyBoard(uint8_t fromPid, uint8_t fromBid, int limitLength) { - sendcmd("p[%d].b[%d].loadpageid.val=%d", pg_keyPasswd, ob_keyPasswd_loadpageid, fromPid); - sendcmd("p[%d].b[%d].loadcmpid.val=%d", pg_keyPasswd, ob_keyPasswd_loadcmpid, fromBid); - sendcmd("p[%d].b[%d].show.txt=%s", pg_keyPasswd, ob_keyPasswd_show, ""); - sendcmd("p[%d].b[%d].show.pw=1", pg_keyPasswd, ob_keyPasswd_show); - sendcmd("p[%d].b[%d].inputlenth.val=%d", pg_keyPasswd, ob_keyPasswd_inputlenth, limitLength); + sendcmd("p[%d].b[%d].val=%d", pg_keyPasswd, ob_keyPasswd_loadpageid, fromPid); + sendcmd("p[%d].b[%d].val=%d", pg_keyPasswd, ob_keyPasswd_loadcmpid, fromBid); + sendcmd("p[%d].b[%d].txt=%s", pg_keyPasswd, ob_keyPasswd_show, ""); + sendcmd("p[%d].b[%d].pw=1", pg_keyPasswd, ob_keyPasswd_show); + sendcmd("p[%d].b[%d].val=%d", pg_keyPasswd, ob_keyPasswd_inputlenth, limitLength); chpage(pg_keyPasswd); } void popNumKeyBoard(uint8_t fromPid, uint8_t fromBid, int limitLength, const char* initval) { - sendcmd("p[%d].b[%d].loadpageid.val=%d", pg_keybdB, ob_keybdB_loadpageid, fromPid); - sendcmd("p[%d].b[%d].loadcmpid.val=%d", pg_keybdB, ob_keybdB_loadcmpid, fromBid); - sendcmd("p[%d].b[%d].show.txt=%s", pg_keybdB, ob_keybdB_show, initval); - sendcmd("p[%d].b[%d].show.pw=0", pg_keybdB, ob_keybdB_show); - sendcmd("p[%d].b[%d].inputlenth.val=%d", pg_keybdB, ob_keybdB_inputlenth, limitLength); + sendcmd("p[%d].b[%d].val=%d", pg_keybdB, ob_keybdB_loadpageid, fromPid); + sendcmd("p[%d].b[%d].val=%d", pg_keybdB, ob_keybdB_loadcmpid, fromBid); + sendcmd("p[%d].b[%d].txt=%s", pg_keybdB, ob_keybdB_show, initval); + sendcmd("p[%d].b[%d].pw=0", pg_keybdB, ob_keybdB_show); + sendcmd("p[%d].b[%d].val=%d", pg_keybdB, ob_keybdB_inputlenth, limitLength); chpage(pg_keybdB); } + void popSelcKeyBoard(uint8_t fromPid, uint8_t fromBid, int numselect, const char * selectvals[], int selectvalindex) { + sendcmd("p[%d].b[%d].val=%d", pg_keybMutiSel, ob_keybMutiSel_loadpageid, fromPid); + sendcmd("p[%d].b[%d].val=%d", pg_keybMutiSel, ob_keybMutiSel_loadcmpid, fromBid); + sendcmd("p[%d].b[%d].val=%d", pg_keybMutiSel, ob_keybMutiSel_ctent, selectvalindex); + static char contentbus[128]; + for (int i = 0; i < numselect; i++) { + // \r\n 拼接字符串数组 + sprintf(contentbus, "%s\r\n%s", contentbus, selectvals[i]); + } + sendcmd("p[%d].b[%d].path=%s", pg_keybMutiSel, ob_keybMutiSel_ctent, contentbus); + chpage(pg_keybMutiSel); + } + /*********************************************************************************************************************** * UTILS * ***********************************************************************************************************************/ @@ -115,6 +128,9 @@ class UIControler { void setTouchEnableState(uint8_t bid, uint8_t enable); // 不支持跨页面隐藏 bool visEx(uint8_t pid, uint8_t bid, bool val); // 通过搬移组件实现跨页面隐藏 + bool movePicToXY(uint8_t pid, uint8_t bid, int32_t x, int32_t y); + bool movePicTo(uint8_t pid, uint8_t bid, uint8_t toBid); + bool movePicOutOfScreen(uint8_t pid, uint8_t bid); private: void processScreenRxPacket(uint8_t* data, size_t len);