优化雷鸟定时器业务逻辑 2331/1 2331/head
authorCaisking <Casiking@zhihuishixun.com>
Sat, 20 Sep 2025 08:47:09 +0000 (16:47 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Sat, 20 Sep 2025 08:47:09 +0000 (16:47 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdMainView.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp

index 59c5e37..f84d02c 100644 (file)
@@ -19,9 +19,18 @@ namespace OHOS
     public:
         static ThunderBirdModel *GetInstance(void);
         std::string GetCurrentTimeStr();
-        void timer_callback_proc();
-        void StopTimer(void);
-        void StartTimer(uint32_t interval = 2 * 1000);//2秒
+        
+        // 时间显示定时器(只显示数据,不做处理)
+        void StartTimeDisplayTimer(uint32_t interval = 1000); // 1秒更新一次时间显示
+        void StopTimeDisplayTimer(void);
+        void TimeDisplayCallback();
+        
+        // 状态管理定时器(管理状态,进行状态变换处理)
+        void StartStatusTimer(uint32_t interval = 2 * 1000); // 2秒检查一次状态
+        void StopStatusTimer(void);
+        void StatusCallback();
+        
+        // 业务定时器控制函数(保持原有接口)
         void StartReminderHideTimer(uint32_t intervalMs = 1000);
         void StartOtaCountdown(uint32_t startVal);
         void StopOtaCountdown(void);
@@ -39,8 +48,7 @@ namespace OHOS
         // OTA升级状态
         void UpdateOtaStatus(int status);   
         int GetOtaStatus();
-        int GetOtaProgress();
-     // 新手引导相关函数
+        // 新手引导相关函数
      enum class BindingStatus {
         BOUND = 0,      // 已绑定
         NOT_BOUND = 1,  // 未绑定
@@ -49,9 +57,28 @@ namespace OHOS
         
     };    
         BindingStatus CheckBindingStatus();
+        
+        // 设备状态枚举
+        enum class DeviceStatus {
+            IDLE = 0,           // 空闲状态
+            RECORDING = 1,      // 录音中
+            PROCESSING = 2,     // 处理中
+            PLAYING = 3,        // 播放中
+            CONNECTING = 4,     // 连接中
+            UPDATING = 5,       // 更新中
+            ERROR = 6,          // 错误状态
+            SLEEPING = 7,       // 睡眠状态
+            CHARGING = 8        // 充电中
+        };
+        
+        // 状态管理相关函数
+        DeviceStatus GetCurrentStatus() const;
+        void SetCurrentStatus(DeviceStatus status);
+        void UpdateDeviceStatus();
+        std::string GetStatusString() const;
 
         // 对话相关函数
-        bool StartRecording(std::string audioPath);
+        bool StartRecording();
         bool StopRecording();
         bool SendRecording();
         bool ReceiveAnswer();
@@ -118,9 +145,25 @@ namespace OHOS
         std::string m_currentTimeStr;
         // OTA升级状态
         int m_otaStatus;
-        // OTA升级进度
-        int m_otaProgress;
+        
+        // 定时器相关
+        void* m_timeDisplayTimer;      // 时间显示定时器
+        void* m_statusTimer;           // 状态管理定时器
+        
+        // 设备状态管理
+        DeviceStatus m_currentStatus;  // 当前设备状态
+        uint32_t m_statusChangeTime;   // 状态变更时间
+        uint32_t m_lastStatusCheckTime; // 上次状态检查时间
+        
+        // 业务定时器状态
+        bool m_reminderHideActive;     // 提醒隐藏定时器是否激活
+        uint32_t m_reminderHideTime;   // 提醒隐藏剩余时间
+        bool m_otaCountdownActive;     // OTA倒计时是否激活
+        int m_otaCountdownValue;       // OTA倒计时值
+        bool m_countUpActive;          // 计数定时器是否激活
+        int m_countUpValue;            // 当前计数值
+        int m_countUpTarget;           // 计数目标值
     };
 }
 
-#endif // THUNDERBIRD_MODEL_H
\ No newline at end of file
+#endif // THUNDERBIRD_MODEL_H
index 562b193..f347b2e 100644 (file)
@@ -74,7 +74,8 @@ namespace OHOS
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::ThunderBirdMainView");
         g_pThunderBirdMainView = this;
         ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 打开屏幕常亮
-        ThunderBirdModel::GetInstance()->StartTimer();
+        ThunderBirdModel::GetInstance()->StartTimeDisplayTimer();
+        ThunderBirdModel::GetInstance()->StartStatusTimer();
     }
 
     ThunderBirdMainView::~ThunderBirdMainView()
@@ -89,7 +90,8 @@ namespace OHOS
         }
         g_pThunderBirdMainView = nullptr;
         ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 关闭屏幕常亮
-        ThunderBirdModel::GetInstance()->StopTimer();
+        ThunderBirdModel::GetInstance()->StopTimeDisplayTimer();
+        ThunderBirdModel::GetInstance()->StopStatusTimer();
     }
 
     ThunderBirdMainView *ThunderBirdMainView::GetInstance()
index 0a66667..a93e7b0 100644 (file)
@@ -1,3 +1,5 @@
+
+
 /***
  * @Date: 2024-06-22 18:08:25
  * @LastEditors: Caisking 3449750381@qq.com
 
      static bool g_isRecording = false;//是否正在录音
 
-     ThunderBirdModel::ThunderBirdModel() : m_nextReminderId(1) 
+     ThunderBirdModel::ThunderBirdModel() : m_nextReminderId(1), m_otaStatus(0),
+                                           m_timeDisplayTimer(nullptr), m_statusTimer(nullptr),
+                                           m_currentStatus(DeviceStatus::IDLE), 
+                                           m_statusChangeTime(0), m_lastStatusCheckTime(0),
+                                           m_reminderHideActive(false), m_reminderHideTime(0),
+                                           m_otaCountdownActive(false), m_otaCountdownValue(0),
+                                           m_countUpActive(false), m_countUpValue(0), m_countUpTarget(0)
      {
          // 初始化时加载提醒数据
          // LoadRemindersFromFile();
          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();
-         //状态监控
-         if(ThunderBirdPresenter::GetInstance() != nullptr)
-         {
-            ThunderBirdPresenter::GetInstance()->timer_callback_toui_proc();
-         }
-     }
-     /*
-      * @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);
+    }
 
 
 
 
-    // ---------------------- 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");
      }
 
 
  
  
 
-     // ---------------------- 通用计时加一定时器(0 -> targetSeconds,每步1秒) ----------------------
-     static osTimerId_t g_countUpTimer = nullptr;
-     static int g_countUpTargetSeconds = 0;
-     static int g_countUpValue = 0;
-     static void CountUpTimerProc(uint8_t data)
-     {
-         (void)data;
-         if (g_countUpValue >= g_countUpTargetSeconds)
-         {
-             if (g_countUpTimer != nullptr)
-             {
-                 osTimerStop(g_countUpTimer);
-                 osTimerDelete(g_countUpTimer);
-                 g_countUpTimer = nullptr;
-             }
-             return;
-         }
-         g_countUpValue += 1;
-         ThunderBirdLullabyView::GetInstance()->UpdateTimeText(g_countUpValue, g_countUpTargetSeconds);
-     }
-     static void CountUpTimerCb(uint8_t data)
-     {
-         CountUpTimerProc(data);
-     }
-     void ThunderBirdModel::StartCountUpTimer(uint32_t targetSeconds)
-     {
-         // 参数保护:至少为1秒
-         if (targetSeconds < 1) { targetSeconds = 1; }
-         // 停止旧定时器
-         if (g_countUpTimer != nullptr)
-         {
-             osTimerStop(g_countUpTimer);
-             osStatus_t ret = osTimerDelete(g_countUpTimer);
-             (void)ret;
-             g_countUpTimer = nullptr;
-         }
-         // 初始化
-         g_countUpTargetSeconds = (int)targetSeconds;
-         g_countUpValue = 0;
-         // 创建1s周期定时器
-         uint32_t oneSecond = 1000;
-         g_countUpTimer = osTimerNew((osTimerFunc_t)CountUpTimerCb, osTimerPeriodic, nullptr, nullptr);
-         if (g_countUpTimer == nullptr)
-         {
-             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartCountUpTimer new timer failed!!");
-             return;
-         }
-         osStatus_t ret = osTimerStart(g_countUpTimer, oneSecond);
-         if (ret != osOK)
-         {
-             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartCountUpTimer start failed, ret = %lx!!", ret);
-             osTimerDelete(g_countUpTimer);
-             g_countUpTimer = nullptr;
-         }
-     }
+     // ---------------------- 通用计时加一定时器(已整合到新定时器系统) ----------------------
+    void ThunderBirdModel::StartCountUpTimer(uint32_t targetSeconds)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StartCountUpTimer: targetSeconds=%u", targetSeconds);
+        
+        // 参数保护:至少为1秒
+        if (targetSeconds < 1) { targetSeconds = 1; }
+        
+        // 设置计数定时器状态
+        m_countUpActive = true;
+        m_countUpTarget = (int)targetSeconds;
+        m_countUpValue = 0;
+        
+        // 确保状态管理定时器正在运行
+        if (m_statusTimer == nullptr) {
+            StartStatusTimer(1000); // 1秒间隔
+        }
+        
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Count up timer started: 0/%d", m_countUpTarget);
+    }
      void ThunderBirdModel::StopCountUpTimer(void)
      {
-         if (g_countUpTimer != nullptr)
-         {
-             osTimerStop(g_countUpTimer);
-             osStatus_t ret = osTimerDelete(g_countUpTimer);
-             if (ret != osOK)
-             {
-                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopCountUpTimer delete failed, ret = %lx!!", ret);
-             }
-             g_countUpTimer = nullptr;
-         }
+         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopCountUpTimer");
+         
+         // 停止计数定时器
+         m_countUpActive = false;
+         m_countUpValue = 0;
+         m_countUpTarget = 0;
+         
+         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Count up timer stopped");
      }
      int ThunderBirdModel::GetCountUpValue() const
      {
-         return g_countUpValue;
+         return m_countUpValue;
      }
 
 
      void ThunderBirdModel::UpdateOtaProgress(int progress)
      {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::UpdateOtaProgress: %d", progress);
-        m_otaProgress = progress;
         if(ThunderBirdOtaView::GetInstance())
         {
             ThunderBirdOtaView::GetInstance()->SetRemindProgress(progress);
         }
      }
-     /*************************获取OTA升级进度*************************/
-     int ThunderBirdModel::GetOtaProgress()
-     {
-        return m_otaProgress;
-     }
+
      /*************************OTA升级状态*************************/
      void ThunderBirdModel::UpdateOtaStatus(int status)
      {
      }
 
      // ==================== 对话相关函数 ====================
-     bool ThunderBirdModel::StartRecording(std::string audioPath)
+     bool ThunderBirdModel::StartRecording()
      {
          WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::StartRecording");
          
              return false;
          }
          g_isRecording = true;//设置录音状态
-        // std::string audioPath = uapi_ln_get_speechchat_audio_path();
+         std::string audioPath = uapi_ln_get_story_choose_audio_path();
         if(audioPath.empty())
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::StartRecording: 故事选择的录音文件路径为空");
             4、事项提醒
     */ 
 
+    // ==================== 时间显示定时器实现 ====================
+
+    /**
+     * @brief 时间显示定时器回调函数
+    */
+     static void TimeDisplayTimerCallback(uint8_t data)
+     {
+         GraphicService::GetInstance()->PostGraphicEvent(
+             std::bind([]() {
+                 ThunderBirdModel::GetInstance()->TimeDisplayCallback();
+             }));
+     }
+     
+    /**
+     * @brief 启动时间显示定时器
+     * @param interval 定时器间隔,单位毫秒,默认1000ms
+     */
+    void ThunderBirdModel::StartTimeDisplayTimer(uint32_t interval)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::StartTimeDisplayTimer: interval=%u", interval);
+        
+        // 如果定时器已存在,先停止
+        if (m_timeDisplayTimer != nullptr) {
+            StopTimeDisplayTimer();
+        }
+        
+        // 创建定时器
+        m_timeDisplayTimer = osTimerNew((osTimerFunc_t)TimeDisplayTimerCallback, osTimerPeriodic, nullptr, nullptr);
+        if (m_timeDisplayTimer == nullptr) {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to create time display timer");
+            return;
+        }
+        
+        // 启动定时器
+        osStatus_t ret = osTimerStart(m_timeDisplayTimer, interval);
+        if (ret != osOK) {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to start time display timer, ret=%d", ret);
+            osTimerDelete(m_timeDisplayTimer);
+            m_timeDisplayTimer = nullptr;
+        }
+    }
+    
+    /**
+     * @brief 停止时间显示定时器
+     */
+    void ThunderBirdModel::StopTimeDisplayTimer()
+    {
+        if (m_timeDisplayTimer != nullptr) {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::StopTimeDisplayTimer");
+            osTimerStop(m_timeDisplayTimer);
+            osTimerDelete(m_timeDisplayTimer);
+            m_timeDisplayTimer = nullptr;
+        }
+    }
+    
+    /**
+     * @brief 时间显示回调处理
+     */
+    void ThunderBirdModel::TimeDisplayCallback()
+    {
+        // 更新时间显示
+        ThunderBirdMainView *view = ThunderBirdMainView::GetInstance();
+        if (view) {
+            std::string currentTime = GetCurrentTimeStr();
+            view->UpdateTimeText(currentTime.c_str());
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimeDisplayCallback: %s", currentTime.c_str());
+        }
+        
+        // 处理提醒隐藏定时器
+        if (m_reminderHideActive) {
+            if (m_reminderHideTime > 0) {
+                m_reminderHideTime--;
+            } else {
+                // 提醒隐藏时间到,隐藏所有提醒
+                auto *reminder = ThunderBirdReminderView::GetInstance();
+                if (reminder != nullptr) {
+                    reminder->HideAll();
+                }
+                m_reminderHideActive = false;
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reminder hide timer completed");
+            }
+        }
+    }
+    
+    // ==================== 状态管理定时器实现 ====================
+        
+    /**
+     * @brief 状态管理定时器回调函数
+     */
+     static void StatusTimerCallback(uint8_t data)
+     {
+         GraphicService::GetInstance()->PostGraphicEvent(
+             std::bind([]() {
+                 ThunderBirdModel::GetInstance()->StatusCallback();
+             }));
+     }
+     
+    /**
+     * @brief 启动状态管理定时器
+     * @param interval 定时器间隔,单位毫秒,默认2000ms
+     */
+    void ThunderBirdModel::StartStatusTimer(uint32_t interval)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::StartStatusTimer: interval=%u", interval);
+        
+        // 如果定时器已存在,先停止
+        if (m_statusTimer != nullptr) {
+            StopStatusTimer();
+        }
+        
+        // 创建定时器
+        m_statusTimer = osTimerNew((osTimerFunc_t)StatusTimerCallback, osTimerPeriodic, nullptr, nullptr);
+        if (m_statusTimer == nullptr) {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to create status timer");
+            return;
+        }
+        
+        // 启动定时器
+        osStatus_t ret = osTimerStart(m_statusTimer, interval);
+        if (ret != osOK) {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to start status timer, ret=%d", ret);
+            osTimerDelete(m_statusTimer);
+            m_statusTimer = nullptr;
+        }
+    }
+    
+    /**
+     * @brief 停止状态管理定时器
+     */
+    void ThunderBirdModel::StopStatusTimer()
+    {
+        if (m_statusTimer != nullptr) {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::StopStatusTimer");
+            osTimerStop(m_statusTimer);
+            osTimerDelete(m_statusTimer);
+            m_statusTimer = nullptr;
+        }
+    }
+    /**
+     * @brief 状态管理回调处理
+     */
+    void ThunderBirdModel::StatusCallback()
+    {
+        // 更新设备状态
+        UpdateDeviceStatus();
+        
+        // 处理OTA倒计时定时器
+        if (m_otaCountdownActive) {
+            if (m_otaCountdownValue <= 0) {
+                // OTA倒计时结束,停止定时器并开始OTA
+                m_otaCountdownActive = false;
+                m_otaCountdownValue = 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);
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OTA countdown completed, starting OTA");
+            } else {
+                // 更新倒计时值
+                m_otaCountdownValue--;
+                
+                // 更新UI显示
+                if (ThunderBirdOtaView::GetInstance()) {
+                    ThunderBirdOtaView::GetInstance()->UpdateCountdown(m_otaCountdownValue);
+                }
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OTA countdown: %d", m_otaCountdownValue);
+            }
+        }
+        
+        // 处理计数定时器
+        if (m_countUpActive) {
+            if (m_countUpValue >= m_countUpTarget) {
+                // 计数完成,停止定时器
+                m_countUpActive = false;
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Count up timer completed: %d/%d", m_countUpValue, m_countUpTarget);
+            } else {
+                // 增加计数值
+                m_countUpValue++;
+                
+                // 更新UI显示
+                ThunderBirdLullabyView::GetInstance()->UpdateTimeText(m_countUpValue, m_countUpTarget);
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Count up: %d/%d", m_countUpValue, m_countUpTarget);
+            }
+        }
+        
+        // 更新UI显示
+        ThunderBirdMainView *view = ThunderBirdMainView::GetInstance();
+        if (view) {
+            view->updateSignalDisplay();
+            view->UpdateBatteryProcess();
+        }
+        
+        // 通知Presenter进行状态处理
+        if (ThunderBirdPresenter::GetInstance() != nullptr) {
+            ThunderBirdPresenter::GetInstance()->timer_callback_toui_proc();
+        }
+        
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StatusCallback: status=%d", static_cast<int>(m_currentStatus));
+    }
+    
+    // ==================== 状态管理相关函数实现 ====================
+    
+    /**
+     * @brief 获取当前设备状态
+     */
+    ThunderBirdModel::DeviceStatus ThunderBirdModel::GetCurrentStatus() const
+    {
+        return m_currentStatus;
+    }
+    
+    /**
+     * @brief 设置当前设备状态
+     */
+    void ThunderBirdModel::SetCurrentStatus(DeviceStatus status)
+    {
+        if (m_currentStatus != status) {
+            DeviceStatus oldStatus = m_currentStatus;
+            m_currentStatus = status;
+            m_statusChangeTime = uapi_get_timestampe_ss(nullptr) ? 0 : uapi_get_timestampe_ss(nullptr);
+            
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Status changed: %d -> %d", 
+                         static_cast<int>(oldStatus), static_cast<int>(status));
+        }
+    }
+    
+    /**
+     * @brief 更新设备状态
+     */
+    void ThunderBirdModel::UpdateDeviceStatus()
+    {
+        uint32_t currentTime = 0;
+        uapi_get_timestampe_ss(&currentTime);
+        m_lastStatusCheckTime = currentTime;
+        
+        // 根据当前状态进行状态检查和转换
+        switch (m_currentStatus) {
+            case DeviceStatus::IDLE:
+                // 空闲状态检查
+                break;
+                
+            case DeviceStatus::RECORDING:
+                // 录音状态检查
+                if (!g_isRecording) {
+                    SetCurrentStatus(DeviceStatus::IDLE);
+                }
+                break;
+                
+            case DeviceStatus::PROCESSING:
+                // 处理状态检查,可以设置超时
+                if (currentTime - m_statusChangeTime > 30000) { // 30秒超时
+                    SetCurrentStatus(DeviceStatus::IDLE);
+                }
+                break;
+                
+            case DeviceStatus::PLAYING:
+                // 播放状态检查
+                break;
+                
+            case DeviceStatus::CONNECTING:
+                // 连接状态检查
+                if (currentTime - m_statusChangeTime > 10000) { // 10秒超时
+                    SetCurrentStatus(DeviceStatus::ERROR);
+                }
+                break;
+                
+            case DeviceStatus::UPDATING:
+                // 更新状态检查
+                break;
+                
+            case DeviceStatus::ERROR:
+                // 错误状态检查
+                break;
+                
+            case DeviceStatus::SLEEPING:
+                // 睡眠状态检查
+                break;
+                
+            case DeviceStatus::CHARGING:
+                // 充电状态检查
+                break;
+        }
+    }
+    
+    /**
+     * @brief 获取状态字符串
+     */
+    std::string ThunderBirdModel::GetStatusString() const
+    {
+        switch (m_currentStatus) {
+            case DeviceStatus::IDLE:
+                return "空闲";
+            case DeviceStatus::RECORDING:
+                return "录音中";
+            case DeviceStatus::PROCESSING:
+                return "处理中";
+            case DeviceStatus::PLAYING:
+                return "播放中";
+            case DeviceStatus::CONNECTING:
+                return "连接中";
+            case DeviceStatus::UPDATING:
+                return "更新中";
+            case DeviceStatus::ERROR:
+                return "错误";
+            case DeviceStatus::SLEEPING:
+                return "睡眠";
+            case DeviceStatus::CHARGING:
+                return "充电中";
+            default:
+                return "未知";
+        }
+    }
 
  }
  
\ No newline at end of file
index aec47cc..8eae672 100644 (file)
@@ -307,7 +307,7 @@ namespace OHOS
         } else {
             // 开始录音
             ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_LISTENING);
-            ThunderBirdModel::GetInstance()->StartRecording(uapi_ln_get_speechchat_audio_path());
+            ThunderBirdModel::GetInstance()->StartRecording();
         }
     }
 
@@ -320,7 +320,7 @@ namespace OHOS
              currentSubView == ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_3) {
                 if(isLullabyRecording == false)
                 {
-                    ThunderBirdModel::GetInstance()->StartRecording(uapi_ln_get_story_choose_audio_path());
+                    ThunderBirdModel::GetInstance()->StartRecording();
                     isLullabyRecording = true;
                     ThunderBirdLullabyView::GetInstance()->listenAnimator->Start();
                     return;