return std::string(buffer);
}
- void ThunderBirdModel::timer_callback_proc()
- {
- ThunderBirdMainView *view = ThunderBirdMainView::GetInstance();
- if (view)
- {
- view->UpdateTimeText(GetCurrentTimeStr().c_str());
- }
- }
- /* ---------------------- 状态栏时间刷新定时器 ---------------------- */
- static osTimerId_t g_timer = nullptr;
- /*定时器到期时的处理*/
- static void TimerCallbackProc(uint8_t data)
- {
- // 倒计时
- ThunderBirdModel::GetInstance()->timer_callback_proc();
- ThunderBirdMainView::GetInstance()->updateSignalDisplay();
- ThunderBirdMainView::GetInstance()->UpdateBatteryProcess();
- }
- /*
- * @brief 回调函数
- */
- static void TimerCallback(uint8_t data)
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerCallback %d", data);
- GraphicService::GetInstance()->PostGraphicEvent(
- std::bind(TimerCallbackProc, data));
- }
-
- /*
- * @brief 开启定时器函数
- * @param interval 时间间隔,单位ms
- */
- void ThunderBirdModel::StartTimer(uint32_t interval)
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::StartTimer");
- /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回
- * ------------------------- */
- if (g_timer != nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!");
- return;
- }
-
- /* --------------------------------- 2.创建定时器
- * -------------------------------- */
- g_timer = osTimerNew((osTimerFunc_t)TimerCallback, osTimerPeriodic,
- nullptr, nullptr);
- // 检查定时器创建是否成功
- if (g_timer == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!");
- return;
- }
-
- /* ----------------------------- 3.将毫秒转换为系统时钟节拍数
- * ---------------------------- */
- /* --------------------------------- 4.启动定时器
- * -------------------------------- */
- osStatus_t ret = osTimerStart(g_timer, interval);
- /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为
- * nullptr -------------------- */
- if (ret != osOK)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
- "osTimerDelete failed, ret = %lx!!", ret);
- if (g_timer != nullptr)
- {
- ret = osTimerDelete(g_timer);
- }
- g_timer = nullptr;
- return;
- }
- }
- /*
- * @brief 停止定时器
- */
- void ThunderBirdModel::StopTimer(void)
- {
- // 检查定时器是否存在
- if (g_timer != nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::BP_StopTimer");
- osTimerStop(g_timer);
- // 删除定时器并置为 nullptr
- osStatus_t ret = osTimerDelete(g_timer);
- if (ret != osOK)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
- "osTimerDelete failed, ret = %lx!!", ret);
- }
- g_timer = nullptr;
- }
- }
+ // 旧的定时器系统已整合到新的统一定时器系统中
- /*----------------------提醒界面定时器----------------------------------*/
- static osTimerId_t g_reminderHideTimer = nullptr;
- static void ReminderHideTimerCallbackProc(uint8_t data)
- {
- (void)data;
- auto *reminder = ThunderBirdReminderView::GetInstance();
- if (reminder != nullptr)
- {
- reminder->HideAll();
- }
- int16_t currentView = ThunderBirdMainView::GetInstance()->GetCurrentView();
- int16_t currentSubView = ThunderBirdMainView::GetInstance()->GetCurrentSubView();
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "currentView = %d, currentSubView = %d", currentView, currentSubView);
- // 隐藏后切回之前的界面
- // auto *mainv = ThunderBirdReminderView::GetInstance();
- // if (mainv != nullptr)//判断条件需要修改
- // {
- // mainv->Show(-1);
- // }
- }
- static void ReminderHideTimerCallback(uint8_t data)
- {
- GraphicService::GetInstance()->PostGraphicEvent(std::bind(ReminderHideTimerCallbackProc, data));
- }
- void ThunderBirdModel::StartReminderHideTimer(uint32_t intervalMs)
- {
- if (g_reminderHideTimer != nullptr)
- {
- osTimerStop(g_reminderHideTimer);
- osStatus_t ret = osTimerDelete(g_reminderHideTimer);
- (void)ret;
- g_reminderHideTimer = nullptr;
- }
- g_reminderHideTimer = osTimerNew((osTimerFunc_t)ReminderHideTimerCallback, osTimerOnce, nullptr, nullptr);
- if (g_reminderHideTimer == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartReminderHideTimer new timer failed!!");
- return;
- }
- osStatus_t ret = osTimerStart(g_reminderHideTimer, intervalMs);
- if (ret != osOK)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartReminderHideTimer start failed, ret = %lx!!", ret);
- osTimerDelete(g_reminderHideTimer);
- g_reminderHideTimer = nullptr;
- }
- auto *reminder = ThunderBirdReminderView::GetInstance();//先隐藏全部提醒界面
- if (reminder != nullptr)
- {
- reminder->HideAll();
- }
- }
+ /*----------------------提醒界面定时器(已整合到新定时器系统)----------------------------------*/
+ void ThunderBirdModel::StartReminderHideTimer(uint32_t intervalMs)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StartReminderHideTimer: intervalMs=%u", intervalMs);
+
+ // 设置提醒隐藏定时器状态
+ m_reminderHideActive = true;
+ m_reminderHideTime = intervalMs / 1000; // 转换为秒数
+
+ // 先隐藏全部提醒界面
+ auto *reminder = ThunderBirdReminderView::GetInstance();
+ if (reminder != nullptr) {
+ reminder->HideAll();
+ }
+
+ // 确保时间显示定时器正在运行
+ if (m_timeDisplayTimer == nullptr) {
+ StartTimeDisplayTimer(1000); // 1秒间隔
+ }
+
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reminder hide timer started: %d seconds", m_reminderHideTime);
+ }
-
-
+ void ThunderBirdModel::StopReminderHideTimer(void)
+ {
+ if (g_reminderHideTimer != nullptr)
+ {
+ osTimerStop(g_reminderHideTimer);
+ osStatus_t ret = osTimerDelete(g_reminderHideTimer);
+ if (ret != osOK)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopReminderHideTimer delete failed, ret = %lx!!", ret);
+ }
+ g_reminderHideTimer = nullptr;
+ }
+ }
- // ---------------------- OTA 倒计时定时器(5 -> 1,每步1秒,然后监控下载状态) ----------------------
- static osTimerId_t g_otaCountdownTimer = nullptr;
- static int g_otaCountdownValue = 0;
- static int g_otaDownloadTimeout = 0; // 下载超时计数器(秒)
- static const int OTA_DOWNLOAD_TIMEOUT_SECONDS = 60; // 60秒超时
- static void OtaCountdownTimerProc(uint8_t data)
- {
- (void)data;
+ // ---------------------- OTA 倒计时定时器(已整合到新定时器系统) ----------------------
+ void ThunderBirdModel::StartOtaCountdown(uint32_t startVal)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StartOtaCountdown: startVal=%u", startVal);
- // 前5秒:倒计时阶段
- if (g_otaCountdownValue > 0)
- {
- g_otaCountdownValue -= 1;
- GraphicService::GetInstance()->PostGraphicEvent([](){
- if (ThunderBirdOtaView::GetInstance())
- {
- ThunderBirdOtaView::GetInstance()->UpdateCountdown(g_otaCountdownValue);
- }
- });
- return;
- }
+ // 范围保护
+ if (startVal < 1) { startVal = 1; }
+ if (startVal > 5) { startVal = 5; }
- // 倒计时结束,跳转到下载中界面
- if (g_otaCountdownValue == 0)
- {
- g_otaCountdownValue = -1; // 标记已进入下载阶段
- g_otaDownloadTimeout = 0; // 重置超时计数器
-
- // 开始OTA下载
- do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_OTA_DOWNLOAD, NULL, 0);
- ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_OTAVIEW, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_UPDATING);
- return;
+ // 设置OTA倒计时状态
+ m_otaCountdownActive = true;
+ m_otaCountdownValue = (int)startVal;
+
+ // 立即刷新一次当前值
+ if (ThunderBirdOtaView::GetInstance()) {
+ ThunderBirdOtaView::GetInstance()->UpdateCountdown(m_otaCountdownValue);
}
- // 下载阶段:检查OTA状态
- if (g_otaCountdownValue == -1)
- {
- g_otaDownloadTimeout++;
- // 检查超时(60秒无数据更新)
- if (g_otaDownloadTimeout >= OTA_DOWNLOAD_TIMEOUT_SECONDS)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OTA download timeout after %d seconds", OTA_DOWNLOAD_TIMEOUT_SECONDS);
-
- // 停止定时器
- if (g_otaCountdownTimer != nullptr)
- {
- osTimerStop(g_otaCountdownTimer);
- osTimerDelete(g_otaCountdownTimer);
- g_otaCountdownTimer = nullptr;
- }
-
- // 跳转到失败界面
- ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_OTAVIEW, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_UPDATE_FAILED);
- return;
- }
-
- // 检查OTA状态
- ThunderBirdModel* model = ThunderBirdModel::GetInstance();
- int otaStatus = model->GetOtaStatus();
-
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OTA status check: status=%d, timeout=%d", otaStatus, g_otaDownloadTimeout);
-
- if (otaStatus == 2) // 更新成功
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OTA update success");
-
- // 停止定时器
- if (g_otaCountdownTimer != nullptr)
- {
- osTimerStop(g_otaCountdownTimer);
- osTimerDelete(g_otaCountdownTimer);
- g_otaCountdownTimer = nullptr;
- }
-
- // 跳转到成功界面
- ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_OTAVIEW, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_UPDATE_SUCCESS);
- return;
- }
- else if (otaStatus == 3) // 更新失败
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OTA update failed");
-
- // 停止定时器
- if (g_otaCountdownTimer != nullptr)
- {
- osTimerStop(g_otaCountdownTimer);
- osTimerDelete(g_otaCountdownTimer);
- g_otaCountdownTimer = nullptr;
- }
-
- // 跳转到失败界面
- ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_OTAVIEW, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_UPDATE_FAILED);
- return;
- }
+ // 确保状态管理定时器正在运行
+ if (m_statusTimer == nullptr) {
+ StartStatusTimer(1000); // 1秒间隔
}
- }
- static void OtaCountdownTimerCb(uint8_t data)
- {
- OtaCountdownTimerProc(data);
- }
- void ThunderBirdModel::StartOtaCountdown(uint32_t startVal)
- {
- // 范围保护
- if (startVal < 1) { startVal = 1; }
- if (startVal > 5) { startVal = 5; }
- // 先停旧定时器
- if (g_otaCountdownTimer != nullptr)
- {
- osTimerStop(g_otaCountdownTimer);
- osTimerDelete(g_otaCountdownTimer);
- g_otaCountdownTimer = nullptr;
- }
- g_otaCountdownValue = (int)startVal;
- // 立即刷新一次当前值
- if (ThunderBirdOtaView::GetInstance())
- {
- ThunderBirdOtaView::GetInstance()->UpdateCountdown(g_otaCountdownValue);
- }
- // 创建1s周期定时器
- uint32_t oneSecond = 1000;
- g_otaCountdownTimer = osTimerNew((osTimerFunc_t)OtaCountdownTimerCb, osTimerPeriodic, nullptr, nullptr);
- if (g_otaCountdownTimer == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartOtaCountdown new timer failed!!");
- return;
- }
- osStatus_t ret = osTimerStart(g_otaCountdownTimer, oneSecond);
- if (ret != osOK)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartOtaCountdown start failed, ret = %lx!!", ret);
- osTimerDelete(g_otaCountdownTimer);
- g_otaCountdownTimer = nullptr;
- }
- }
+
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OTA countdown started: %d seconds", m_otaCountdownValue);
+ }
void ThunderBirdModel::StopOtaCountdown(void)
{
- if (g_otaCountdownTimer != nullptr)
- {
- osTimerStop(g_otaCountdownTimer);
- osTimerDelete(g_otaCountdownTimer);
- g_otaCountdownTimer = nullptr;
- }
- g_otaCountdownValue = 0;
- g_otaDownloadTimeout = 0; // 重置超时计数器
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopOtaCountdown");
+
+ // 停止OTA倒计时
+ m_otaCountdownActive = false;
+ m_otaCountdownValue = 0;
+
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OTA countdown stopped");
}