Merge branch 'sdk650pathc0423' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0... 2334/1 2334/head
authorxue <2144439972@qq.com>
Sat, 20 Sep 2025 10:06:19 +0000 (18:06 +0800)
committerxue <2144439972@qq.com>
Sat, 20 Sep 2025 10:06:19 +0000 (18:06 +0800)
1  2 
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

@@@ -19,11 -19,19 +19,20 @@@ namespace OHO
      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 StopReminderHideTimer(void);
          void StartOtaCountdown(uint32_t startVal);
          void StopOtaCountdown(void);
          void StartCountUpTimer(uint32_t targetSeconds);
          
      };    
          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 IsRecording() const;
          bool SendRecording();
          bool ReceiveAnswer();
          std::string GetConversationText();
@@@ -73,8 -73,9 +73,9 @@@ namespace OHO
      {
          WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::ThunderBirdMainView");
          g_pThunderBirdMainView = this;
 -        ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 打开屏幕常亮
 +        //ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 打开屏幕常亮
-         ThunderBirdModel::GetInstance()->StartTimer();
+         ThunderBirdModel::GetInstance()->StartTimeDisplayTimer();
+         ThunderBirdModel::GetInstance()->StartStatusTimer();
      }
  
      ThunderBirdMainView::~ThunderBirdMainView()
@@@ -88,8 -89,9 +89,9 @@@
              ScrollView_ = nullptr;
          }
          g_pThunderBirdMainView = nullptr;
 -        ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 关闭屏幕常亮
 +        //ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 关闭屏幕常亮
-         ThunderBirdModel::GetInstance()->StopTimer();
+         ThunderBirdModel::GetInstance()->StopTimeDisplayTimer();
+         ThunderBirdModel::GetInstance()->StopStatusTimer();
      }
  
      ThunderBirdMainView *ThunderBirdMainView::GetInstance()
           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");
       }