#include <custom_utils.h>\r
#include <errcode.h>\r
#include <custom_save_runtime.h>\r
+#include "vibrator_service.h"\r
namespace OHOS\r
{\r
/* -------------------------------------------------------------------------- */\r
CountDown_StopTimer(); // 停止定时器\r
uapi_set_screen_on_api(); // 点亮屏幕\r
CountDownModel::GetInstance()->RequestStartRingtone(); // 播放铃声\r
+ CountDownModel::GetInstance()->CountDown_VibratorTimerStart(); // 触发震动\r
\r
StartCountDownView::GetInstance()->GetPlayOrPauseToggleButton()->SetVisible(false);\r
p_StartCountDownView->GetRepeatButton()->SetVisible(true);\r
}\r
}\r
\r
+ static osTimerId_t g_vibrator_timer = nullptr;\r
+ static void CountDown_VibratorTimerCallbackProc(void *arg)\r
+ {\r
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerCallbackProc");\r
+ if(CountDownModel::GetInstance()->isNeedVibratorTimerStop())\r
+ {\r
+ CountDownModel::GetInstance()->CountDown_VibratorTimerStop();\r
+ return;\r
+ }\r
+ // 触发震动\r
+ custom_VibratorFunc_int(0);\r
+ custom_VibratorFunc_int(0);\r
+ }\r
+\r
+ static void CountDown_VibratorTimerCallback(void *arg)\r
+ {\r
+ GraphicService::GetInstance()->PostGraphicEvent(std::bind(CountDown_VibratorTimerCallbackProc, arg));\r
+ }\r
+\r
+ void CountDownModel::CountDown_VibratorTimerStart(uint32_t interval)\r
+ {\r
+ // 检查定时器是否存在\r
+ if (g_vibrator_timer != nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerStart Timer already exists!!");\r
+ return;\r
+ }\r
+ g_vibrator_timer = osTimerNew((osTimerFunc_t)CountDown_VibratorTimerCallback, osTimerPeriodic, nullptr, nullptr);\r
+ // 检查定时器创建是否成功\r
+ if (g_vibrator_timer == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerStart Timer create failed!!");\r
+ return;\r
+ }\r
+\r
+ int tick = osMs2Tick(interval);\r
+ osStatus_t ret = osTimerStart(g_vibrator_timer, tick);\r
+ if (ret != osOK)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_VibratorTimerStart] osTimerStart failed, ret = %lx!!", ret);\r
+ if (g_vibrator_timer != nullptr)\r
+ {\r
+ ret = osTimerDelete(g_vibrator_timer);\r
+ }\r
+ g_vibrator_timer = nullptr;\r
+ return;\r
+ }\r
+ return;\r
+ }\r
+\r
+ void CountDownModel::CountDown_VibratorTimerStop(void)\r
+ {\r
+ // 检查定时器是否存在\r
+ if (g_vibrator_timer != nullptr)\r
+ {\r
+ osTimerStop(g_vibrator_timer);\r
+ // 删除定时器并置为 nullptr\r
+ osStatus_t ret = osTimerDelete(g_vibrator_timer);\r
+ if (ret != osOK)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerStop osTimerDelete failed, ret = %lx!!", ret);\r
+ }\r
+ g_vibrator_timer = nullptr;\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stop vibrator timer success!!");\r
+ }\r
+ }\r
+\r
+ bool CountDownModel::isNeedVibratorTimerStop()\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "isNeedVibratorTimerStop");\r
+ if (playerCtr.get() == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCtr.get() == nullptr");\r
+ return OHOS_FAILURE;\r
+ }\r
+ int32_t state = 0;\r
+ playerCtr->GetPlayerState(state);\r
+ if (state != PlayerStates::PLAYER_STARTED)\r
+ {\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
+\r
+\r
/* ----------------------- CountDownRingPlayerListener ---------------------- */\r
\r
void CountDownRingPlayerListener::SetOwner(std::shared_ptr<Player> player)\r