uapi_set_screen_on_api();
}
+ // 分发按键事件到对应的处理函数
+ switch (keyID) {
+ case static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER):
+ return HandlePowerKey(keyState, currentView, currentSubView, screenState);
+
+ case static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC):
+ return HandleFuncKey(keyState, currentView, currentSubView, screenState);
+
+ case static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_VENDOR_UP):
+ return HandleVendorUpKey(keyState, currentView, currentSubView, screenState);
+
+ case static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_VENDOR_DOWN):
+ return HandleVendorDownKey(keyState, currentView, currentSubView, screenState);
+
+ default:
+ return true;
+ }
+ }
+
+ void ThunderBirdPresenter::Notify()
+ {
+
+ //如果在二维码界面 判断是否绑定
+ if(ThunderBirdMainView::GetInstance() != nullptr)
+ {
+ int16_t currentView = ThunderBirdMainView::GetInstance()->GetCurrentView();
+ int16_t currentSubView = ThunderBirdMainView::GetInstance()->GetCurrentSubView();
+ //如果在二维码界面 要一直判断绑定状态 绑定成功就返回主界面
+ if(currentSubView == ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3)
+ {
+ ThunderBirdModel::BindingStatus bindingStatus = ThunderBirdModel::GetInstance()->CheckBindingStatus();
+ if(bindingStatus == ThunderBirdModel::BindingStatus::BOUND)
+ {
+ //绑定成功
+ ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_SPEAKING);
+ }
+ else
+ {
+ //判断二维码的有效性
+ if(ThunderBirdModel::GetInstance()->IsDeviceIdValid())
+ {
+ //更新二维码
+ ThunderBirdGuideView::GetInstance()->UpdateQrcode();
+ }
+ }
+ }
+ }
+ }
+
+ // ==================== 按键处理函数 ====================
+
+ /**
+ * @brief 处理POWER键事件
+ */
+ bool ThunderBirdPresenter::HandlePowerKey(uint16_t keyState, int16_t currentView, int16_t currentSubView, int screenState)
+ {
// 长按关机键
- if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) &&
- keyState == InputDevice::STATE_LONG_PRESS)
- {
+ if (keyState == InputDevice::STATE_LONG_PRESS) {
NativeAbility::GetInstance().SwitchSlice(VIEW_REBOOT);
return true;
}
-
- // 长按 FUNC:进入 LCD 产测 slice
- if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC) &&
- keyState == InputDevice::STATE_LONG_PRESS &&
- uapi_get_screen_state() == 0)
- {
- NativeAbility::GetInstance().SwitchSlice(VIEW_LCD_TEST);
+
+ // 短按POWER键(息屏状态下)
+ if (keyState == InputDevice::STATE_PRESS && screenState == 0) {
return true;
}
- /*************************power键*************************/
- if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)
- {
+
+ return true;
+ }
+
+ /**
+ * @brief 处理FUNC键事件
+ */
+ bool ThunderBirdPresenter::HandleFuncKey(uint16_t keyState, int16_t currentView, int16_t currentSubView, int screenState)
+ {
+ // 长按FUNC键:进入LCD产测
+ if (keyState == InputDevice::STATE_LONG_PRESS && screenState == 0) {
+ NativeAbility::GetInstance().SwitchSlice(VIEW_LCD_TEST);
return true;
}
- /*************************语音键*************************/
- if(keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC) && keyState == 1 && uapi_get_screen_state() == 0)
- {
- if(ThunderBirdModel::GetInstance()->CheckBindingStatus() != ThunderBirdModel::BindingStatus::BOUND)
- {
- if(ThunderBirdMainView::GetInstance()->GetCurrentSubView() != ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3)
- {
+
+ // 短按FUNC键(息屏状态下)
+ if (keyState == InputDevice::STATE_PRESS && screenState == 0) {
+ // 检查绑定状态
+ if (ThunderBirdModel::GetInstance()->CheckBindingStatus() != ThunderBirdModel::BindingStatus::BOUND) {
+ if (currentSubView != ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3) {
ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_GUIDEVIEW, ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3);
}
return true;
}
- if(currentView == THUNDERBIRD_DIALOGUEVIEW && currentSubView == ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_LISTENING)
- {
- ThunderBirdModel::GetInstance()->StopRecording();
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_SPEAKING);
- ThunderBirdModel::GetInstance()->SendRecording();
- }
- else
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_LISTENING);
- ThunderBirdModel::GetInstance()->StartRecording();
- }
+ // 处理对话功能
+ HandleDialogueFunction(currentView, currentSubView);
return true;
}
- /*************************VENDOR_UP键*************************/
- if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_VENDOR_UP) && keyState == 1 && uapi_get_screen_state() == 0)
- {
- if(ThunderBirdModel::GetInstance()->CheckBindingStatus() != ThunderBirdModel::BindingStatus::BOUND)
- {
- if(ThunderBirdMainView::GetInstance()->GetCurrentSubView() != ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3)
- {
+ return true;
+ }
+
+ /**
+ * @brief 处理VENDOR_UP键事件
+ */
+ bool ThunderBirdPresenter::HandleVendorUpKey(uint16_t keyState, int16_t currentView, int16_t currentSubView, int screenState)
+ {
+ if (keyState == InputDevice::STATE_PRESS && screenState == 0) {
+ // 检查绑定状态
+ if (ThunderBirdModel::GetInstance()->CheckBindingStatus() != ThunderBirdModel::BindingStatus::BOUND) {
+ if (currentSubView != ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3) {
ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_GUIDEVIEW, ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3);
}
return true;
}
- // 音量界面:FUNC 键 +10
- if (currentView == THUNDERBIRD_DIALOGUEVIEW ||
- (currentView == THUNDERBIRD_LULLABYVIEW &&
- (currentSubView == ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_1 ||
- currentSubView == ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_4))) //只有在对话界面还有哄睡界面才触发
- {
- ThunderBirdMainView::GetInstance()->ChangeThunderBirdReminderView(THUNDERBIRD_REMINDERVIEW);//不走ChangeView
- if (ThunderBirdReminderView::GetInstance())
- {
- ThunderBirdModel::GetInstance()->StartReminderHideTimer(1000);
- ThunderBirdReminderView::GetInstance()->Show(ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_VOLUME);
- ThunderBirdReminderView::GetInstance()->AdjustRemindProgress(10);
- }
+ // 音量调节功能
+ if (IsVolumeAdjustmentAvailable(currentView, currentSubView)) {
+ ShowVolumeAdjustment(10); // +10
return true;
}
- // 引导界面导航
- else if(currentView == THUNDERBIRD_GUIDEVIEW)
- {
- if(currentSubView == ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_1)
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_GUIDEVIEW, ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_2);
- }
- else if(currentSubView == ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_2)
- {
+
+ // 界面导航
+ return HandleViewNavigation(currentView, currentSubView, true);
+ }
+
+ return true;
+ }
+
+ /**
+ * @brief 处理VENDOR_DOWN键事件
+ */
+ bool ThunderBirdPresenter::HandleVendorDownKey(uint16_t keyState, int16_t currentView, int16_t currentSubView, int screenState)
+ {
+ // 长按VENDOR_DOWN 5秒
+ if (keyState == InputDevice::STATE_LONG_PRESS) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VENDOR_DOWN long press 5s detected");
+ // 可以在这里添加具体的功能
+ return true;
+ }
+
+ if (keyState == InputDevice::STATE_PRESS && screenState == 0) {
+ // 检查绑定状态
+ if (ThunderBirdModel::GetInstance()->CheckBindingStatus() != ThunderBirdModel::BindingStatus::BOUND) {
+ if (currentSubView != ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3) {
ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_GUIDEVIEW, ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3);
}
- else if(currentSubView == ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3)
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_SPEAKING);
- }
- return true;
+ return true;
}
- // 对话界面导航
- else if(currentView == THUNDERBIRD_DIALOGUEVIEW)
- {
- if(currentSubView == ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_SPEAKING) // 说话中
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_LISTENING);
- }
- else if(currentSubView == ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_LISTENING) // 聆听中
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_STATUS_SHOW);
- }
- else if(currentSubView == ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_STATUS_SHOW) // 状态展示
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_VOLUME);
- }
- return true;
- }
- // OTA界面导航
- else if(currentView == THUNDERBIRD_OTAVIEW)
- {
- if(currentSubView == ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_UPDATE_NOW) // 设置夜间更新
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_NIGHT_UPDATE_SUCCESS);
- }
-
- else if(currentSubView == ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_NORMAL
- || ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_OBVIOUS
- || ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_UPDATE_NOW) // 确认升级,先判断电量、网络、内存
- {
- if(ThunderBirdMainView::GetInstance()->Batteryvalue <= 50)//低电量
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_LOW_BATTERY);
- }
- else if(uapi_dev_runtime_get_cat1_signal() == 99)//无网络
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_NETWORK_ERROR);
- }
- else if(0)//获取内存状态
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_MEMORY_ERROR);
- }
- else
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_COUNTDOWN);
- }
- }
- else if(currentSubView == ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_COUNTDOWN) // 更新倒计时进入更新中
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_UPDATING);
- do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_OTA_DOWNLOAD, NULL, 0);//开始升级
- }
- return true;
- }
- // 哄睡界面导航
- else if(currentView == THUNDERBIRD_LULLABYVIEW)
- {
- if(currentSubView == ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_1)
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_LULLABYVIEW, ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_2);
- }
- else if(currentSubView == ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_2)
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_LULLABYVIEW, ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_3);
- }
- else if(currentSubView == ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_3)
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_LULLABYVIEW, ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_4);
- }
- else if(currentSubView == ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_4)
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_LULLABYVIEW, ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_5);
- }
- else if(currentSubView == ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_5)
- {
- // 返回主界面
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_SPEAKING);
- }
+ // 音量调节功能
+ if (IsVolumeAdjustmentAvailable(currentView, currentSubView)) {
+ ShowVolumeAdjustment(-10); // -10
return true;
}
- // 提醒界面导航
- else if(currentView == THUNDERBIRD_REMINDERVIEW)
- {
- if(currentSubView == ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_VOLUME) // 音量调节
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_TASK_REMINDER);
- }
- else if(currentSubView == ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_TASK_REMINDER) // 事项提醒
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_NETWORK_DISCONNECT);
- }
- else if(currentSubView == ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_NETWORK_DISCONNECT) // 网络断开
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_LOW_BATTERY);
- }
- else if(currentSubView == ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_LOW_BATTERY) // 电量不足
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_CHARGING);
- }
- else if(currentSubView == ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_CHARGING) // 充电中
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_CHARGE_COMPLETE);
- }
- else if(currentSubView == ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_CHARGE_COMPLETE) // 充电完成
- {
- // 返回主界面
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_ADJUSTVIEW, ThunderBirdAdjustView::THUNDERBIRD_ADJUSTVIEW_BIND_SUCCESS);
- }
- return true;
+
+ // OTA界面特殊处理
+ if (currentView == THUNDERBIRD_OTAVIEW) {
+ return HandleOtaViewNavigation(currentSubView);
}
- // 调节界面导航
- else if(currentView == THUNDERBIRD_ADJUSTVIEW)
- {
- if(currentSubView == ThunderBirdAdjustView::THUNDERBIRD_ADJUSTVIEW_BIND_SUCCESS) // 绑定成功
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_ADJUSTVIEW, ThunderBirdAdjustView::THUNDERBIRD_ADJUSTVIEW_WARNING);
- }
- else if(currentSubView == ThunderBirdAdjustView::THUNDERBIRD_ADJUSTVIEW_WARNING) // 异常警告
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_ADJUSTVIEW, ThunderBirdAdjustView::THUNDERBIRD_ADJUSTVIEW_NETWORK_CONNECTING);
- }
- else if(currentSubView == ThunderBirdAdjustView::THUNDERBIRD_ADJUSTVIEW_NETWORK_CONNECTING) // 网络连接中
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_SHUTDOWNVIEW, 0);
- //ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_SHUTDOWNTESTVIEW, -1);
- }
- return true;
- }
- return true;
- }
- /*************************VENDOR_DOWN键*************************/
- // 长按 VENDOR_DOWN 5秒
- if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_VENDOR_DOWN) && keyState == InputDevice::STATE_LONG_PRESS )
- {
- // 长按5秒操作 - 可以在这里添加具体的功能
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VENDOR_DOWN long press 5s detected - keyID=%d, keyState=%d", keyID, keyState);
- // 例如:切换到特定界面或执行特定操作
- // NativeAbility::GetInstance().SwitchSlice(VIEW_SOME_SPECIAL_VIEW);
- return true;
}
- if(keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_VENDOR_DOWN) && keyState == 1 && uapi_get_screen_state() == 0)
- {
- if(ThunderBirdModel::GetInstance()->CheckBindingStatus() != ThunderBirdModel::BindingStatus::BOUND )
- {
- if(ThunderBirdMainView::GetInstance()->GetCurrentSubView() != ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3)
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_GUIDEVIEW, ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3);
- }
- return true;
- }
- // 音量界面:FUNC 键 -10
- if (currentView == THUNDERBIRD_DIALOGUEVIEW ||
+ return true;
+ }
+
+ // ==================== 辅助函数 ====================
+
+ /**
+ * @brief 处理对话功能
+ */
+ void ThunderBirdPresenter::HandleDialogueFunction(int16_t currentView, int16_t currentSubView)
+ {
+ if (currentView == THUNDERBIRD_DIALOGUEVIEW &&
+ currentSubView == ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_LISTENING) {
+ // 停止录音并发送
+ ThunderBirdModel::GetInstance()->StopRecording();
+ ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_SPEAKING);
+ ThunderBirdModel::GetInstance()->SendRecording();
+ } else {
+ // 开始录音
+ ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_LISTENING);
+ ThunderBirdModel::GetInstance()->StartRecording();
+ }
+ }
+
+ /**
+ * @brief 检查是否可以调节音量
+ */
+ bool ThunderBirdPresenter::IsVolumeAdjustmentAvailable(int16_t currentView, int16_t currentSubView)
+ {
+ return (currentView == THUNDERBIRD_DIALOGUEVIEW ||
(currentView == THUNDERBIRD_LULLABYVIEW &&
(currentSubView == ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_1 ||
- currentSubView == ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_4))) //只有在对话界面还有哄睡界面才触发
- {
- ThunderBirdMainView::GetInstance()->ChangeThunderBirdReminderView(THUNDERBIRD_REMINDERVIEW);//不走ChangeView
- if (ThunderBirdReminderView::GetInstance())
- {
- ThunderBirdModel::GetInstance()->StartReminderHideTimer(1000);
- ThunderBirdReminderView::GetInstance()->Show(ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_VOLUME);
- ThunderBirdReminderView::GetInstance()->AdjustRemindProgress(-10);
- }
+ currentSubView == ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_4)));
+ }
+
+ /**
+ * @brief 显示音量调节界面
+ */
+ void ThunderBirdPresenter::ShowVolumeAdjustment(int volumeDelta)
+ {
+ ThunderBirdMainView::GetInstance()->ChangeThunderBirdReminderView(THUNDERBIRD_REMINDERVIEW);
+ if (ThunderBirdReminderView::GetInstance()) {
+ ThunderBirdModel::GetInstance()->StartReminderHideTimer(1000);
+ ThunderBirdReminderView::GetInstance()->Show(ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_VOLUME);
+ ThunderBirdReminderView::GetInstance()->AdjustRemindProgress(volumeDelta);
+ }
+ }
+
+ /**
+ * @brief 处理界面导航
+ */
+ bool ThunderBirdPresenter::HandleViewNavigation(int16_t currentView, int16_t currentSubView, bool isUpKey)
+ {
+ switch (currentView) {
+ case THUNDERBIRD_GUIDEVIEW:
+ return HandleGuideViewNavigation(currentSubView);
+
+ case THUNDERBIRD_DIALOGUEVIEW:
+ return HandleDialogueViewNavigation(currentSubView);
+
+ case THUNDERBIRD_OTAVIEW:
+ return HandleOtaViewNavigation(currentSubView);
+
+ case THUNDERBIRD_LULLABYVIEW:
+ return HandleLullabyViewNavigation(currentSubView);
+
+ case THUNDERBIRD_REMINDERVIEW:
+ return HandleReminderViewNavigation(currentSubView);
+
+ case THUNDERBIRD_ADJUSTVIEW:
+ return HandleAdjustViewNavigation(currentSubView);
+
+ default:
return true;
- }
- if(currentView == THUNDERBIRD_OTAVIEW)
- {
- if(currentSubView == ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_NORMAL
- || currentSubView == ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_OBVIOUS ) // 可选升级退出进入是否设置夜间更新,强制更新退出(直接关机)
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_NIGHT_UPDATE);
- }
- else if(currentSubView == ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_NIGHT_UPDATE
- || currentSubView == ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_COUNTDOWN
- || currentSubView == ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_UPDATE_FAILED
- || currentSubView == ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_LOW_BATTERY
- || currentSubView == ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_NETWORK_ERROR
- || currentSubView == ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_MEMORY_ERROR) // 夜间更新退出返回原任务,强制更新退出(直接关机),倒计时界面退出返回原任务,更新失败退出返回原任务,电量不足退出返回原任务,网络异常退出返回原任务,内存不足退出返回原任务
- {
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_SPEAKING);
- }
- }
}
-
+ }
+
+ // ==================== 界面导航处理函数 ====================
+
+ /**
+ * @brief 处理引导界面导航
+ */
+ bool ThunderBirdPresenter::HandleGuideViewNavigation(int16_t currentSubView)
+ {
+ switch (currentSubView) {
+ case ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_1:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_GUIDEVIEW, THUNDERBIRD_GUIDEVIEW, ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_2);
+ break;
+ case ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_2:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_GUIDEVIEW, THUNDERBIRD_GUIDEVIEW, ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3);
+ break;
+ case ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_GUIDEVIEW, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_SPEAKING);
+ break;
+ }
return true;
}
- void ThunderBirdPresenter::Notify()
+ /**
+ * @brief 处理对话界面导航
+ */
+ bool ThunderBirdPresenter::HandleDialogueViewNavigation(int16_t currentSubView)
{
-
- //如果在二维码界面 判断是否绑定
- if(ThunderBirdMainView::GetInstance() != nullptr)
- {
- int16_t currentView = ThunderBirdMainView::GetInstance()->GetCurrentView();
- int16_t currentSubView = ThunderBirdMainView::GetInstance()->GetCurrentSubView();
- //如果在二维码界面 要一直判断绑定状态 绑定成功就返回主界面
- if(currentSubView == ThunderBirdGuideView::THUNDERBIRD_GUIDEVIEW_3)
- {
- ThunderBirdModel::BindingStatus bindingStatus = ThunderBirdModel::GetInstance()->CheckBindingStatus();
- if(bindingStatus == ThunderBirdModel::BindingStatus::BOUND)
- {
- //绑定成功
- ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_SPEAKING);
- }
- else
- {
- //判断二维码的有效性
- if(ThunderBirdModel::GetInstance()->IsDeviceIdValid())
- {
- //更新二维码
- ThunderBirdGuideView::GetInstance()->UpdateQrcode();
- }
- }
- }
+ switch (currentSubView) {
+ case ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_SPEAKING:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_DIALOGUEVIEW, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_LISTENING);
+ break;
+ case ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_LISTENING:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_DIALOGUEVIEW, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_STATUS_SHOW);
+ break;
+ case ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_STATUS_SHOW:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_DIALOGUEVIEW, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_VOLUME);
+ break;
}
+ return true;
+ }
+
+ /**
+ * @brief 处理OTA界面导航
+ */
+ bool ThunderBirdPresenter::HandleOtaViewNavigation(int16_t currentSubView)
+ {
+ switch (currentSubView) {
+ case ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_UPDATE_NOW:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_OTAVIEW, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_NIGHT_UPDATE_SUCCESS);
+ break;
+
+ case ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_NORMAL:
+ case ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_OBVIOUS:
+ // 确认升级,检查条件
+ return CheckOtaConditionsAndProceed();
+
+ case ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_COUNTDOWN:
+ // 进入更新中
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_OTAVIEW, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_UPDATING);
+ do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_OTA_DOWNLOAD, NULL, 0);
+ break;
+
+ // VENDOR_DOWN键的特殊处理
+ case ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_NIGHT_UPDATE:
+ case ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_UPDATE_FAILED:
+ case ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_LOW_BATTERY:
+ case ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_NETWORK_ERROR:
+ case ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_MEMORY_ERROR:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_OTAVIEW, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_SPEAKING);
+ break;
+ }
+ return true;
+ }
+
+ /**
+ * @brief 检查OTA升级条件并继续
+ */
+ bool ThunderBirdPresenter::CheckOtaConditionsAndProceed()
+ {
+ if (ThunderBirdMainView::GetInstance()->Batteryvalue <= 50) {
+ // 低电量
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_OTAVIEW, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_LOW_BATTERY);
+ } else if (uapi_dev_runtime_get_cat1_signal() == 99) {
+ // 无网络
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_OTAVIEW, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_NETWORK_ERROR);
+ } else if (0) { // 获取内存状态
+ // 内存不足
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_OTAVIEW, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_MEMORY_ERROR);
+ } else {
+ // 条件满足,开始倒计时
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_OTAVIEW, THUNDERBIRD_OTAVIEW, ThunderBirdOtaView::THUNDERBIRD_OTAVIEW_COUNTDOWN);
+ }
+ return true;
+ }
+
+ /**
+ * @brief 处理哄睡界面导航
+ */
+ bool ThunderBirdPresenter::HandleLullabyViewNavigation(int16_t currentSubView)
+ {
+ switch (currentSubView) {
+ case ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_1:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_LULLABYVIEW, THUNDERBIRD_LULLABYVIEW, ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_2);
+ break;
+ case ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_2:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_LULLABYVIEW, THUNDERBIRD_LULLABYVIEW, ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_3);
+ break;
+ case ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_3:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_LULLABYVIEW, THUNDERBIRD_LULLABYVIEW, ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_4);
+ break;
+ case ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_4:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_LULLABYVIEW, THUNDERBIRD_LULLABYVIEW, ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_5);
+ break;
+ case ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_5:
+ // 返回主界面
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_LULLABYVIEW, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_SPEAKING);
+ break;
+ }
+ return true;
+ }
+
+ /**
+ * @brief 处理提醒界面导航
+ */
+ bool ThunderBirdPresenter::HandleReminderViewNavigation(int16_t currentSubView)
+ {
+ switch (currentSubView) {
+ case ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_VOLUME:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_REMINDERVIEW, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_TASK_REMINDER);
+ break;
+ case ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_TASK_REMINDER:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_REMINDERVIEW, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_NETWORK_DISCONNECT);
+ break;
+ case ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_NETWORK_DISCONNECT:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_REMINDERVIEW, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_LOW_BATTERY);
+ break;
+ case ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_LOW_BATTERY:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_REMINDERVIEW, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_CHARGING);
+ break;
+ case ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_CHARGING:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_REMINDERVIEW, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_CHARGE_COMPLETE);
+ break;
+ case ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_CHARGE_COMPLETE:
+ // 返回主界面
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_REMINDERVIEW, THUNDERBIRD_ADJUSTVIEW, ThunderBirdAdjustView::THUNDERBIRD_ADJUSTVIEW_BIND_SUCCESS);
+ break;
+ }
+ return true;
+ }
+
+ /**
+ * @brief 处理调节界面导航
+ */
+ bool ThunderBirdPresenter::HandleAdjustViewNavigation(int16_t currentSubView)
+ {
+ switch (currentSubView) {
+ case ThunderBirdAdjustView::THUNDERBIRD_ADJUSTVIEW_BIND_SUCCESS:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_ADJUSTVIEW, THUNDERBIRD_ADJUSTVIEW, ThunderBirdAdjustView::THUNDERBIRD_ADJUSTVIEW_WARNING);
+ break;
+ case ThunderBirdAdjustView::THUNDERBIRD_ADJUSTVIEW_WARNING:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_ADJUSTVIEW, THUNDERBIRD_ADJUSTVIEW, ThunderBirdAdjustView::THUNDERBIRD_ADJUSTVIEW_NETWORK_CONNECTING);
+ break;
+ case ThunderBirdAdjustView::THUNDERBIRD_ADJUSTVIEW_NETWORK_CONNECTING:
+ ThunderBirdMainView::GetInstance()->ChangeView(THUNDERBIRD_ADJUSTVIEW, THUNDERBIRD_SHUTDOWNVIEW, 0);
+ break;
+ }
+ return true;
}
}
#include "imsl_vad.h"
#include "media_thread_adapt.h"
#include "ln_api.h"
+#include "ln_api_interface.h"
#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
#define VAD_MAX_ARGC 8
/* 录音封装(由 C++ 提供,C 接口声明) */
extern int32_t AudioCaptureSample(int32_t argc, const char *argv[]);
+/* 对话控制相关AT命令函数声明 */
+static uint32_t ln_conversation_flag_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd);
+static uint32_t ln_push_text_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd);
+
/* 将 PCM 文件按 10ms(160点) 分帧喂给 VAD 并打印结果 */
static int AnalyzePcmFileWithVad(const char *pcm_path)
{
return ERRCODE_SUCC;
}
+/* ==================== 对话控制相关AT命令实现 ==================== */
+
+/**
+ * @brief 设置对话标志AT命令
+ * @param para 参数字符串
+ * @param paraLen 参数长度
+ * @param strCommonCmd 命令字符串
+ * @return 错误码
+ *
+ * 用法: AT^LN_CONV_FLAG=1 (设置开始对话标志)
+ * AT^LN_CONV_FLAG=0 (清除开始对话标志)
+ * AT^LN_CONV_FLAG? (查询当前标志状态)
+ */
+static uint32_t ln_conversation_flag_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+ VAD_UNUSED(strCommonCmd);
+
+ uint8_t argv[LN_MAX_ARGC][LN_MAX_ARGV_LEN] = {0};
+ uint32_t argc = 0;
+
+ // 解析参数
+ if (ConvertCmdToParam(para, paraLen, argv, &argc) != VAD_SUCCESS) {
+ printf("ERROR: Failed to parse parameters\n");
+ return ERRCODE_FAIL;
+ }
+
+ // 查询模式(无参数或参数为"?")
+ if (argc == 0 || (argc == 1 && strcmp((char*)argv[0], "?") == 0)) {
+ int current_flag = get_start_conversation_flag();
+ printf("+LN_CONV_FLAG: %d\n", current_flag);
+ return ERRCODE_SUCC;
+ }
+
+ if (argc < 1) {
+ printf("ERROR: Missing parameter\n");
+ printf("Usage: AT^LN_CONV_FLAG=1/0 or AT^LN_CONV_FLAG?\n");
+ return ERRCODE_FAIL;
+ }
+
+ // 设置模式
+ int flag = atoi((char*)argv[0]);
+ if (flag != 0 && flag != 1) {
+ printf("ERROR: Invalid flag value. Must be 0 or 1\n");
+ printf("Usage: AT^LN_CONV_FLAG=1/0\n");
+ return ERRCODE_FAIL;
+ }
+
+ set_start_conversation_flag(flag);
+ printf("+LN_CONV_FLAG: %d\n", flag);
+
+ return ERRCODE_SUCC;
+}
+
+/**
+ * @brief 推送文本到UI的AT命令
+ * @param para 参数字符串
+ * @param paraLen 参数长度
+ * @param strCommonCmd 命令字符串
+ * @return 错误码
+ *
+ * 用法: AT^LN_PUSH_TEXT=hello world
+ * AT^LN_PUSH_TEXT="测试文本"
+ */
+static uint32_t ln_push_text_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+ VAD_UNUSED(strCommonCmd);
+
+ uint8_t argv[LN_MAX_ARGC][LN_MAX_ARGV_LEN] = {0};
+ uint32_t argc = 0;
+
+ // 解析参数
+ if (ConvertCmdToParam(para, paraLen, argv, &argc) != VAD_SUCCESS) {
+ printf("ERROR: Failed to parse parameters\n");
+ return ERRCODE_FAIL;
+ }
+
+ if (argc < 1) {
+ printf("ERROR: Missing text parameter\n");
+ printf("Usage: AT^LN_PUSH_TEXT=your_text_here\n");
+ return ERRCODE_FAIL;
+ }
+
+ const char *text = (char*)argv[0];
+ if (text == NULL || strlen(text) == 0) {
+ printf("ERROR: Empty text parameter\n");
+ return ERRCODE_FAIL;
+ }
+
+ // 检查文本长度限制
+ if (strlen(text) > 512) {
+ printf("ERROR: Text too long (max 512 characters)\n");
+ return ERRCODE_FAIL;
+ }
+
+ // 推送文本到UI
+ push_text_to_ui(text);
+ printf("+LN_PUSH_TEXT: OK\n");
+ printf("Text pushed to UI: %s\n", text);
+
+ return ERRCODE_SUCC;
+}
static const at_cmd_table_t g_ln_api_cmd[] = {
/* ----------------------------------- VAD ---------------------------------- */
{(char *)"AT^LN_STORY_FINISH", ln_story_finish_at, (char *)"确认结束哄睡(JSON): AT^LN_STORY_FINISH"},
{(char *)"AT^LN_DEV_CHARACTER", ln_device_get_character_at, (char *)"获取设备角色信息(JSON,GET): AT^LN_DEV_CHARACTER"},
{(char *)"AT^LN_DEV_USERID", ln_device_get_userid_at, (char *)"获取设备绑定用户ID(JSON,GET): AT^LN_DEV_USERID"},
- // {(char *)"AT^LN_SET_DEV_USERID", ln_device_set_userid_at, (char *)"获取设备绑定用户ID(JSON,SET): AT^LN_DEV_USERID"},
+ {(char *)"AT^LN_SET_DEV_USERID", ln_device_set_userid_at, (char *)"获取设备绑定用户ID(JSON,SET): AT^LN_SET_DEV_USERID"},
{(char *)"AT^LN_OTA_GET_TASK", ln_ota_get_task_at, (char *)"获取OTA升级任务(JSON,GET): AT^LN_OTA_GET_TASK"},
{(char *)"AT^LN_OTA_DOWNLOAD", ln_ota_download_at, (char *)"下载OTA升级包(JSON,GET->下载): AT^LN_OTA_DOWNLOAD"},
{(char *)"AT^LN_AUDIO_PLAY_FILE", ln_audio_play_file_at, (char *)"播放指定文件: AT^LN_AUDIO_PLAY_FILE=/path/to/file.mp3"},
{(char *)"AT^LN_AUDIO_PAUSE", ln_audio_pause_at, (char *)"暂停播放: AT^LN_AUDIO_PAUSE"},
{(char *)"AT^LN_AUDIO_RESUME", ln_audio_resume_at, (char *)"恢复播放: AT^LN_AUDIO_RESUME"},
+
+ /* 对话控制 */
+ {(char *)"AT^LN_CONV_FLAG", ln_conversation_flag_at, (char *)"设置对话标志: AT^LN_CONV_FLAG=1/0"},
+ {(char *)"AT^LN_PUSH_TEXT", ln_push_text_at, (char *)"推送文本到UI: AT^LN_PUSH_TEXT=hello world"},
};