From 6e12d4b5416afad9f3253bdfede31e3bdd8dba01 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Sat, 27 Jul 2024 14:12:51 +0800 Subject: [PATCH] =?utf8?q?OBU=20Message=20Slice=20=E6=B7=BB=E5=8A=A0?= =?utf8?q?=E5=AE=9A=E6=97=B6=E5=99=A8=E6=9B=B4=E6=96=B0a5133=E6=95=B0?= =?utf8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../obumessage/include/OBUMessageModel.h | 4 +- .../obumessage/src/OBUMessageModel.cpp | 85 ++++++++++++++++++- .../obumessage/src/OBUMessagePresenter.cpp | 6 +- .../obumessage/src/OBUMessageView.cpp | 22 +++-- 4 files changed, 103 insertions(+), 14 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageModel.h b/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageModel.h index 95780ebc2..ac2fc98f6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-07-27 11:22:07 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-27 11:37:32 + * @LastEditTime: 2024-07-27 13:55:09 * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageModel.h * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ @@ -17,6 +17,8 @@ namespace OHOS public: static OBUMessageModel &GetInstance(void); void UpdateOBUMessageViewData(void); + void OBUMessage_StartTimer(int interval = 1000); + void OBUMessage_StopTimer(void); private: OBUMessageModel(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageModel.cpp index aa65d7a74..bbc880abf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-07-27 11:22:17 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-27 11:37:26 + * @LastEditTime: 2024-07-27 14:09:11 * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageModel.cpp * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ @@ -10,7 +10,9 @@ #include "obumessage/include/OBUMessageModel.h" #include "obumessage/include/OBUMessagePresenter.h" #include "wearable_log.h" - +#include +#include +#include namespace OHOS { OBUMessageModel::OBUMessageModel() {} @@ -31,4 +33,83 @@ namespace OHOS obuMessagePresenter->UpdateOBUMessageViewData(); } } + + // 声明定时器变量 + static osTimerId_t g_timer = NULL; + + /*定时器到期时的处理*/ + static void OBUMessage_TimerCallbackProc(int data) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OBUMessage_TimerCallbackProc"); + OBUMessageModel::GetInstance().UpdateOBUMessageViewData(); + } + + /* + * @brief 回调函数 + */ + static void OBUMessage_TimerCallback(int data) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(OBUMessage_TimerCallbackProc, data)); + } + + /* + * @brief 开启定时器函数 + * @param interval 时间间隔,单位ms + */ + void OBUMessageModel::OBUMessage_StartTimer(int interval) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OBUMessageViewEventListener::OBUMessage_StartTimer"); + /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ + if (g_timer != NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer already exists!!"); + return; + } + + /* --------------------------------- 2.创建定时器 -------------------------------- */ + g_timer = osTimerNew((osTimerFunc_t)OBUMessage_TimerCallback, osTimerPeriodic, NULL, NULL); + // 检查定时器创建是否成功 + if (g_timer == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer create failed!!"); + return; + } + + /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ + int tick = osMs2Tick(interval); + + /* --------------------------------- 4.启动定时器 -------------------------------- */ + osStatus_t ret = osTimerStart(g_timer, tick); + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */ + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_StartTimer] osTimerDelete failed, ret = %lx!!", ret); + if (g_timer != NULL) + { + ret = osTimerDelete(g_timer); + } + g_timer = NULL; + return; + } + return; + } + + /* + * @brief 停止定时器 + */ + void OBUMessageModel::OBUMessage_StopTimer(void) + { + // 检查定时器是否存在 + if (g_timer != NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OBUMessageViewEventListener::OBUMessage_StopTimer"); + // 删除定时器并置为 NULL + osStatus_t ret = osTimerDelete(g_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); + } + g_timer = NULL; + } + } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessagePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessagePresenter.cpp index 992bc8e5f..3deabbb9c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessagePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessagePresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:11:17 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-27 12:33:15 + * @LastEditTime: 2024-07-27 13:49:58 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/OBUMessagePresenter.cpp */ #include "AppViewIDs.h" @@ -12,7 +12,7 @@ #include "UiConfig.h" #include "obumessage/include/OBUMessagePresenter.h" #include "obumessage/include/OBUMessageView.h" - +#include "obumessage/include/OBUMessageModel.h" namespace OHOS { @@ -47,6 +47,7 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OBUMessagePresenter::OnStart"); Presenter::OnStart(); + OBUMessageModel::GetInstance().OBUMessage_StartTimer(); } // 页面已经展示后的调用逻辑 @@ -72,6 +73,7 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OBUMessagePresenter::OnStop"); Presenter::OnStop(); + OBUMessageModel::GetInstance().OBUMessage_StopTimer(); } bool OBUMessagePresenter::OnClick(UIView &view, const ClickEvent &event) diff --git a/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp index cd13b6613..a9b27d249 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp @@ -1,14 +1,16 @@ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 - * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-07-27 13:29:31 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-07-27 14:06:08 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp */ #include "obumessage/include/OBUMessagePresenter.h" #include "obumessage/include/OBUMessageView.h" #include "wearable_log.h" #include "custom_utils.h" +#include "iostream" +#include namespace OHOS { @@ -129,7 +131,7 @@ namespace OHOS displayTimeLabel->SetPosition(83, 0, 300, 35); displayTimeLabel->SetStyle(STYLE_TEXT_FONT, 30); displayTimeLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - displayTimeLabel->SetText("12:30:30"); + displayTimeLabel->SetText(""); displayTimeLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); displayTimeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); displayTimeLabel->SetRollSpeed(70); @@ -147,12 +149,12 @@ namespace OHOS } obuMessageLabel->SetPosition(53, 30, 360, 250); obuMessageLabel->SetStyle(STYLE_BORDER_RADIUS, 33); - obuMessageLabel->SetStyle(STYLE_TEXT_FONT, 30); - obuMessageLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - obuMessageLabel->SetText("OBU MESSAGE DATA"); + obuMessageLabel->SetStyle(STYLE_TEXT_FONT, 40); + obuMessageLabel->SetStyle(STYLE_LINE_HEIGHT, 45); + obuMessageLabel->SetText(""); obuMessageLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); obuMessageLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - obuMessageLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + obuMessageLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); group->Add(obuMessageLabel); viewInitStatus = true; } @@ -213,11 +215,13 @@ namespace OHOS return; } + static std::string labelTimeStr; + static std::string rxdataStr; + void OBUMessageView::UpdateOBUMessageViewDisplayData(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OBUMessageView::UpdateOBUMessageViewDisplayDate"); - std::string labelTimeStr; - std::string rxdataStr; + if (uapi_get_a5133_update_state()) { uint8_t rxdata[80] = {0}; -- 2.17.1