远程遥控开发中
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/data/models/running_status_model.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_state.dart';
|
||||
|
||||
import '../../domain/entities/machine_control_status_entity.dart';
|
||||
@@ -11,7 +12,12 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
Timer? _timer;
|
||||
|
||||
RemoteControlCubit(this._repository)
|
||||
: super(RemoteControlState(controlEntity: MachineControlStatusEntity())) {
|
||||
: super(
|
||||
RemoteControlState(
|
||||
controlEntity: MachineControlStatusEntity(),
|
||||
runningStatusModel: RunningStatusModel(),
|
||||
),
|
||||
) {
|
||||
_initPacketListener();
|
||||
}
|
||||
|
||||
@@ -78,6 +84,10 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
// _sendProtocolData(0x12, ...);
|
||||
}
|
||||
|
||||
void toggleLeftPip() => emit(state.copyWith(showLeftPip: !state.showLeftPip));
|
||||
void toggleRightPip() =>
|
||||
emit(state.copyWith(showRightPip: !state.showRightPip));
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_timer?.cancel(); // 退出页面时务必销毁定时器
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/data/models/running_status_model.dart';
|
||||
|
||||
import '../../domain/entities/machine_control_status_entity.dart';
|
||||
|
||||
enum RemoteControlStatus { initial, controlling, error }
|
||||
|
||||
enum ControlMode { TCP, BLE, LOCAL, NONE, OTHER }
|
||||
|
||||
class RemoteControlState extends Equatable {
|
||||
final RemoteControlStatus status;
|
||||
final MachineControlStatusEntity controlEntity; // 之前的业务实体
|
||||
final MachineControlStatusEntity controlEntity; // 控制业务实体
|
||||
final RunningStatusModel runningStatusModel;
|
||||
//状态业务实体
|
||||
final String? errorMessage;
|
||||
final bool hasPermission; // 是否获得了 0x12 权限
|
||||
final bool isEmergency;
|
||||
final bool isLocked;
|
||||
final int ping;
|
||||
final int battery;
|
||||
final int voltage;
|
||||
final String permissionPlatform;
|
||||
final String currentPlatform;
|
||||
final bool showPermissionRequestDialog;
|
||||
final bool showLeftPip;
|
||||
final bool showRightPip;
|
||||
|
||||
final String obstacleFlag; //障碍物标志位
|
||||
|
||||
const RemoteControlState({
|
||||
this.status = RemoteControlStatus.initial,
|
||||
@@ -26,9 +36,14 @@ class RemoteControlState extends Equatable {
|
||||
this.isLocked = false,
|
||||
this.ping = 0,
|
||||
this.battery = 0,
|
||||
this.voltage = 0,
|
||||
this.permissionPlatform = '',
|
||||
this.currentPlatform = '',
|
||||
this.showPermissionRequestDialog = false,
|
||||
this.showLeftPip = true,
|
||||
this.showRightPip = true,
|
||||
this.obstacleFlag = '',
|
||||
required this.runningStatusModel,
|
||||
});
|
||||
|
||||
// 方便 UI 更新部分属性
|
||||
@@ -41,9 +56,14 @@ class RemoteControlState extends Equatable {
|
||||
bool? isLocked,
|
||||
int? ping,
|
||||
int? battery,
|
||||
int? voltage,
|
||||
String? permissionPlatform,
|
||||
String? currentPlatform,
|
||||
bool? showPermissionRequestDialog,
|
||||
bool? showLeftPip,
|
||||
bool? showRightPip,
|
||||
RunningStatusModel? runningStatusModel,
|
||||
String? obstacleFlag,
|
||||
}) {
|
||||
return RemoteControlState(
|
||||
status: status ?? this.status,
|
||||
@@ -54,10 +74,15 @@ class RemoteControlState extends Equatable {
|
||||
isLocked: isLocked ?? this.isLocked,
|
||||
ping: ping ?? this.ping,
|
||||
battery: battery ?? this.battery,
|
||||
voltage: voltage ?? this.voltage,
|
||||
permissionPlatform: permissionPlatform ?? this.permissionPlatform,
|
||||
currentPlatform: currentPlatform ?? this.currentPlatform,
|
||||
showPermissionRequestDialog:
|
||||
showPermissionRequestDialog ?? this.showPermissionRequestDialog,
|
||||
showLeftPip: showLeftPip ?? this.showLeftPip,
|
||||
showRightPip: showRightPip ?? this.showRightPip,
|
||||
runningStatusModel: runningStatusModel ?? this.runningStatusModel,
|
||||
obstacleFlag: obstacleFlag ?? this.obstacleFlag,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,8 +96,13 @@ class RemoteControlState extends Equatable {
|
||||
isLocked,
|
||||
ping,
|
||||
battery,
|
||||
voltage,
|
||||
permissionPlatform,
|
||||
currentPlatform,
|
||||
showPermissionRequestDialog,
|
||||
showLeftPip,
|
||||
showRightPip,
|
||||
runningStatusModel,
|
||||
obstacleFlag,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user