From 19e006a1329079da64cb56de3e0ae9f9a6492316 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Thu, 22 Feb 2024 15:20:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B0=83=E6=95=B4=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=97=B6=E9=97=B4=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdk/base/words.cpp | 3 ++ sdk/base/words.h | 3 ++ ui/dev_menu.cpp | 111 +++++++++++++++++++++++++++++++++++++++++++-- ui/dev_menu.h | 6 ++- ui/font.cpp | 80 +++++++++++++++++++++++--------- xmake.lua | 2 +- 6 files changed, 177 insertions(+), 28 deletions(-) diff --git a/sdk/base/words.cpp b/sdk/base/words.cpp index 880d6d2..40e67d7 100644 --- a/sdk/base/words.cpp +++ b/sdk/base/words.cpp @@ -52,6 +52,9 @@ WORDS_AND_ID_IMPL(WORDS_MENU_CLEAR_PASSWAY, "\346\270\205\347\220\206\347 WORDS_AND_ID_IMPL(WORDS_MENU_HISTORY_COUNT, "\345\216\206\345\217\262\345\274\240\346\225\260"); WORDS_AND_ID_IMPL(WORDS_MENU_ROLLER_COUNT, "\346\273\232\350\275\264\345\274\240\346\225\260"); WORDS_AND_ID_IMPL(WORDS_MENU_RESET_ROLLOER_CNT, "\346\270\205\351\231\244\346\273\232\350\275\264\345\274\240\346\225\260"); +WORDS_AND_ID_IMPL(WORDS_MENU_ADJUST_TIME, "\350\260\203\346\225\264\347\263\273\347\273\237\346\227\266\351\227\264"); +WORDS_AND_ID_IMPL(WORDS_MENU_ADJUST_HOUR, "\346\227\266\351\222\237"); +WORDS_AND_ID_IMPL(WORDS_MENU_ADJUST_MINUTE, "\345\210\206\351\222\237"); WORDS_AND_ID_IMPL(WORDS_MENU_SHUTDOWN, "\345\205\263\346\234\272"); WORDS_AND_ID_IMPL(WORDS_MENU_YES, "\347\241\256\345\256\232"); WORDS_AND_ID_IMPL(WORDS_MENU_NO, "\345\217\226\346\266\210"); diff --git a/sdk/base/words.h b/sdk/base/words.h index 7ca3033..fa3e970 100644 --- a/sdk/base/words.h +++ b/sdk/base/words.h @@ -65,6 +65,9 @@ WORDS_AND_ID_DECL(WORDS_MENU_CLEAR_PASSWAY); WORDS_AND_ID_DECL(WORDS_MENU_HISTORY_COUNT); WORDS_AND_ID_DECL(WORDS_MENU_ROLLER_COUNT); WORDS_AND_ID_DECL(WORDS_MENU_RESET_ROLLOER_CNT); +WORDS_AND_ID_DECL(WORDS_MENU_ADJUST_TIME); +WORDS_AND_ID_DECL(WORDS_MENU_ADJUST_HOUR); +WORDS_AND_ID_DECL(WORDS_MENU_ADJUST_MINUTE); WORDS_AND_ID_DECL(WORDS_MENU_SHUTDOWN); WORDS_AND_ID_DECL(WORDS_MENU_YES); WORDS_AND_ID_DECL(WORDS_MENU_NO); diff --git a/ui/dev_menu.cpp b/ui/dev_menu.cpp index 3b8c5e8..18edac2 100644 --- a/ui/dev_menu.cpp +++ b/ui/dev_menu.cpp @@ -145,7 +145,7 @@ bool dev_menu::move_to(bool next) return ret; } -bool dev_menu::select(const char* txt) +bool dev_menu::select(const char* txt, bool apply_cur) { int ind = find_item(txt); @@ -153,17 +153,26 @@ bool dev_menu::select(const char* txt) return false; sel_ = ind; + if(apply_cur) + cur_ = sel_; return true; } void dev_menu::reset_pos(void) { - cur_ = sel_ == -1 ? init_pos_ : sel_; + if(reset_pos_) + reset_pos_(this); + else + cur_ = sel_ == -1 ? init_pos_ : sel_; } void dev_menu::set_default_pos(int pos) { init_pos_ = pos; } +void dev_menu::set_default_pos(std::function f) +{ + reset_pos_ = f; +} dev_menu* dev_menu::enter(int* id) { @@ -249,6 +258,9 @@ namespace menu_command MENU_CMD_ID_SHUTDOWN = 0x90, MENU_CMD_ID_WELCOME = 0xa0, + + MENU_CMD_ID_SEQ_0 = 0x1000, + MENU_CMD_ID_SEQ_LAST = 0x7FFF, }; static std::string command_string(int cmd) @@ -554,7 +566,12 @@ bool ui_mgr::do_menu_command(int cmd) utils::to_log(LOG_LEVEL_DEBUG, "Do menu command: %s\n", menu_command::command_string(cmd).c_str()); - if(handler_.count(cmd)) + if(cmd >= menu_command::MENU_CMD_ID_SEQ_0 && cmd <= menu_command::MENU_CMD_ID_SEQ_LAST) + { + if(handler_.count(menu_command::MENU_CMD_ID_SEQ_0)) + holdui = handler_[menu_command::MENU_CMD_ID_SEQ_0](cur_, cmd - menu_command::MENU_CMD_ID_SEQ_0); + } + else if(handler_.count(cmd)) holdui = handler_[cmd](cur_, cmd); // at last, we return to main menu OR parent ? @@ -838,6 +855,92 @@ void ui_mgr::init(void) root_->add_menu(WORDS_MENU_LIFTER_POS, child); child->release(); } + // 调整系统时间 + { + auto adjtm = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET + { + int hour = -1, + min = -1; + + if(id < seq_hour_) + { + hour = id; + } + else if(id < seq_min_) + { + min = id - seq_hour_; + } + if(hour != -1 || min != -1) + { + // adjust system time here ... (date -s "2022-01-01 09:30:00") + time_t t = time(nullptr); + struct tm* l = localtime(&t); + char cmd[40] = {0}; + + if(hour == -1) + hour = l->tm_hour; + if(min == -1) + min = l->tm_min; + sprintf(cmd, "date -s \"%04d-%02d-%02d %02d:%02d:%02d\"" + , l->tm_year + 1900, l->tm_mon + 1, l->tm_mday + , hour, min, l->tm_sec); + system(cmd); + } + + return false; + }; + handler_[menu_command::MENU_CMD_ID_SEQ_0] = adjtm; + + dev_menu* clck = new dev_menu(); + child = new dev_menu(); + + for(int i = 0; i < 24; ++i) + { + char text[20] = {0}; + + sprintf(text, "%02d", i); + clck->add_menu(text, menu_command::MENU_CMD_ID_SEQ_0 + i); + } + auto h = [&](dev_menu* obj) -> void + { + time_t t = time(nullptr); + char text[20] = {0}; + + t /= 3600; + t %= 24; + sprintf(text, "%02d", t); + obj->select(text, true); + }; + clck->set_default_pos(h); + child->add_menu(WORDS_MENU_ADJUST_HOUR, clck); + clck->release(); + + clck = new dev_menu(); + for(int i = 0; i < 60; ++i) + { + char text[20] = {0}; + + sprintf(text, "%02d", i); + clck->add_menu(text, menu_command::MENU_CMD_ID_SEQ_0 + i + seq_hour_); + } + auto m = [&](dev_menu* obj) -> void + { + time_t t = time(nullptr); + char text[20] = {0}; + + t /= 60; + t %= 60; + sprintf(text, "%02d", t); + obj->select(text, true); + }; + clck->set_default_pos(m); + child->add_menu(WORDS_MENU_ADJUST_MINUTE, clck); + clck->release(); + + root_->add_menu(WORDS_MENU_ADJUST_TIME, child); + child->release(); + } + // 关机 { child = new dev_menu(false, false); child->add_menu(WORDS_MENU_YES, menu_command::MENU_CMD_ID_SHUTDOWN); @@ -1044,7 +1147,7 @@ void ui_mgr::display_ready(bool time_only) memset(&dd, 0, sizeof(dd)); dd.cnt = custom_font::get_string_font(now.c_str(), dd.ptr, custom_font::FONT_SIZE_8); - dd.x = Lcd::LCD_WIDTH - 30; + dd.x = Lcd::LCD_WIDTH - (dd.ptr[0][0] + 1) * dd.cnt; dd.y = 8; lcd_->write_line(dd.ptr, dd.cnt, dd.x, dd.y, dd.mask); } diff --git a/ui/dev_menu.h b/ui/dev_menu.h index f74e6ea..16c4d3d 100644 --- a/ui/dev_menu.h +++ b/ui/dev_menu.h @@ -48,6 +48,7 @@ class dev_menu : public refer int sel_ = -1; // current checked item bool check_item_ = false; bool need_ret_parent_ = true; + std::function reset_pos_ = std::function(); int find_item(const char* text); @@ -65,9 +66,10 @@ public: bool remove_menu(const char* text); void set_need_return_parent(bool need); bool move_to(bool next); // true - move to next, false - move to previous. if at end position of move direction, return false - bool select(const char* txt); + bool select(const char* txt, bool apply_cur = false); void reset_pos(void); void set_default_pos(int pos = 0); + void set_default_pos(std::function f); // Function: access current menu // @@ -93,6 +95,8 @@ class ui_mgr : public refer { dev_menu* root_ = nullptr; dev_menu* cur_ = nullptr; + const int seq_hour_ = 24; + const int seq_min_ = 84; volatile bool menu_mode_ = false; // whether LCD is displaying menu volatile bool run_ = true; volatile bool ready_enable_ = true; diff --git a/ui/font.cpp b/ui/font.cpp index 81ac21b..a9e6733 100644 --- a/ui/font.cpp +++ b/ui/font.cpp @@ -24,58 +24,58 @@ namespace custom_font void init_8x8(void) { - static uint8_t colon[] = {5, 8 - , 0x00, 0x00, 0x28, 0x00, 0x00 + static uint8_t colon[] = {3, 8 + , 0x00, 0x28, 0x00 }; font_map8x8_["\072\000\000"] = colon; - static uint8_t num0[] = {5, 8 - , 0x00, 0x7C, 0x44, 0x7C, 0x00 + static uint8_t num0[] = {4, 8 + , 0x00, 0x7C, 0x44, 0x7C }; font_map8x8_["\060\000\000"] = num0; - static uint8_t num1[] = {5, 8 - , 0x00, 0x44, 0x7C, 0x40, 0x00 + static uint8_t num1[] = {4, 8 + , 0x00, 0x44, 0x7C, 0x40 }; font_map8x8_["\061\000\000"] = num1; - static uint8_t num2[] = {5, 8 - , 0x00, 0x6C, 0x54, 0x4C, 0x00 + static uint8_t num2[] = {4, 8 + , 0x00, 0x6C, 0x54, 0x4C }; font_map8x8_["\062\000\000"] = num2; - static uint8_t num3[] = {5, 8 - , 0x00, 0x44, 0x54, 0x7C, 0x00 + static uint8_t num3[] = {4, 8 + , 0x00, 0x44, 0x54, 0x7C }; font_map8x8_["\063\000\000"] = num3; - static uint8_t num4[] = {5, 8 - , 0x20, 0x30, 0x7C, 0x20, 0x00 + static uint8_t num4[] = {4, 8 + , 0x20, 0x30, 0x7C, 0x20 }; font_map8x8_["\064\000\000"] = num4; - static uint8_t num5[] = {5, 8 - , 0x00, 0x5C, 0x54, 0x74, 0x00 + static uint8_t num5[] = {4, 8 + , 0x00, 0x5C, 0x54, 0x74 }; font_map8x8_["\065\000\000"] = num5; - static uint8_t num6[] = {5, 8 - , 0x00, 0x54, 0x54, 0x74, 0x00 + static uint8_t num6[] = {4, 8 + , 0x00, 0x7C, 0x54, 0x74 }; font_map8x8_["\066\000\000"] = num6; - static uint8_t num7[] = {5, 8 - , 0x00, 0x44, 0x74, 0x0C, 0x00 + static uint8_t num7[] = {4, 8 + , 0x00, 0x44, 0x74, 0x0C }; font_map8x8_["\067\000\000"] = num7; - static uint8_t num8[] = {5, 8 - , 0x00, 0x7C, 0x54, 0x7C, 0x00 + static uint8_t num8[] = {4, 8 + , 0x00, 0x7C, 0x54, 0x7C }; font_map8x8_["\070\000\000"] = num8; - static uint8_t num9[] = {5, 8 - , 0x00, 0x5C, 0x54, 0x3C, 0x00 + static uint8_t num9[] = {4, 8 + , 0x00, 0x5C, 0x54, 0x3C }; font_map8x8_["\071\000\000"] = num9; @@ -602,6 +602,42 @@ namespace custom_font }; font_map_["\346\227\240"] = wu; + static uint8_t diao[] = {16, 16 + , 0x00, 0x00, 0x40, 0x42, 0xCC, 0x0C, 0x00, 0x02, 0xFE, 0x82, 0x92, 0xFE, 0xFE, 0x92, 0x92, 0xFE + , 0x00, 0x00, 0x00, 0x40, 0x7F, 0x20, 0x90, 0x78, 0x1F, 0x00, 0x3E, 0x12, 0x92, 0xBE, 0x80, 0xFF + }; + font_map_["\350\260\203"] = diao; + + static uint8_t zheng3[] = {16, 16 + , 0x00, 0x00, 0x04, 0xFC, 0xCC, 0xFF, 0xFF, 0x4C, 0x7C, 0x24, 0x18, 0x1F, 0xE5, 0xE4, 0x3C, 0x0C + , 0x00, 0x04, 0x82, 0x82, 0x85, 0xF7, 0x97, 0x85, 0x87, 0xFE, 0x95, 0x95, 0x94, 0x94, 0x95, 0x83 + }; + font_map_["\346\225\264"] = zheng3; + + static uint8_t xi[] = {16, 16 + , 0x00, 0x00, 0x00, 0x04, 0x40, 0x60, 0x70, 0x52, 0x8E, 0xE6, 0x66, 0x62, 0xB2, 0x13, 0x03, 0x00 + , 0x00, 0x00, 0x80, 0xC0, 0x66, 0x36, 0x1F, 0x9B, 0x82, 0xFE, 0xFE, 0x0A, 0x0A, 0x13, 0x33, 0xE6 + }; + font_map_["\347\263\273"] = xi; + + static uint8_t tong[] = {16, 16 + , 0x00, 0x00, 0x60, 0x38, 0xAE, 0x63, 0x30, 0x10, 0x84, 0xC4, 0xB4, 0x9F, 0x8E, 0xA4, 0xE4, 0xC4 + , 0x00, 0x00, 0x66, 0x27, 0x32, 0x12, 0x12, 0x02, 0x81, 0x60, 0x3E, 0x00, 0x00, 0xFF, 0x80, 0x80 + }; + font_map_["\347\273\237"] = tong; + + static uint8_t jian1[] = {16, 16 + , 0x00, 0x00, 0xFC, 0xFC, 0x03, 0x06, 0xE0, 0xE2, 0x22, 0x22, 0x22, 0xE2, 0x02, 0x02, 0x02, 0xFE + , 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x1F, 0x1F, 0x09, 0x09, 0x09, 0x1F, 0x80, 0x80, 0x80, 0xFF + }; + font_map_["\351\227\264"] = jian1; + + static uint8_t zhong1[] = {16, 16 + , 0x00, 0x80, 0x60, 0x7E, 0xCF, 0x48, 0x48, 0x48, 0x30, 0xF0, 0x10, 0x10, 0xFF, 0x10, 0x10, 0xF0 + , 0x00, 0x02, 0x02, 0x02, 0xFF, 0x42, 0x22, 0x12, 0x06, 0x07, 0x02, 0x02, 0xFF, 0x02, 0x02, 0x07 + }; + font_map_["\351\222\237"] = zhong1; + } ~font_init() {} diff --git a/xmake.lua b/xmake.lua index e046b07..5a17d55 100644 --- a/xmake.lua +++ b/xmake.lua @@ -61,7 +61,7 @@ add_defines("BUILD_AS_DEVICE") add_defines("VER_MAIN=2") add_defines("VER_FAMILY=200") add_defines("VER_DATE=20240222") -add_defines("VER_BUILD=17") +add_defines("VER_BUILD=19") target("conf") set_kind("phony")