From 21723e07446d1f523ce737f3f14ff937e19b0a35 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Tue, 10 Mar 2026 15:11:16 +0800 Subject: [PATCH] =?utf8?q?=E5=80=92=E8=AE=A1=E6=97=B6=E5=88=B0=E6=9C=9F?= =?utf8?q?=E6=B7=BB=E5=8A=A0=E9=9C=87=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../countdown/include/CountDownModel.h | 5 ++ .../nativeui/countdown/src/CountDownModel.cpp | 88 +++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/include/CountDownModel.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/include/CountDownModel.h index 070b94240..41810b9da 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/include/CountDownModel.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/include/CountDownModel.h @@ -68,6 +68,11 @@ namespace OHOS public: static CountDownModel *GetInstance(); // shared_ptr:当没有引用指向这个实例时会自动释放内存 + //震动定时器 + void CountDown_VibratorTimerStart(uint32_t interval = 1000); + void CountDown_VibratorTimerStop(void); + bool isNeedVibratorTimerStop(); + bool CountDownTimerIsEnd(); // 计时器是否结束 bool GetChanageToStartCountDownView(); void SetChanageToStartCountDownView(bool val); diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/src/CountDownModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/src/CountDownModel.cpp index 69d9c59d5..cc661312c 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/src/CountDownModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/src/CountDownModel.cpp @@ -21,6 +21,7 @@ #include #include #include +#include "vibrator_service.h" namespace OHOS { /* -------------------------------------------------------------------------- */ @@ -383,6 +384,7 @@ namespace OHOS CountDown_StopTimer(); // 停止定时器 uapi_set_screen_on_api(); // 点亮屏幕 CountDownModel::GetInstance()->RequestStartRingtone(); // 播放铃声 + CountDownModel::GetInstance()->CountDown_VibratorTimerStart(); // 触发震动 StartCountDownView::GetInstance()->GetPlayOrPauseToggleButton()->SetVisible(false); p_StartCountDownView->GetRepeatButton()->SetVisible(true); @@ -631,6 +633,92 @@ namespace OHOS } } + static osTimerId_t g_vibrator_timer = nullptr; + static void CountDown_VibratorTimerCallbackProc(void *arg) + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerCallbackProc"); + if(CountDownModel::GetInstance()->isNeedVibratorTimerStop()) + { + CountDownModel::GetInstance()->CountDown_VibratorTimerStop(); + return; + } + // 触发震动 + custom_VibratorFunc_int(0); + custom_VibratorFunc_int(0); + } + + static void CountDown_VibratorTimerCallback(void *arg) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(CountDown_VibratorTimerCallbackProc, arg)); + } + + void CountDownModel::CountDown_VibratorTimerStart(uint32_t interval) + { + // 检查定时器是否存在 + if (g_vibrator_timer != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerStart Timer already exists!!"); + return; + } + g_vibrator_timer = osTimerNew((osTimerFunc_t)CountDown_VibratorTimerCallback, osTimerPeriodic, nullptr, nullptr); + // 检查定时器创建是否成功 + if (g_vibrator_timer == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerStart Timer create failed!!"); + return; + } + + int tick = osMs2Tick(interval); + osStatus_t ret = osTimerStart(g_vibrator_timer, tick); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_VibratorTimerStart] osTimerStart failed, ret = %lx!!", ret); + if (g_vibrator_timer != nullptr) + { + ret = osTimerDelete(g_vibrator_timer); + } + g_vibrator_timer = nullptr; + return; + } + return; + } + + void CountDownModel::CountDown_VibratorTimerStop(void) + { + // 检查定时器是否存在 + if (g_vibrator_timer != nullptr) + { + osTimerStop(g_vibrator_timer); + // 删除定时器并置为 nullptr + osStatus_t ret = osTimerDelete(g_vibrator_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerStop osTimerDelete failed, ret = %lx!!", ret); + } + g_vibrator_timer = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stop vibrator timer success!!"); + } + } + + bool CountDownModel::isNeedVibratorTimerStop() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "isNeedVibratorTimerStop"); + if (playerCtr.get() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCtr.get() == nullptr"); + return OHOS_FAILURE; + } + int32_t state = 0; + playerCtr->GetPlayerState(state); + if (state != PlayerStates::PLAYER_STARTED) + { + return true; + } + return false; + } + + + /* ----------------------- CountDownRingPlayerListener ---------------------- */ void CountDownRingPlayerListener::SetOwner(std::shared_ptr player) -- 2.17.1