From fcb90d0b7d6bb5a687ad3a3a78104b0e72685bf9 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Mon, 5 Feb 2024 17:57:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8F=9C=E5=8D=95=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hardware/hardware.cpp | 2 +- sdk/base/words.h | 7 +- ui/Lcd.cpp | 8 +- ui/dev_menu.cpp | 317 ++++++++++++++++++++++++++++++++++++++++-- ui/dev_menu.h | 17 ++- ui/font.cpp | 52 ++++++- ui/font.h | 2 +- xmake.lua | 4 +- 8 files changed, 383 insertions(+), 26 deletions(-) diff --git a/hardware/hardware.cpp b/hardware/hardware.cpp index 06d427a..454a302 100644 --- a/hardware/hardware.cpp +++ b/hardware/hardware.cpp @@ -417,7 +417,7 @@ void scanner_hw::thread_image_capture(void) used_v4l2_mem++; img.pos.paper_ind++; img.pos.status = hg_err_2_image_status(err); - //img_handler_(mem, true, &img); + img_handler_(mem, true, &img); mem->release(); if((!scan_cntless_ && img.pos.paper_ind == scan_count_) || is_scan_fatal()) diff --git a/sdk/base/words.h b/sdk/base/words.h index 103569f..735f64e 100644 --- a/sdk/base/words.h +++ b/sdk/base/words.h @@ -18,6 +18,7 @@ +#define WORDS_MENU_WELCOME "\346\254\242\350\277\216" #define WORDS_MENU_SELECTED "\342\210\232" #define WORDS_MENU_RETURN "\350\277\224\345\233\236\344\270\212\347\272\247\350\217\234\345\215\225" #define WORDS_MENU_SEPARATE_STRENGTH "\345\210\206\347\272\270\345\274\272\345\272\246" @@ -43,4 +44,8 @@ #define WORDS_MENU_RESET_ROLLOER_CNT "\346\270\205\351\231\244\346\273\232\350\275\264\345\274\240\346\225\260" #define WORDS_MENU_SHUTDOWN "\345\205\263\346\234\272" #define WORDS_MENU_YES "\347\241\256\345\256\232" -#define WORDS_MENU_NO "\345\217\226\346\266\210" \ No newline at end of file +#define WORDS_MENU_NO "\345\217\226\346\266\210" + +#define WORDS_FUNCTION_COUNT "\345\274\240\346\225\260" + +#define WORDS_STATUS_READY "\345\260\261\347\273\252" \ No newline at end of file diff --git a/ui/Lcd.cpp b/ui/Lcd.cpp index 9b7a1dd..0fabc9c 100644 --- a/ui/Lcd.cpp +++ b/ui/Lcd.cpp @@ -4,6 +4,7 @@ #include #include #include +#include using namespace std; @@ -838,6 +839,11 @@ void Lcd::clear(int x, int y, int w, int h) } void Lcd::write_line(uint8_t rows, uint8_t cols, uint8_t cnt, uint8_t** data, int x, int y, uint8_t mask) { + uint8_t *ptr[16] = {0}; + + for(int i = 0; i < cnt && i < _countof(ptr); ++i) + ptr[i] = data[i]; + for(int r = 0; r < rows / LCD_LINE_PER_PAGE; ++r) { go_to(y / LCD_LINE_PER_PAGE + r, x); @@ -848,7 +854,7 @@ void Lcd::write_line(uint8_t rows, uint8_t cols, uint8_t cnt, uint8_t** data, in { for(int c = 0; c < cols; ++c) { - write_char(*data[ind]++, mask); + write_char(*ptr[ind]++, mask); } write_char(0, mask); } diff --git a/ui/dev_menu.cpp b/ui/dev_menu.cpp index 1b3f416..f16e4d0 100644 --- a/ui/dev_menu.cpp +++ b/ui/dev_menu.cpp @@ -206,6 +206,7 @@ int dev_menu::get_menu_text(std::vector& text, int& sel) + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ui_mgr enum @@ -239,13 +240,50 @@ enum MENU_CMD_ID_GET_ROLLER_COUNT, MENU_CMD_ID_SHUTDOWN = 0x90, + + MENU_CMD_ID_WELCOME = 0xa0, }; +static uint8_t welcome[] = {128, 32 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0xC0, 0x80, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0xC0, 0x80, 0x80 + , 0x80, 0x80, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x40, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE6, 0x02, 0x00, 0x00, 0x00, 0x04, 0x04 + , 0x04, 0x04, 0x04, 0x08, 0x08, 0x88, 0x88, 0x08, 0x00, 0x00, 0x00, 0x10, 0xB0, 0x36, 0x66, 0xFF + , 0xFE, 0xF6, 0xE0, 0x80, 0x00, 0xC0, 0xE0, 0xF0, 0xD8, 0xDC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF4 + , 0xFC, 0xFC, 0xF8, 0xF0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xF0, 0xF0, 0x60, 0x20, 0x20, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x3F, 0x7F, 0x27, 0x3E, 0x1F, 0x1E, 0x36, 0x00, 0x08, 0x0C + , 0x17, 0x7F, 0x3F, 0x1D, 0x3F, 0x63, 0x3E, 0x0C, 0x00, 0x00, 0x23, 0x3D, 0x1F, 0x7F, 0x5F, 0x15 + , 0x30, 0x20, 0x00, 0x00, 0x16, 0x3F, 0x39, 0x1A, 0x1E, 0x0F, 0x1B, 0x18, 0x00, 0x00, 0x00, 0x0F + , 0x03, 0x7F, 0x7F, 0x7F, 0x7F, 0x13, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x08, 0x08, 0x08, 0x09, 0x0B, 0x03, 0x07, 0x17, 0x1F, 0x0F, 0x0F, 0x1F, 0x0B, 0x13 + , 0x17, 0x17, 0x3F, 0x3F, 0x1F, 0x1F, 0x0F, 0x1F, 0x0F, 0x0F, 0x0F, 0x17, 0x0F, 0x0F, 0x0F, 0x1F + , 0x1F, 0x1F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x05, 0x05, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + ui_mgr::ui_mgr() : disp_data_("lcd-msg") { init(); - auto ke = [this](int key) -> void + auto ke = [this](int key) -> MENU_CMD_HANDLER_RET { key_event(key); }; @@ -253,9 +291,14 @@ ui_mgr::ui_mgr() : disp_data_("lcd-msg") lcd_->Lcd_Initial_Lcd(false); lcd_->clear(); + ready_.cnt = get_string_font(WORDS_STATUS_READY, ready_.ptr, &ready_.rows, &ready_.cols); + ready_.x = (Lcd::LCD_WIDTH - ready_.cols * ready_.cnt) / 2; + ready_.y = (Lcd::LCD_HEIGHT - ready_.rows) / 2; + ready_.mask = 0; + keyboard_.reset(new KeyMonitor(ke)); disp_thrd_.reset(new std::thread(&ui_mgr::thread_display, this)); - refresh_lcd(true); + // refresh_lcd(true); } ui_mgr::~ui_mgr() { @@ -267,15 +310,22 @@ ui_mgr::~ui_mgr() clear(); } -void ui_mgr::do_menu_command(int cmd) +bool ui_mgr::do_menu_command(int cmd) { + bool holdui = false; + if(handler_.count(cmd)) - handler_[cmd](cur_, cmd); + holdui = handler_[cmd](cur_, cmd); // at last, we return to main menu OR parent ? - cur_->release(); - cur_ = root_; // main menu - cur_->add_ref(); + if(!holdui) + { + cur_->release(); + cur_ = root_; // main menu + cur_->add_ref(); + } + + return holdui; } void ui_mgr::init(void) { @@ -287,8 +337,29 @@ void ui_mgr::init(void) { child = new dev_menu(true); child->add_menu(WORDS_MENU_LOW, MENU_CMD_ID_SEPARATE_LOW); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_SEPARATE_LOW] = f; + } child->add_menu(WORDS_MENU_MID, MENU_CMD_ID_SEPARATE_MID); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_SEPARATE_MID] = f; + } child->add_menu(WORDS_MENU_HIGH, MENU_CMD_ID_SEPARATE_HIGH); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_SEPARATE_HIGH] = f; + } child->select(WORDS_MENU_MID); root_->add_menu(WORDS_MENU_SEPARATE_STRENGTH, child); child->release(); @@ -297,14 +368,77 @@ void ui_mgr::init(void) { child = new dev_menu(true); child->add_menu(WORDS_MENU_SLEEP_NONE, MENU_CMD_ID_SLEEP_NEVER); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_SLEEP_NEVER] = f; + } child->add_menu(WORDS_MENU_SLEEP_NOW, MENU_CMD_ID_SLEEP_IMMEDIATELY); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_SLEEP_IMMEDIATELY] = f; + } child->add_menu(WORDS_MENU_SLEEP_5_MIN, MENU_CMD_ID_SLEEP_5MIN); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_SLEEP_5MIN] = f; + } child->add_menu(WORDS_MENU_SLEEP_10_MIN, MENU_CMD_ID_SLEEP_10MIN); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_SLEEP_10MIN] = f; + } child->add_menu(WORDS_MENU_SLEEP_20_MIN, MENU_CMD_ID_SLEEP_20MIN); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_SLEEP_20MIN] = f; + } child->add_menu(WORDS_MENU_SLEEP_30_MIN, MENU_CMD_ID_SLEEP_30MIN); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_SLEEP_30MIN] = f; + } child->add_menu(WORDS_MENU_SLEEP_1_HOUR, MENU_CMD_ID_SLEEP_1H); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_SLEEP_1H] = f; + } child->add_menu(WORDS_MENU_SLEEP_2_HOUR, MENU_CMD_ID_SLEEP_2H); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_SLEEP_2H] = f; + } child->add_menu(WORDS_MENU_SLEEP_4_HOUR, MENU_CMD_ID_SLEEP_4H); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_SLEEP_4H] = f; + } child->select(WORDS_MENU_SLEEP_NONE); root_->add_menu(WORDS_MENU_POWER, child); child->release(); @@ -313,8 +447,29 @@ void ui_mgr::init(void) { child = new dev_menu(true); child->add_menu(WORDS_MENU_LOW, MENU_CMD_ID_LIFTER_LOW); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_LIFTER_LOW] = f; + } child->add_menu(WORDS_MENU_MID, MENU_CMD_ID_LIFTER_MID); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_LIFTER_MID] = f; + } child->add_menu(WORDS_MENU_HIGH, MENU_CMD_ID_LIFTER_HIGH); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_LIFTER_HIGH] = f; + } child->select(WORDS_MENU_LOW); root_->add_menu(WORDS_MENU_LIFTER_POS, child); child->release(); @@ -322,13 +477,72 @@ void ui_mgr::init(void) // 计数模式、手动模式、清理纸道、历史张数、滚轴张数、清除滚轴张数(确定,取消)、进入休眠、关机 root_->add_menu(WORDS_MENU_COUNT_MODE, MENU_CMD_ID_COUNT_MODE); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + // 保持界面:第一行显示当前保持的功能 + // 第二行显示当前功能的信息,过程中只更新该行 + // + // 任意按键的反应:第一行显示“退出当前功能” + // 第二行显示“确定”、“取消”,菜单键在此两项中跳转 + DISPDATA dd; + + memset(&dd, 0, sizeof(dd)); + disp_data_.save(dd, true); + + dd.cnt = get_string_font(WORDS_MENU_COUNT_MODE, dd.ptr, &dd.rows, &dd.cols); + disp_data_.save(dd, true); + + dd.y = dd.rows; + dd.cnt = get_string_font(WORDS_FUNCTION_COUNT, dd.ptr, &dd.rows, &dd.cols); + disp_data_.save(dd, true); + + return true; + }; + handler_[MENU_CMD_ID_COUNT_MODE] = f; + } root_->add_menu(WORDS_MENU_MANUAL_MODE, MENU_CMD_ID_HANDLE_MODE); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return true; + }; + handler_[MENU_CMD_ID_HANDLE_MODE] = f; + } root_->add_menu(WORDS_MENU_CLEAR_PASSWAY, MENU_CMD_ID_CLEAR_PASSWAY); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_CLEAR_PASSWAY] = f; + } root_->add_menu(WORDS_MENU_HISTORY_COUNT, MENU_CMD_ID_GET_HISTORY_COUNT); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_GET_HISTORY_COUNT] = f; + } root_->add_menu(WORDS_MENU_ROLLER_COUNT, MENU_CMD_ID_GET_ROLLER_COUNT); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_GET_ROLLER_COUNT] = f; + } { child = new dev_menu(false, false); child->add_menu(WORDS_MENU_YES, MENU_CMD_ID_CLEAR_ROLLER_CNT); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + return false; + }; + handler_[MENU_CMD_ID_CLEAR_ROLLER_CNT] = f; + } child->add_menu(WORDS_MENU_NO, MENU_CMD_ID_CANCEL); root_->add_menu(WORDS_MENU_RESET_ROLLOER_CNT, child); child->release(); @@ -336,11 +550,39 @@ void ui_mgr::init(void) { child = new dev_menu(false, false); child->add_menu(WORDS_MENU_YES, MENU_CMD_ID_SHUTDOWN); - child->add_menu(WORDS_MENU_NO, MENU_CMD_ID_CANCEL); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + system("poweroff"); + + return false; + }; + handler_[MENU_CMD_ID_SHUTDOWN] = f; + } + child->add_menu(WORDS_MENU_NO, MENU_CMD_ID_CANCEL); root_->add_menu(WORDS_MENU_SHUTDOWN, child); child->release(); } + root_->add_menu(WORDS_MENU_WELCOME, MENU_CMD_ID_WELCOME); + { + auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + DISPDATA dd; + dd.mask = 0; + dd.x = 0; + dd.y = 0; + dd.rows = welcome[1]; + dd.cols = welcome[0]; + dd.cnt = 1; + dd.ptr[0] = welcome + 2; + disp_data_.save(dd, true); + + return false; + }; + handler_[MENU_CMD_ID_WELCOME] = f; + } + cur_ = root_; cur_->add_ref(); } @@ -392,7 +634,7 @@ void ui_mgr::refresh_lcd(bool cur_at_top) dd.y = rows; dd.rows = font_size_.cy; dd.cols = font_size_.cx; - dd.cnt = get_string_font(disp[i].c_str(), dd.ptr); + dd.cnt = get_string_font(disp[i].c_str(), dd.ptr, &dd.rows, &dd.cols); cur = disp_data_.save(dd, true); rows += font_size_.cy; } @@ -418,6 +660,9 @@ void ui_mgr::enter(void) cur_ = root_; if(cur_) cur_->add_ref(); + refresh_lcd(true); + + return; } if(cur_) @@ -429,7 +674,8 @@ void ui_mgr::enter(void) bef->release(); if(id != -1) { - do_menu_command(id); + bool holdui = do_menu_command(id); + set_ready_status_enabled(!holdui); } if(cur_ != bef) { @@ -438,7 +684,7 @@ void ui_mgr::enter(void) } } } -int ui_mgr::get_string_font(const char* text, uint8_t** ptr) +int ui_mgr::get_string_font(const char* text, uint8_t** ptr, uint8_t* rows, uint8_t* cols) { DISPDATA dd; int cnt = 0, ind = 0; @@ -457,7 +703,7 @@ int ui_mgr::get_string_font(const char* text, uint8_t** ptr) { ind += 3; } - ptr[cnt] = get_font_data(utf8) + 2; // skip height and widht data + ptr[cnt] = get_font_data(utf8, rows, cols) + 2; // skip height and widht data } return cnt; @@ -466,20 +712,65 @@ int ui_mgr::get_string_font(const char* text, uint8_t** ptr) void ui_mgr::thread_display(void) { DISPDATA dd; + bool first = true; + + // welcome + { + uint8_t *ptr[] = {welcome + 2}; + lcd_->write_line(welcome[1], welcome[0], 1, ptr); + std::this_thread::sleep_for(std::chrono::seconds(10)); + } + while(run_) { - if(disp_data_.take(dd, true)) + if(disp_data_.take(dd, true, SEC_2_MS(3))) { if(dd.cnt) lcd_->write_line(dd.rows, dd.cols, dd.cnt, dd.ptr, dd.x, dd.y, dd.mask); else lcd_->clear(); } + else if(ready_enable_) + { + int elapse = first ? 10 : get_ready_watch_ms() / SEC_2_MS(1); + + first = false; + if(elapse >= 3) + display_ready(); + } } } +void ui_mgr::display_ready(void) +{ + set_ready_status_enabled(false); + + menu_mode_ = false; + lcd_->clear(); + + lcd_->write_line(ready_.rows, ready_.cols, ready_.cnt, ready_.ptr, ready_.x, ready_.y, ready_.mask); +} +void ui_mgr::set_ready_status_enabled(bool enable) +{ + SIMPLE_LOCK(ready_lck_); + + ready_enable_ = enable; +} +void ui_mgr::reset_ready_watch(void) +{ + SIMPLE_LOCK(ready_lck_); + ready_watch_.reset(); +} +int ui_mgr::get_ready_watch_ms(void) +{ + SIMPLE_LOCK(ready_lck_); + + return ready_watch_.elapse_ms(); +} void ui_mgr::key_event(int key) { + reset_ready_watch(); + if(key == (int)KeyMonitor::HGKey::Key_Menu) enter(); else if(key == (int)KeyMonitor::HGKey::Key_Left) diff --git a/ui/dev_menu.h b/ui/dev_menu.h index 46cea07..c1fac06 100644 --- a/ui/dev_menu.h +++ b/ui/dev_menu.h @@ -24,7 +24,7 @@ #define MENU_ID_RETURN -1 // ID of menu item that return to parent #define LINK_DEFINE(x, y) x##y #define MEMNU_CMD_HANDLER_PARAM dev_menu* menu, int id -#define MENU_CMD_HANDLER_RET void +#define MENU_CMD_HANDLER_RET bool #define MENU_CMD_CALLBACK std::function class dev_menu : public refer @@ -92,19 +92,20 @@ class ui_mgr : public refer dev_menu* cur_ = nullptr; volatile bool menu_mode_ = false; // whether LCD is displaying menu volatile bool run_ = true; + volatile bool ready_enable_ = true; SIZE font_size_ = {16, 16}; std::map handler_; std::unique_ptr lcd_; std::unique_ptr keyboard_; - void do_menu_command(int cmd); + bool do_menu_command(int cmd); // return whether should hold UI ? void init(void); void clear(void); void refresh_lcd(bool cur_at_top); void move_to(bool next); void enter(void); - int get_string_font(const char* text, uint8_t** ptr); + int get_string_font(const char* text, uint8_t** ptr, uint8_t* rows, uint8_t* cols); typedef struct _disp_data { @@ -116,9 +117,17 @@ class ui_mgr : public refer uint8_t mask; uint8_t *ptr[16]; }DISPDATA; - safe_fifo disp_data_; + + MUTEX ready_lck_; + chronograph ready_watch_; + DISPDATA ready_; + safe_fifo disp_data_; std::unique_ptr disp_thrd_; void thread_display(void); + void display_ready(void); + void set_ready_status_enabled(bool enable); + void reset_ready_watch(void); + int get_ready_watch_ms(void); public: ui_mgr(); diff --git a/ui/font.cpp b/ui/font.cpp index 9224259..2c025c6 100644 --- a/ui/font.cpp +++ b/ui/font.cpp @@ -22,6 +22,42 @@ class font_init public: font_init() { +static uint8_t huan[] = {16, 16 + , 0x00, 0x00, 0x00, 0x40, 0xE0, 0xE0, 0xE0, 0xC0, 0xC4, 0xFE, 0xFC, 0xE8, 0xE0, 0xE0, 0x00, 0x00 + , 0x00, 0x00, 0x19, 0x1B, 0x0F, 0x07, 0x2F, 0x10, 0x1D, 0x0F, 0x05, 0x0D, 0x18, 0x18, 0x30, 0x20 + }; +font_map_["\346\254\242"] = huan; + +static uint8_t ying[] = {16, 16 + , 0x00, 0x40, 0xE8, 0xF8, 0xD0, 0x18, 0xF8, 0xFC, 0xCE, 0x3C, 0xF8, 0x98, 0xF8, 0xF8, 0x00, 0x00 + , 0x00, 0x00, 0x08, 0x0B, 0x0F, 0x0C, 0x09, 0x09, 0x08, 0x18, 0x3F, 0x31, 0x31, 0x30, 0x30, 0x10 + }; +font_map_["\350\277\216"] = ying; + +static uint8_t jiu[] = {32, 32 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0xF8, 0xF8, 0xF0, 0xF0 + , 0xE0, 0x80, 0x00, 0x00, 0x60, 0xB0, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x0C, 0x1C, 0x1C, 0x1E, 0xCE, 0xF6, 0xEF, 0x77, 0x77, 0xBF, 0xFB, 0xFB, 0xFB + , 0xF1, 0xB1, 0xC1, 0xE0, 0xF8, 0xFF, 0xFF, 0x77, 0x7C, 0x38, 0x18, 0x1A, 0x07, 0x07, 0x07, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE1, 0xC7, 0x4F, 0x0F, 0xFF, 0xFF, 0x3F, 0x63, 0xE3 + , 0xE1, 0xFD, 0x3F, 0x0F, 0xE3, 0xFD, 0x3F, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x03, 0x00, 0x02, 0x06, 0x1F, 0x1F, 0x00, 0x00, 0x03 + , 0x03, 0x00, 0x00, 0x03, 0x0F, 0x0F, 0x1E, 0x1C, 0x1C, 0x1C, 0x1C, 0x1E, 0x0E, 0x0F, 0x0F, 0x06 + }; +font_map_["\345\260\261"] = jiu; + +static uint8_t xu[] = {32, 32 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xF8, 0xF8, 0xF0, 0xE0, 0x80 + , 0x00, 0x00, 0x01, 0x83, 0xFF, 0xFF, 0xFF, 0xCC, 0xC0, 0x80, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x18, 0x7C, 0x7E, 0x3E, 0xDF, 0xFF, 0xFF, 0xFF, 0xF3, 0x81, 0x81, 0x83 + , 0xC7, 0xCF, 0xFF, 0xFF, 0xFF, 0xEF, 0xF7, 0x7B, 0x7F, 0x7F, 0x7F, 0x77, 0x73, 0x70, 0x40, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0xCF, 0xFF, 0xFF, 0x3F, 0x07, 0x87, 0xE3, 0x73 + , 0x79, 0xFD, 0xFE, 0xFF, 0xDF, 0xFF, 0xCE, 0x7E, 0xFE, 0xFC, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1F, 0x1F, 0x07, 0x02, 0x01, 0x01, 0x00, 0x00 + , 0x00, 0x07, 0x0F, 0x0F, 0x0E, 0x06, 0x1E, 0x7C, 0xFF, 0x7F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00 + }; +font_map_["\347\273\252"] = xu; + static uint8_t right[] = {16, 16 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x3C, 0x04, 0x00 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x06, 0x1C, 0x30, 0x78, 0x0F, 0x01, 0x00, 0x00, 0x00 @@ -388,19 +424,29 @@ font_map_["\345\215\263"] = ji4s; ~font_init() {} - uint8_t* get_font_data(const char* str) + uint8_t* get_font_data(const char* str, uint8_t* rows, uint8_t* cols) { if(font_map_.count(str)) { + if(rows) + *rows = font_map_[str][1]; + if(cols) + *cols = font_map_[str][0]; + return font_map_[str]; } + if(rows) + *rows = font_data::question[1]; + if(cols) + *cols = font_data::question[0]; + return font_data::question; } }; static font_init g_fi_; -uint8_t* get_font_data(const char* str) +uint8_t* get_font_data(const char* str, uint8_t* rows, uint8_t* cols) { - return g_fi_.get_font_data(str); + return g_fi_.get_font_data(str, rows, cols); } diff --git a/ui/font.h b/ui/font.h index a69e546..689bbce 100644 --- a/ui/font.h +++ b/ui/font.h @@ -4,4 +4,4 @@ #pragma once #include -uint8_t* get_font_data(const char* str); +uint8_t* get_font_data(const char* str, uint8_t* rows, uint8_t* cols); diff --git a/xmake.lua b/xmake.lua index 880f2ee..503dc4b 100644 --- a/xmake.lua +++ b/xmake.lua @@ -60,8 +60,8 @@ add_packagedirs("sdk") add_defines("BUILD_AS_DEVICE") add_defines("VER_MAIN=2") add_defines("VER_FAMILY=200") -add_defines("VER_DATE=20240204") -add_defines("VER_BUILD=8") +add_defines("VER_DATE=20240205") +add_defines("VER_BUILD=15") target("conf") set_kind("phony")