优化和路径规划新适配
This commit is contained in:
@@ -79,6 +79,7 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
String? _cacheBattery;
|
||||
String? _cacheCtrlMode;
|
||||
int? _cachePing;
|
||||
DateTime? _lastStatusPushTime; // 最后一次收到设备状态推送的时间
|
||||
|
||||
void _initDeviceStatusListener() {
|
||||
_deviceStatusSub?.cancel();
|
||||
@@ -97,6 +98,7 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
_cacheBattery = battery.toString();
|
||||
_cacheCtrlMode = controlMode;
|
||||
_cachePing = c;
|
||||
_lastStatusPushTime = DateTime.now(); // 记录最后一次推送时间
|
||||
|
||||
// 500ms节流,不到时间不刷新UI
|
||||
final now = DateTime.now();
|
||||
@@ -117,6 +119,7 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
),
|
||||
battery: int.tryParse(_cacheBattery ?? '') ?? 0,
|
||||
ping: _cachePing,
|
||||
hasReceivedStatusPush: true, // 标记已收到设备状态推送
|
||||
// 🔥 标记为设备状态更新
|
||||
updateType: 'device_status',
|
||||
),
|
||||
@@ -677,6 +680,22 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
void toggleRightPip() =>
|
||||
emit(state.copyWith(showRightPip: !state.showRightPip));
|
||||
|
||||
// 🔥 切换前后视角(双击屏幕触发)
|
||||
void toggleCameraView() {
|
||||
final currentOriginY = state.controlEntity.originY;
|
||||
// 🔥 originY >= 0 表示前视角,< 0 表示后视角
|
||||
// 切换逻辑:如果当前是前视角(>=0),切换到后视角(-1);反之亦然
|
||||
final newOriginY = currentOriginY >= 0 ? -1 : 1;
|
||||
|
||||
debugPrint('📷 [RemoteControlCubit] 切换前后视角: $currentOriginY -> $newOriginY');
|
||||
|
||||
final updatedEntity = state.controlEntity.copyWith(y: newOriginY);
|
||||
emit(state.copyWith(controlEntity: updatedEntity));
|
||||
|
||||
// 🔥 发送 TCP 指令到设备
|
||||
_repository.sendControlMachineCmd(updatedEntity);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_timer?.cancel();
|
||||
@@ -926,6 +945,14 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
emit(state.copyWith(topRightIsExpanded: !state.topRightIsExpanded));
|
||||
}
|
||||
|
||||
/// 检查设备状态推送是否活跃(5秒内有推送视为活跃)
|
||||
bool isStatusPushActive() {
|
||||
if (!state.hasReceivedStatusPush) return false;
|
||||
if (_lastStatusPushTime == null) return false;
|
||||
// 超过5秒未收到新推送,视为推送已中断
|
||||
return DateTime.now().difference(_lastStatusPushTime!) < const Duration(seconds: 5);
|
||||
}
|
||||
|
||||
Future<int> getNetworkDelay() async {
|
||||
try {
|
||||
// 直接 Ping 你的服务器IP
|
||||
@@ -956,6 +983,10 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
debugPrint('🎯 [RemoteControl] 设备名称: ${device.deviceName}');
|
||||
debugPrint('🎯 [RemoteControl] 当前TCP状态: ${tcpClient.isConnected ? "已连接" : "未连接"}');
|
||||
|
||||
// 🔥 关键修复:切换设备时清空所有缓存,防止显示上一个设备的数据
|
||||
_clearAllCache();
|
||||
debugPrint('✅ [RemoteControl] 已清空所有缓存数据');
|
||||
|
||||
debugPrint('📦 [RemoteControl] 更新targetDevice状态');
|
||||
emit(state.copyWith(targetDevice: device));
|
||||
debugPrint('✅ [RemoteControl] targetDevice状态已更新');
|
||||
@@ -997,6 +1028,11 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
void clearTargetDevice() {
|
||||
// debugPrint('🧹 [RemoteControl] 清除待控制设备');
|
||||
// _logger.logWithLevel('🧹 [RemoteControl] 清除待控制设备');
|
||||
|
||||
// 🔥 关键修复:退出页面时清空所有缓存,防止数据滞留
|
||||
_clearAllCache();
|
||||
debugPrint('✅ [RemoteControl] 已清空所有缓存数据');
|
||||
|
||||
emit(state.copyWith(targetDevice: null));
|
||||
}
|
||||
|
||||
@@ -1006,5 +1042,32 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
return state.targetDevice;
|
||||
}
|
||||
|
||||
/// 🔥 清空所有缓存数据(解决数据滞留和跨设备数据显示问题)
|
||||
void _clearAllCache() {
|
||||
_cacheVoltage = null;
|
||||
_cacheBattery = null;
|
||||
_cacheCtrlMode = null;
|
||||
_cachePing = null;
|
||||
_lastUiUpdateTime = null;
|
||||
_lastStatusPushTime = null; // 重置推送时间
|
||||
|
||||
// 🔥 同时重置 UI 状态为初始值
|
||||
if (!isClosed) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
runningStatusModel: state.runningStatusModel.copyWith(
|
||||
voltage: '--',
|
||||
battery: '--',
|
||||
controlMode: '--',
|
||||
),
|
||||
battery: 0,
|
||||
ping: null,
|
||||
hasReceivedStatusPush: false, // 重置推送接收标志
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
debugPrint('🗑️ [RemoteControl] 缓存已清空 - voltage, battery, controlMode, ping');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ class RemoteControlState extends Equatable {
|
||||
final String obstacleFlag; //障碍物标志位
|
||||
final RunningStatusModel runningStatusModel;
|
||||
final DeviceEntity? targetDevice;
|
||||
final bool hasReceivedStatusPush; // 是否收到过设备状态推送
|
||||
|
||||
// 🔥 状态更新类型标记 - 用于区分是设备状态更新还是弹窗状态更新
|
||||
final String? updateType;
|
||||
@@ -53,6 +54,7 @@ class RemoteControlState extends Equatable {
|
||||
this.showRightPip = true,
|
||||
this.obstacleFlag = '',
|
||||
required this.runningStatusModel,
|
||||
this.hasReceivedStatusPush = false,
|
||||
this.topRightIsExpanded = false,
|
||||
this.obstacleRecognitionFlag = true,
|
||||
this.targetDevice,
|
||||
@@ -79,6 +81,7 @@ class RemoteControlState extends Equatable {
|
||||
bool? showRightPip,
|
||||
RunningStatusModel? runningStatusModel,
|
||||
String? obstacleFlag,
|
||||
bool? hasReceivedStatusPush,
|
||||
bool? topRightIsExpanded,
|
||||
bool? obstacleRecognitionFlag,
|
||||
DeviceEntity? targetDevice,
|
||||
@@ -104,6 +107,7 @@ class RemoteControlState extends Equatable {
|
||||
showRightPip: showRightPip ?? this.showRightPip,
|
||||
runningStatusModel: runningStatusModel ?? this.runningStatusModel,
|
||||
obstacleFlag: obstacleFlag ?? this.obstacleFlag,
|
||||
hasReceivedStatusPush: hasReceivedStatusPush ?? this.hasReceivedStatusPush,
|
||||
topRightIsExpanded: topRightIsExpanded ?? this.topRightIsExpanded,
|
||||
obstacleRecognitionFlag:
|
||||
obstacleRecognitionFlag ?? this.obstacleRecognitionFlag,
|
||||
@@ -132,6 +136,7 @@ class RemoteControlState extends Equatable {
|
||||
showRightPip,
|
||||
runningStatusModel,
|
||||
obstacleFlag,
|
||||
hasReceivedStatusPush,
|
||||
topRightIsExpanded,
|
||||
obstacleRecognitionFlag,
|
||||
targetDevice,
|
||||
|
||||
Reference in New Issue
Block a user