From: luozheng <1732036298@qq.com> Date: Sat, 7 Sep 2024 04:31:56 +0000 (+0800) Subject: #511,解决,Al说话界面和分析界面会熄屏bug X-Git-Tag: release_V1.2.70_20241020_135402~524^2~9 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=da41e9be5ac1849517e5ce80953432357c5d0602;p=mirrors%2FFD230.git #511,解决,Al说话界面和分析界面会熄屏bug --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h index ddee102c4..ded12eb54 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:14:43 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-31 16:14:37 + * @LastEditTime: 2024-09-07 11:14:50 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h */ #ifndef AI_VOICE_MODEL_H @@ -93,6 +93,11 @@ namespace OHOS void AIVoice_StartTimer(uint32_t interval = 1000); void AIVoice_StopTimer(void); + void ai_start_screen60s_timer(uint32_t interval = 30*1000); + void ai_stop_screen60s_timer(void); + void reset_ai_screen60s_timer_time(); + + void SetSelectAiModel(int index); int GetSelectAiModel(void); int GetAiModelTextId(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp index 3e03713cd..c37c1ab07 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:14:50 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-31 16:13:29 + * @LastEditTime: 2024-09-07 12:04:07 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp */ #include "aivoice/include/AiVoiceModel.h" @@ -27,7 +27,7 @@ namespace OHOS { // 声明定时器变量 - static osTimerId_t g_timer = NULL; + static osTimerId_t g_timer = nullptr; static constexpr uint16_t THIRTY_TIME = 31; static int Time = THIRTY_TIME; static int AiModelConnectTimeout = 5; @@ -105,7 +105,7 @@ namespace OHOS const std::string filePath = "/user/userdata/AiRecording/AIAudio.pcm"; // Check if file exists FILE *file = fopen(filePath.c_str(), "r"); - if (file != NULL) + if (file != nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "File already exists: %s", filePath.c_str()); fclose(file); @@ -114,7 +114,7 @@ namespace OHOS // File does not exist, create it file = fopen(filePath.c_str(), "w"); - if (file == NULL) + if (file == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to create file: %s", filePath.c_str()); return false; @@ -706,16 +706,16 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::AIVoice_StartTimer"); /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_timer != NULL) + if (g_timer != nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); return; } /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_timer = osTimerNew((osTimerFunc_t)AIVoice_TimerCallback, osTimerPeriodic, NULL, NULL); + g_timer = osTimerNew((osTimerFunc_t)AIVoice_TimerCallback, osTimerPeriodic, nullptr, nullptr); // 检查定时器创建是否成功 - if (g_timer == NULL) + if (g_timer == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); return; @@ -726,15 +726,15 @@ namespace OHOS /* --------------------------------- 4.启动定时器 -------------------------------- */ osStatus_t ret = osTimerStart(g_timer, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */ + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ if (ret != osOK) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - if (g_timer != NULL) + if (g_timer != nullptr) { ret = osTimerDelete(g_timer); } - g_timer = NULL; + g_timer = nullptr; return; } } @@ -745,21 +745,102 @@ namespace OHOS void AiVoiceModel::AIVoice_StopTimer(void) { // 检查定时器是否存在 - if (g_timer != NULL) + if (g_timer != nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::AIVoice_StopTimer"); - // 删除定时器并置为 NULL + // 删除定时器并置为 nullptr osStatus_t ret = osTimerDelete(g_timer); if (ret != osOK) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); } - g_timer = NULL; + g_timer = nullptr; Time = THIRTY_TIME; AiModelConnectTimeout = 5; } } + // 声明定时器变量 + static osTimerId_t g_screen60s_timer = nullptr; + static uint16_t SCREEN_60S_TIME = 60; + + static void ai_start_screen60s_timer_callbackProc(int data) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ai_start_screen60s_timer_callbackProc,time = %d", SCREEN_60S_TIME); + SCREEN_60S_TIME -= 30; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ai_start_screen60s_timer_callbackProc,time = %d", SCREEN_60S_TIME); + if (SCREEN_60S_TIME <= 0) + { + // 60s后息屏停止定时 + AiVoiceModel::GetInstance().ai_stop_screen60s_timer(); + // 取消常亮屏 + ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); + } + } + static void ai_start_screen60s_timer_callback(int data) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(ai_start_screen60s_timer_callbackProc, data)); + } + void AiVoiceModel::ai_start_screen60s_timer(uint32_t interval) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ai_start_screen60s_timer"); + /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ + if (g_screen60s_timer != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); + return; + } + /* --------------------------------- 2.创建定时器 -------------------------------- */ + g_screen60s_timer = osTimerNew((osTimerFunc_t)ai_start_screen60s_timer_callback, osTimerPeriodic, nullptr, nullptr); + // 检查定时器创建是否成功 + if (g_screen60s_timer == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); + return; + } + /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ + int tick = osMs2Tick(interval); + /* --------------------------------- 4.启动定时器 -------------------------------- */ + osStatus_t ret = osTimerStart(g_screen60s_timer, tick); + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); + if (g_screen60s_timer != nullptr) + { + ret = osTimerDelete(g_screen60s_timer); + } + g_screen60s_timer = nullptr; + return; + } + } + void AiVoiceModel::ai_stop_screen60s_timer(void) + { + // 检查定时器是否存在 + if (g_screen60s_timer != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ai_stop_screen60s_timer"); + // 删除定时器并置为 nullptr + osStatus_t ret = osTimerDelete(g_screen60s_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); + } + g_screen60s_timer = nullptr; + SCREEN_60S_TIME = 60; + } + } + void AiVoiceModel::reset_ai_screen60s_timer_time() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "reset_ai_screen60s_timer_time"); + SCREEN_60S_TIME = 60; + if (nullptr == g_screen60s_timer) + { + ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 重新常亮屏 + ai_start_screen60s_timer(); // 开启定时器 + } + } + // 设置选择的ai模型 void AiVoiceModel::SetSelectAiModel(int index) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp index 40ccaab12..aa377a509 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:11:17 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-31 16:13:34 + * @LastEditTime: 2024-09-07 12:30:56 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp */ #include "AppViewIDs.h" @@ -55,7 +55,9 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStart"); Presenter::OnStart(); - // ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); + ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); + // 开启一个60s取消长亮屏timer + model->ai_start_screen60s_timer(); } // 页面已经展示后的调用逻辑 @@ -81,8 +83,9 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStop"); Presenter::OnStop(); - // ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); + ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); model->StatusResume(); + model->ai_stop_screen60s_timer(); } /*调转到返回结果界面*/ @@ -152,6 +155,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiModelsPresenter::index = %d", index); model->SetSelectAiModel(index); view_->ChangeAiModelAndUpdateComponentsStatus(); + model->reset_ai_screen60s_timer_time();//重置60s取消常亮屏timer return; } @@ -249,6 +253,8 @@ namespace OHOS { UNUSED(event); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnClick"); + + model->reset_ai_screen60s_timer_time();//重置60s取消常亮屏timer if (strcmp(view.GetViewId(), AIVOICE_IMGAE_VIEW_ID) == 0) /*点击的是Ai模型就切换模型*/ { @@ -268,9 +274,11 @@ namespace OHOS bool AiVoicePresenter::OnRelease(UIView &view, const ReleaseEvent &event) { UNUSED(event); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRelease"); std::string viewId = view.GetViewId(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRelease %s", viewId.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRelease %s", viewId.c_str()); + /* ----------------------------- 重置60s取消常亮屏timer ---------------------------- */ + model->reset_ai_screen60s_timer_time(); + /* -------------------------------------------------------------------------- */ if ((viewId == AIVOICE_CHAT_BUTTON_VIEW_ID) && model->IsExistOpenAIAPIKeys() == false) // 如果点击的是(对话按钮)且未配置apikey { @@ -347,7 +355,7 @@ namespace OHOS } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Return false if viewId doesn't match any entry in the map"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Return false if viewId doesn't match any entry in the map"); return false; } return true; @@ -373,6 +381,9 @@ namespace OHOS { return false; } + + model->reset_ai_screen60s_timer_time();//重置60s取消常亮屏timer + if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) /*左滑*/ { DragRightToLetfChangeAIModel(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp index 1af83f7a8..c2ef25578 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-31 14:32:02 + * @LastEditTime: 2024-09-07 12:12:53 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp */ #include "aivoice/include/AiVoicePresenter.h" @@ -460,7 +460,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::OnStart"); View::OnStart(); SetContainerView(new UIViewGroup()); - if (container_ == nullptr) + if (GetContainer() == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "container_ new fail!!"); return; diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/apikeys/ApiKeysPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/apikeys/ApiKeysPresenter.cpp index cc07de1d1..2b3b57b83 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/apikeys/ApiKeysPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/apikeys/ApiKeysPresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-07-29 16:14:16 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-15 18:26:04 + * @LastEditTime: 2024-09-07 12:19:09 * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/apikeys/ApiKeysPresenter.cpp */ @@ -43,6 +43,8 @@ namespace OHOS std::string viewId = view.GetViewId(); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysPresenter::OnClick ,viewId = %s", viewId.c_str()); + AiVoiceModel::GetInstance().reset_ai_screen60s_timer_time(); // 重置60s取消常亮屏timer + AiVoiceView *p_AiVoiceView = AiVoiceView::GetInstance(); std::map> viewMap = {