APP远程遥控推出页面释放权限集成-待测试
This commit is contained in:
@@ -229,7 +229,15 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
void startControlLoop() {
|
||||
_timer?.cancel();
|
||||
_timer = Timer.periodic(const Duration(milliseconds: 100), (timer) {
|
||||
// 核心调用:直接把 state 里的实体丢给 repository
|
||||
// 🔥 安全检查:无权限或急停时不发送
|
||||
if (!state.hasPermission || state.isEmergency) {
|
||||
debugPrint('⚠️ [定时器] 跳过发送 - hasPermission=${state.hasPermission}, isEmergency=${state.isEmergency}');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
debugPrint('⏰ [定时器] 发送控制指令 - originX=${state.controlEntity.originX}, originY=${state.controlEntity.originY}');
|
||||
_logger.logWithLevel('真实的发送的实体 - originX: ${state.controlEntity.originX}, originY: ${state.controlEntity.originY}');
|
||||
_repository.sendControlMachineCmd(state.controlEntity);
|
||||
});
|
||||
emit(state.copyWith(status: RemoteControlStatus.controlling));
|
||||
@@ -264,16 +272,36 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
}
|
||||
|
||||
void updateOriginY(int y) {
|
||||
debugPrint('📥 [updateOriginY] 收到参数 y=$y');
|
||||
final updatedEntity = state.controlEntity.copyWith(
|
||||
y: y,
|
||||
);
|
||||
debugPrint('📤 [updateOriginY] 创建 updatedEntity.y=${updatedEntity.originY}');
|
||||
emit(state.copyWith(controlEntity: updatedEntity));
|
||||
debugPrint('✅ [updateOriginY] emit 完成,当前 state.controlEntity.originY=${state.controlEntity.originY}');
|
||||
|
||||
// 🔥 关键修复:如果归零,立即发送停止指令,使用更新后的实体
|
||||
if (y == 0) {
|
||||
_logger.logWithLevel('🛑 [updateOriginY] 检测到归零,立即发送停止指令');
|
||||
debugPrint('🛑 [updateOriginY] 发送 updatedEntity: originX=${updatedEntity.originX}, originY=${updatedEntity.originY}');
|
||||
_repository.sendControlMachineCmd(updatedEntity);
|
||||
}
|
||||
}
|
||||
void updateOriginX(int x) {
|
||||
debugPrint('📥 [updateOriginX] 收到参数 x=$x');
|
||||
final updatedEntity = state.controlEntity.copyWith(
|
||||
x: x,
|
||||
);
|
||||
debugPrint('📤 [updateOriginX] 创建 updatedEntity.x=${updatedEntity.originX}');
|
||||
emit(state.copyWith(controlEntity: updatedEntity));
|
||||
debugPrint('✅ [updateOriginX] emit 完成,当前 state.controlEntity.originX=${state.controlEntity.originX}');
|
||||
|
||||
// 🔥 关键修复:如果归零,立即发送停止指令,使用更新后的实体
|
||||
if (x == 0) {
|
||||
_logger.logWithLevel('🛑 [updateOriginX] 检测到归零,立即发送停止指令');
|
||||
debugPrint('🛑 [updateOriginX] 发送 updatedEntity: originX=${updatedEntity.originX}, originY=${updatedEntity.originY}');
|
||||
_repository.sendControlMachineCmd(updatedEntity);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 停止控制循环
|
||||
@@ -416,6 +444,10 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
return 9999;
|
||||
}
|
||||
}
|
||||
//app退出远程遥控界面释放权限
|
||||
Future<bool> releasePermission(String platform) async {
|
||||
return await _repository.releasePermission(platform);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -28,11 +28,13 @@ class RemoteControlPage extends StatefulWidget {
|
||||
class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
String _videoStreamUrl = "";
|
||||
late RemoteControlCubit _cubit;
|
||||
DevicesCubit? _devicesCubit;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_cubit = context.read<RemoteControlCubit>();
|
||||
_devicesCubit = context.read<DevicesCubit>();
|
||||
}
|
||||
@override
|
||||
void initState() {
|
||||
@@ -53,9 +55,16 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// 释放远程控制权限
|
||||
// _cubit.releasePermission("app");
|
||||
//print("远程控制要推出啦");
|
||||
final deviceState = _devicesCubit?.state;
|
||||
if (deviceState?.selectedDevice != null) {
|
||||
_cubit.releasePermission("app");
|
||||
}
|
||||
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
// context.read<RemoteControlCubit>().stopControlLoop();
|
||||
_cubit.stopControlLoop();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -138,7 +147,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
width: sideAreaWidth,
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: LeftJoystickArea(isLocked: remoteState.isLocked, width: sideAreaWidth * 0.5 * 0.7),
|
||||
child: LeftJoystickArea(isLocked: remoteState.isLocked, width: sideAreaWidth * 0.45),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -156,7 +165,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
width: sideAreaWidth,
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: RightJoystickArea(isLocked: remoteState.isLocked, width: sideAreaWidth * 0.5 * 0.7),
|
||||
child: RightJoystickArea(isLocked: remoteState.isLocked, width: sideAreaWidth * 0.45),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user