完善遥控权限、控制发送和急停反馈
This commit is contained in:
@@ -8,7 +8,7 @@ import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remot
|
||||
/// 由调用方决定注入哪一个实现,UI 与控制语义代码零改动。
|
||||
///
|
||||
/// 段位值统一沿用远程遥控编码:上=1、中=0、下=2
|
||||
/// (割刀 1 抬 / 2 降、底盘 1 升 / 2 降、点火 1 点火 / 2 熄火,0 都是停止)。
|
||||
/// 割刀段位由 Cubit 映射为开1/关0/不操作2;底盘、点火编码不变。
|
||||
abstract interface class PvRobotCommandChannel {
|
||||
/// 前进 / 后退(左摇杆,-100~100,上推为正=前进)。
|
||||
void sendDriveY(int y);
|
||||
@@ -19,19 +19,19 @@ abstract interface class PvRobotCommandChannel {
|
||||
/// 底盘升降。
|
||||
void sendChassis(int cmd);
|
||||
|
||||
/// 割刀升降。
|
||||
/// 割刀滑块段位:1=上拨开启、2=下拨关闭、0=回中不操作。
|
||||
void sendMower(int cmd);
|
||||
|
||||
/// 点火 / 熄火。
|
||||
void sendIgnition(int cmd);
|
||||
|
||||
/// 紧急停止。
|
||||
void sendEmergencyStop(bool on);
|
||||
Future<bool> sendEmergencyStop(bool on);
|
||||
|
||||
/// 双轴归零(松手即停,安全底线)。
|
||||
Future<void> stopAllMovement();
|
||||
|
||||
/// 进入控制态:查询一次控制权限,并开始持续下发控制帧(默认 100ms 控制循环)。
|
||||
/// 进入控制态:查询一次控制权限,并开始持续下发控制帧(默认 250ms 控制循环)。
|
||||
void activate();
|
||||
|
||||
/// 退出控制态:归零、停止控制循环、释放控制权、复位权限。
|
||||
@@ -58,22 +58,22 @@ class RemoteControlRobotChannel implements PvRobotCommandChannel {
|
||||
void sendChassis(int cmd) => _cubit.sendChassisCommand(cmd);
|
||||
|
||||
@override
|
||||
void sendMower(int cmd) => _cubit.sendMowerCommand(cmd);
|
||||
void sendMower(int cmd) => _cubit.sendMowerSliderCommand(cmd);
|
||||
|
||||
@override
|
||||
void sendIgnition(int cmd) => _cubit.sendFireCommand(cmd);
|
||||
|
||||
@override
|
||||
void sendEmergencyStop(bool on) => _cubit.updateEmergency(on);
|
||||
Future<bool> sendEmergencyStop(bool on) => _cubit.updateEmergency(on);
|
||||
|
||||
@override
|
||||
Future<void> stopAllMovement() => _cubit.stopAllMovement();
|
||||
Future<void> stopAllMovement() => _cubit.stopAllMovement(reason: 'hud_stop');
|
||||
|
||||
@override
|
||||
void activate() {
|
||||
final cubit = _cubit;
|
||||
// 与远程遥控页一致:进控制态先「仅查询」一次控制权限(grabControl=false,
|
||||
// 只把接口结果如实同步到 hasPermission,不发 TCP 抢占),再启动 100ms 控制循环。
|
||||
// 只把接口结果如实同步到 hasPermission,不发 TCP 抢占),再启动 250ms 控制循环。
|
||||
// 无权限时控制循环会自动跳过发送,行为与极简模式完全相同。
|
||||
final deviceName = cubit.state.targetDevice?.deviceName;
|
||||
if (deviceName != null && deviceName.isNotEmpty) {
|
||||
@@ -90,11 +90,11 @@ class RemoteControlRobotChannel implements PvRobotCommandChannel {
|
||||
|
||||
@override
|
||||
Future<bool?> deactivate() async {
|
||||
// 先解除急停,避免 HUD 退出时残留 isEmergency=true,
|
||||
// 让下一次进入(含极简远程遥控页)控制循环被锁住无法运动。
|
||||
_cubit.updateEmergency(false);
|
||||
_cubit.cancelPermissionRequest();
|
||||
// 退出页面不再自动解除急停;只有明确的用户操作可发送 eStop=0。
|
||||
// 旧调用保留:_cubit.updateEmergency(false);
|
||||
// 停止指令无视权限强制发送,先归零再停循环,避免残留运动。
|
||||
await _cubit.stopAllMovement();
|
||||
await _cubit.stopAllMovement(reason: 'hud_deactivate');
|
||||
_cubit.stopControlLoop();
|
||||
// 与远程遥控页一致:退出释放远程控制权限(type=2),设备名取当前 targetDevice。
|
||||
final deviceId = _cubit.state.targetDevice?.deviceName;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../../../devices/domain/entities/running_status_entity.dart';
|
||||
|
||||
/// 光伏巡检机器人实时遥测数据(本批次为 Mock 假数据,后续可替换为 MQTT/TCP 真实来源)
|
||||
/// 光伏巡检机器人遥测数据;状态值缺失时保留 null,由 UI 展示未知。
|
||||
///
|
||||
/// 采用不可变对象 + copyWith,便于后续接入真实数据流时局部更新字段。
|
||||
@immutable
|
||||
@@ -15,7 +16,14 @@ class PvTelemetry {
|
||||
this.isAutoDriving = true,
|
||||
// 默认留空:具体文案由 UI 层按当前语言兜底(见 PvInfoColumn)
|
||||
this.taskStatus = '',
|
||||
this.speed = 0.3,
|
||||
this.speed,
|
||||
this.leftMeasuredRpm,
|
||||
this.rightMeasuredRpm,
|
||||
this.leftTargetRpm,
|
||||
this.rightTargetRpm,
|
||||
this.mowerRpm,
|
||||
this.motion,
|
||||
this.emergencyStop,
|
||||
this.mileage,
|
||||
this.networkNormal = true,
|
||||
this.temperature,
|
||||
@@ -39,8 +47,58 @@ class PvTelemetry {
|
||||
final bool isAutoDriving;
|
||||
final String taskStatus;
|
||||
|
||||
/// 当前速度 m/s
|
||||
final double speed;
|
||||
/// 当前线速度 m/s;负数表示倒车,null 表示未有效上报。
|
||||
final double? speed;
|
||||
final double? leftMeasuredRpm;
|
||||
final double? rightMeasuredRpm;
|
||||
final double? leftTargetRpm;
|
||||
final double? rightTargetRpm;
|
||||
|
||||
/// 车辆实时 cuttingSpeed / TCP 割刀转速;不使用本地启停指令推断。
|
||||
final double? mowerRpm;
|
||||
final String? motion;
|
||||
final bool? emergencyStop;
|
||||
|
||||
/// 每次从当前状态生成新快照,缺失字段不会沿用上帧数值或默认零值。
|
||||
factory PvTelemetry.fromRunningStatus(
|
||||
RunningStatusEntity? status, {
|
||||
String deviceName = '',
|
||||
bool obstacleAlert = false,
|
||||
}) {
|
||||
final raw = status?.hostRealtime?.rawData ?? const <String, dynamic>{};
|
||||
double? number(String field) {
|
||||
final value = raw[field];
|
||||
final parsed = value is num
|
||||
? value.toDouble()
|
||||
: double.tryParse(value?.toString() ?? '');
|
||||
return parsed != null && parsed.isFinite ? parsed : null;
|
||||
}
|
||||
|
||||
final cutter = double.tryParse(status?.knifeCuttingSpeed ?? '');
|
||||
final battery = number('battery_percentage');
|
||||
return PvTelemetry(
|
||||
deviceName: deviceName,
|
||||
obstacleAlert: obstacleAlert,
|
||||
battery: battery != null && battery >= 0 && battery <= 100
|
||||
? battery
|
||||
: null,
|
||||
mileage: number('total_work_distance'),
|
||||
temperature: number('main_temperature'),
|
||||
speed: number('linear_speed'),
|
||||
leftMeasuredRpm: number('left_measured_rpm'),
|
||||
rightMeasuredRpm: number('right_measured_rpm'),
|
||||
leftTargetRpm: number('left_target_rpm'),
|
||||
rightTargetRpm: number('right_target_rpm'),
|
||||
mowerRpm: cutter != null && cutter.isFinite ? cutter : null,
|
||||
motion: status?.hostRealtime?.motion,
|
||||
emergencyStop: status?.emergencyStop,
|
||||
controlMode: status?.controlMode,
|
||||
fixStatus: status?.qual,
|
||||
satelliteCount: status != null && status.satelliteCnt > 0
|
||||
? status.satelliteCnt
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
/// 巡检里程(累计作业里程);null=未收到实时数据(显示"未知")
|
||||
final double? mileage;
|
||||
@@ -79,6 +137,13 @@ class PvTelemetry {
|
||||
bool? isAutoDriving,
|
||||
String? taskStatus,
|
||||
double? speed,
|
||||
double? leftMeasuredRpm,
|
||||
double? rightMeasuredRpm,
|
||||
double? leftTargetRpm,
|
||||
double? rightTargetRpm,
|
||||
double? mowerRpm,
|
||||
String? motion,
|
||||
bool? emergencyStop,
|
||||
double? mileage,
|
||||
bool? networkNormal,
|
||||
double? temperature,
|
||||
@@ -98,6 +163,13 @@ class PvTelemetry {
|
||||
isAutoDriving: isAutoDriving ?? this.isAutoDriving,
|
||||
taskStatus: taskStatus ?? this.taskStatus,
|
||||
speed: speed ?? this.speed,
|
||||
leftMeasuredRpm: leftMeasuredRpm ?? this.leftMeasuredRpm,
|
||||
rightMeasuredRpm: rightMeasuredRpm ?? this.rightMeasuredRpm,
|
||||
leftTargetRpm: leftTargetRpm ?? this.leftTargetRpm,
|
||||
rightTargetRpm: rightTargetRpm ?? this.rightTargetRpm,
|
||||
mowerRpm: mowerRpm ?? this.mowerRpm,
|
||||
motion: motion ?? this.motion,
|
||||
emergencyStop: emergencyStop ?? this.emergencyStop,
|
||||
mileage: mileage ?? this.mileage,
|
||||
networkNormal: networkNormal ?? this.networkNormal,
|
||||
temperature: temperature ?? this.temperature,
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import 'dart:async';
|
||||
import 'package:maibu_satabot_v2/features/device_control_mode/domain/entities/device_control_mode.dart';
|
||||
import 'package:maibu_satabot_v2/features/device_control_mode/presentation/widgets/control_mode_entry_gate.dart';
|
||||
import 'package:maibu_satabot_v2/features/device_control_mode/presentation/widgets/mode_independent_control.dart';
|
||||
import 'dart:io';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../remote_control/presentation/widgets/emergency_stop_confirmation.dart';
|
||||
import '../../../remote_control/presentation/widgets/emergency_stop_button.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@@ -12,13 +15,14 @@ import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/tcp_consts.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/env_config.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/auth/presentation/bloc/auth_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/widgets/remote_control_link_feedback.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/local_camera/presentation/cubit/local_camera_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/usb_camera/data/uvc_camera_service.dart';
|
||||
@@ -75,7 +79,6 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
final GlobalKey _videoKey = GlobalKey();
|
||||
|
||||
/// 本批次使用 Mock 遥测数据
|
||||
final PvTelemetry _telemetry = const PvTelemetry();
|
||||
|
||||
/// 遥控指令传输通道:当前为 TCP 实现(委托 `RemoteControlCubit`),
|
||||
/// 以后接蓝牙 / 下位机只换一个实现类,HUD 与本页面代码零改动。
|
||||
@@ -89,13 +92,11 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
/// 尾部那次 stopControlLoop() 会把刚起来的循环又关掉,HUD 就变成
|
||||
/// “摇杆推了没反应”。故延后到 deactivate 收尾再起循环。
|
||||
bool _deactivating = false;
|
||||
bool _emergencyConfirming = false;
|
||||
|
||||
/// deactivate 期间收到过重新进入控制态的请求。
|
||||
bool _restartAfterDeactivate = false;
|
||||
|
||||
/// 急停开关态:HUD 急停钮每点一次翻转,经通道下发 updateEmergency。
|
||||
bool _emergencyOn = false;
|
||||
|
||||
/// 远程控制单例(HUD 与原远程遥控页共用它,指令通道内部也委托它)。
|
||||
RemoteControlCubit get _cubit => sl<RemoteControlCubit>();
|
||||
|
||||
@@ -147,41 +148,12 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
: AppLocalizations.of(context).translate('pv_control.no_device');
|
||||
}
|
||||
|
||||
/// 实际下发的遥测:真实字段来自全局 [DeviceStatusBloc] 的 host 实时数据
|
||||
/// (电量/巡检里程/设备温度),未收到时置 null 由 UI 显示"未知";
|
||||
/// 开启「模拟障碍物信息」相当于收到机器告警推送,叠加 obstacleAlert。
|
||||
/// 使用当前设备的实时快照;未上报的字段由 UI 显示未知。
|
||||
PvTelemetry _resolveTelemetry(DeviceStatusState dsState, String deviceName) {
|
||||
double? battery;
|
||||
double? mileage;
|
||||
double? temp;
|
||||
int? fixStatus;
|
||||
int? satelliteCount;
|
||||
String? controlMode;
|
||||
if (dsState is DeviceStatusUpdated) {
|
||||
final s = dsState.status;
|
||||
// 定位质量:来自 location/post 的 fix_status(qual)
|
||||
fixStatus = s.qual;
|
||||
// 控制模式:与“设备数据监控”同一口径,只要收到状态就跟随,不加 host 门控
|
||||
controlMode = s.controlMode;
|
||||
// 卫星数:realtime/post 尚未推送,无数据源时保持 null 显示"未知"
|
||||
if (s.satelliteCnt > 0) satelliteCount = s.satelliteCnt;
|
||||
// 以下三项来自 host 实时话题(device/{sn}/host/realTime/message)
|
||||
if (s.hostDataReceived) {
|
||||
battery = double.tryParse(s.battery);
|
||||
mileage = s.totalWorkDistance;
|
||||
temp = s.chipTemp;
|
||||
}
|
||||
}
|
||||
return _telemetry.copyWith(
|
||||
// 设备名用真实选中的设备,不再用 PvTelemetry 里写死的占位名
|
||||
return PvTelemetry.fromRunningStatus(
|
||||
dsState is DeviceStatusUpdated ? dsState.status : null,
|
||||
deviceName: deviceName,
|
||||
obstacleAlert: _simObstacle,
|
||||
battery: battery,
|
||||
mileage: mileage,
|
||||
temperature: temp,
|
||||
fixStatus: fixStatus,
|
||||
satelliteCount: satelliteCount,
|
||||
controlMode: controlMode,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -230,7 +202,7 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
if (widget.deviceId.isNotEmpty && token != null) {
|
||||
setState(() {
|
||||
_streamUrl =
|
||||
'webrtc://${TCPConsts.TCP_IP}/live/livestream/${widget.deviceId}?token=$token';
|
||||
'webrtc://${EnvConfig.webRtcStreamAuthority}/live/livestream/${widget.deviceId}?token=$token';
|
||||
});
|
||||
} else {
|
||||
debugPrint('❌ [PvControl] 视频URL初始化失败:deviceId 或 token 为空');
|
||||
@@ -310,15 +282,43 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
);
|
||||
}
|
||||
|
||||
void _onEmergencyStop() {
|
||||
// HUD 急停钮为“点一下急停 / 再点一下恢复”的切换态(按钮自身不携带 on/off)。
|
||||
_emergencyOn = !_emergencyOn;
|
||||
_channel.sendEmergencyStop(_emergencyOn);
|
||||
Future<void> _onEmergencyStop() async {
|
||||
if (_emergencyConfirming || _cubit.state.isEmergencyRequestPending) return;
|
||||
final sn = _cubit.state.targetDevice?.deviceName;
|
||||
final on = !_cubit.state.isEmergency;
|
||||
if (!_cubit.checkEmergencyRequest(on)) {
|
||||
CapsuleToast.show(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.${_cubit.state.emergencyFeedbackKey}'),
|
||||
showCheck: false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!_cubit.checkEmergencyRequest(on)) {
|
||||
CapsuleToast.show(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.${_cubit.state.emergencyFeedbackKey}'),
|
||||
showCheck: false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
_emergencyConfirming = true;
|
||||
bool confirmed;
|
||||
try {
|
||||
confirmed = await confirmEmergencyStop(context, engage: on, sn: sn ?? '');
|
||||
} finally {
|
||||
_emergencyConfirming = false;
|
||||
}
|
||||
if (!confirmed || !mounted || sn != _cubit.state.targetDevice?.deviceName) {
|
||||
return;
|
||||
}
|
||||
await _channel.sendEmergencyStop(on);
|
||||
if (!mounted || sn != _cubit.state.targetDevice?.deviceName) return;
|
||||
final tr = AppLocalizations.of(context);
|
||||
CapsuleToast.show(
|
||||
_emergencyOn
|
||||
? tr.translate('pv_control.toast_emergency_sent')
|
||||
: tr.translate('pv_control.toast_emergency_released'),
|
||||
tr.translate('remote_control.${_cubit.state.emergencyFeedbackKey}'),
|
||||
showCheck: false,
|
||||
);
|
||||
}
|
||||
@@ -338,8 +338,7 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
return;
|
||||
}
|
||||
_controlActive = true;
|
||||
// deactivate 会清除急停态,重新进入从“未急停”开始,与通道保持同步。
|
||||
_emergencyOn = false;
|
||||
// 急停由共享 Cubit 保持,重新进入页面不自动解除。
|
||||
_channel.activate();
|
||||
}
|
||||
|
||||
@@ -679,6 +678,7 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
deviceName: widget.deviceName,
|
||||
target: ControlModeTarget.remote,
|
||||
cancelToPreview: true,
|
||||
emergencyStopControl: const EmergencyStopButton(),
|
||||
onReady: _startControl,
|
||||
child: _buildPage(context),
|
||||
);
|
||||
@@ -863,15 +863,20 @@ class _PvTopNav extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: onSettings,
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
icon: const Icon(
|
||||
Icons.settings,
|
||||
color: PvColors.textSecondary,
|
||||
size: 20,
|
||||
RemoteControlHeartbeatIndicator(
|
||||
heartbeats: sl<RemoteControlCubit>().serverHeartbeats,
|
||||
),
|
||||
ModeIndependentControl(
|
||||
child: IconButton(
|
||||
onPressed: onSettings,
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
icon: const Icon(
|
||||
Icons.settings,
|
||||
color: PvColors.textSecondary,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import '../../../remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
import '../../../device_control_mode/presentation/widgets/mode_independent_control.dart';
|
||||
|
||||
import '../theme/pv_colors.dart';
|
||||
|
||||
@@ -48,9 +51,7 @@ class PvControlBar extends StatelessWidget {
|
||||
onTap: onPauseTask,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: PvEmergencyStopButton(onTap: onEmergencyStop),
|
||||
),
|
||||
Expanded(child: PvEmergencyStopButton(onTap: onEmergencyStop)),
|
||||
Expanded(
|
||||
child: _ControlButton(
|
||||
icon: Icons.videocam,
|
||||
@@ -160,9 +161,9 @@ class _PvEmergencyStopButtonState extends State<PvEmergencyStopButton>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _controller;
|
||||
|
||||
/// 是否处于「急停中」:默认 false(正常态、不呼吸)。
|
||||
/// 点击一次进入急停(呼吸 + 「急停中」提示),再点一次解除恢复正常。
|
||||
bool _active = false;
|
||||
bool get _active =>
|
||||
context.read<RemoteControlCubit>().state.isEmergency &&
|
||||
context.read<RemoteControlCubit>().state.hasEmergencyStatus;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -179,19 +180,30 @@ class _PvEmergencyStopButtonState extends State<PvEmergencyStopButton>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _handleTap() {
|
||||
setState(() => _active = !_active);
|
||||
if (_active) {
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final state = context.watch<RemoteControlCubit>().state;
|
||||
final active = state.isEmergency && state.hasEmergencyStatus;
|
||||
if (active && !_controller.isAnimating) {
|
||||
_controller.repeat(reverse: true);
|
||||
} else {
|
||||
} else if (!active && _controller.isAnimating) {
|
||||
_controller.stop();
|
||||
_controller.value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void _handleTap() {
|
||||
if (context.read<RemoteControlCubit>().state.isEmergencyRequestPending)
|
||||
return;
|
||||
widget.onTap();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context) =>
|
||||
ModeIndependentControl(child: _buildButton(context));
|
||||
|
||||
Widget _buildButton(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, child) {
|
||||
@@ -214,7 +226,9 @@ class _PvEmergencyStopButtonState extends State<PvEmergencyStopButton>
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: PvColors.danger.withValues(alpha: 0.5 + 0.35 * t),
|
||||
color: PvColors.danger.withValues(
|
||||
alpha: 0.5 + 0.35 * t,
|
||||
),
|
||||
blurRadius: 18 + 12 * t,
|
||||
spreadRadius: 2 + 3 * t,
|
||||
),
|
||||
@@ -232,9 +246,11 @@ class _PvEmergencyStopButtonState extends State<PvEmergencyStopButton>
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
AppLocalizations.of(context).translate(
|
||||
_active
|
||||
? 'pv_control.emergency_stopping'
|
||||
: 'pv_control.emergency_stop',
|
||||
!context.read<RemoteControlCubit>().state.hasEmergencyStatus
|
||||
? 'remote_control.emergency_unknown'
|
||||
: _active
|
||||
? 'remote_control.emergency_stopping'
|
||||
: 'remote_control.emergency_inactive',
|
||||
),
|
||||
maxLines: 1,
|
||||
textAlign: TextAlign.center,
|
||||
|
||||
@@ -38,8 +38,9 @@ class PvInfoColumn extends StatelessWidget {
|
||||
label: AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.current_speed'),
|
||||
value: telemetry.speed.toStringAsFixed(1),
|
||||
unit: 'm/s',
|
||||
value: telemetry.speed?.toStringAsFixed(2) ??
|
||||
AppLocalizations.of(context).translate('pv_control.unknown'),
|
||||
unit: telemetry.speed == null ? '' : 'm/s',
|
||||
)),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: _MetricCard.icon(
|
||||
|
||||
@@ -3,12 +3,14 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:cc_ui_kit/cc_ui_kit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:maibu_satabot_v2/features/device_control_mode/presentation/widgets/mode_independent_control.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/components/control_mode_text.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/logging/remote_control_diagnostics.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/domain/entities/reverse_camera_data.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
@@ -22,6 +24,8 @@ import '../models/pv_video_source.dart';
|
||||
import '../theme/pv_colors.dart';
|
||||
import '../theme/pv_hud_theme.dart';
|
||||
import '../channel/pv_robot_command_channel.dart';
|
||||
import '../../../remote_control/presentation/widgets/remote_control_link_feedback.dart';
|
||||
import '../../../remote_control/presentation/widgets/permission_request_feedback.dart';
|
||||
import 'pv_control_bar.dart';
|
||||
import 'pv_rear_view_card.dart';
|
||||
import 'pv_local_rtsp_video.dart';
|
||||
@@ -53,7 +57,7 @@ typedef _PvSheetSpec = ({
|
||||
/// 计算缩放系数 [_sc],手机横屏(高约 360 → _sc≈0.64)时顶栏占比、字号、按钮
|
||||
/// 全部等比缩小,平板(高约 600 → _sc≈1.07)时放大,从而在两种设备上还原版式。
|
||||
///
|
||||
/// AR 障碍框、遥测数值为写死的假数据;控制指令(摇杆 / 割刀 / 底盘 / 点火 / 急停)
|
||||
/// 状态卡由实时遥测驱动;控制指令(摇杆 / 割刀 / 底盘 / 点火 / 急停)
|
||||
/// 已通过 [PvRobotCommandChannel] 接入(TCP 实现委托远程遥控 Cubit,见 pv_robot_command_channel.dart)。
|
||||
class PvManualControlView extends StatefulWidget {
|
||||
const PvManualControlView({
|
||||
@@ -615,6 +619,10 @@ class _PvManualControlViewState extends State<PvManualControlView>
|
||||
SizedBox(width: d(8)),
|
||||
// 「正在控制 / 未在控制」状态胶囊(与远程遥控顶栏同款、同逻辑)
|
||||
_buildControlStatusChip(),
|
||||
RemoteControlHeartbeatIndicator(
|
||||
heartbeats: sl<RemoteControlCubit>().serverHeartbeats,
|
||||
size: d(9),
|
||||
),
|
||||
// 中:链路信息(FittedBox 保证窄屏自动缩小不溢出)
|
||||
Expanded(
|
||||
child: Padding(
|
||||
@@ -686,10 +694,12 @@ class _PvManualControlViewState extends State<PvManualControlView>
|
||||
active: _showSidePips,
|
||||
onTap: _toggleSidePips,
|
||||
),
|
||||
_navItem(
|
||||
Icons.settings_outlined,
|
||||
tr.translate('pv_control.nav_settings'),
|
||||
onTap: widget.onSettings,
|
||||
ModeIndependentControl(
|
||||
child: _navItem(
|
||||
Icons.settings_outlined,
|
||||
tr.translate('pv_control.nav_settings'),
|
||||
onTap: widget.onSettings,
|
||||
),
|
||||
),
|
||||
SizedBox(width: d(4)),
|
||||
],
|
||||
@@ -752,17 +762,18 @@ class _PvManualControlViewState extends State<PvManualControlView>
|
||||
initialData: cubit.state,
|
||||
stream: cubit.stream,
|
||||
builder: (context, snapshot) {
|
||||
final hasPermission = snapshot.data?.hasPermission ?? false;
|
||||
final tr = AppLocalizations.of(context);
|
||||
final color = hasPermission
|
||||
? PvHudColors.success
|
||||
: PvHudColors.danger;
|
||||
final permissionState = snapshot.data ?? cubit.state;
|
||||
final hasPermission = permissionState.hasPermission;
|
||||
final busy = permissionState.isPermissionRequestBusy;
|
||||
final color = busy
|
||||
? Colors.orange
|
||||
: hasPermission ? PvHudColors.success : PvHudColors.danger;
|
||||
final chip = Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: d(10), vertical: d(3)),
|
||||
decoration: BoxDecoration(
|
||||
color: hasPermission
|
||||
? PvHudColors.successBg
|
||||
: PvHudColors.dangerBg,
|
||||
color: busy
|
||||
? Colors.orange.withValues(alpha: 0.12)
|
||||
: hasPermission ? PvHudColors.successBg : PvHudColors.dangerBg,
|
||||
borderRadius: BorderRadius.circular(d(20)),
|
||||
),
|
||||
child: Row(
|
||||
@@ -775,9 +786,7 @@ class _PvManualControlViewState extends State<PvManualControlView>
|
||||
),
|
||||
SizedBox(width: d(4)),
|
||||
Text(
|
||||
hasPermission
|
||||
? tr.translate('remote_control.controlling')
|
||||
: tr.translate('remote_control.not_controlling'),
|
||||
permissionStatusText(context, permissionState),
|
||||
maxLines: 1,
|
||||
style: s(PvHudType.caption, 11).copyWith(
|
||||
color: color,
|
||||
@@ -787,19 +796,16 @@ class _PvManualControlViewState extends State<PvManualControlView>
|
||||
],
|
||||
),
|
||||
);
|
||||
return GestureDetector(
|
||||
return PermissionRequestFeedback(
|
||||
cubit: cubit,
|
||||
child: Tooltip(
|
||||
message: permissionStatusHint(context, permissionState),
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () {
|
||||
// 已在控制:无需重复抢占。
|
||||
if (hasPermission) return;
|
||||
final targetDevice = cubit.state.targetDevice;
|
||||
if (targetDevice == null) {
|
||||
debugPrint('❌ [PV遥控] targetDevice 为空,无法请求权限');
|
||||
return;
|
||||
}
|
||||
debugPrint('🔑 [PV遥控] 👆 点击“未在控制”,请求抢占控制权');
|
||||
if (hasPermission || busy) return;
|
||||
cubit.requestControlPermissionS(
|
||||
targetDevice.deviceName,
|
||||
cubit.state.targetDevice?.deviceName ?? '',
|
||||
'app',
|
||||
source: '手动点击',
|
||||
grabControl: true,
|
||||
@@ -816,6 +822,8 @@ class _PvManualControlViewState extends State<PvManualControlView>
|
||||
),
|
||||
child: chip,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -1348,12 +1356,26 @@ class _PvManualControlViewState extends State<PvManualControlView>
|
||||
);
|
||||
}
|
||||
|
||||
/// 状态卡:图标 + 标签 + 数值的竖排列表(设计稿左栏第二张卡)。
|
||||
Widget _statusCard() {
|
||||
final tr = AppLocalizations.of(context);
|
||||
final telemetry = widget.telemetry;
|
||||
final unknown = tr.translate('pv_control.unknown');
|
||||
String speedText(double? value, String unit) =>
|
||||
value == null ? unknown : '${value.toStringAsFixed(2)} $unit';
|
||||
final motionKey = telemetry.emergencyStop == true
|
||||
? 'pv_control.emergency_stopping'
|
||||
: switch (telemetry.motion) {
|
||||
'moving' => 'pv_control.status_moving',
|
||||
'stopped' => 'pv_control.status_stopped',
|
||||
'blocked' => 'pv_control.status_blocked',
|
||||
_ => 'pv_control.unknown',
|
||||
};
|
||||
final motionDanger = telemetry.emergencyStop == true ||
|
||||
telemetry.motion == 'blocked';
|
||||
final mowerRunning = telemetry.mowerRpm != null && telemetry.mowerRpm != 0;
|
||||
final batteryText = widget.telemetry.battery == null
|
||||
? tr.translate('pv_control.unknown')
|
||||
: '${widget.telemetry.battery!.toStringAsFixed(0)}% (5.6 h)';
|
||||
? unknown
|
||||
: '${widget.telemetry.battery!.toStringAsFixed(0)}%';
|
||||
final fixQuality = widget.telemetry.fixStatus == 4;
|
||||
return _panel(
|
||||
padding: EdgeInsets.symmetric(horizontal: d(10), vertical: d(6)),
|
||||
@@ -1362,30 +1384,59 @@ class _PvManualControlViewState extends State<PvManualControlView>
|
||||
_statusRow(
|
||||
Icons.directions_car_filled_outlined,
|
||||
tr.translate('pv_control.vehicle_status'),
|
||||
tr.translate('pv_control.status_normal'),
|
||||
valueColor: PvHudColors.success,
|
||||
capsule: true,
|
||||
tr.translate(motionKey),
|
||||
valueColor: motionDanger
|
||||
? PvHudColors.danger
|
||||
: motionKey == 'pv_control.unknown'
|
||||
? PvHudColors.textSecondary
|
||||
: PvHudColors.success,
|
||||
),
|
||||
_statusRow(
|
||||
Icons.speed,
|
||||
tr.translate('pv_control.drive_speed'),
|
||||
'1.2 m/s',
|
||||
speedText(telemetry.speed, 'm/s'),
|
||||
),
|
||||
_statusRow(
|
||||
Icons.speed,
|
||||
tr.translate('pv_control.left_measured_rpm'),
|
||||
speedText(telemetry.leftMeasuredRpm, 'rpm'),
|
||||
),
|
||||
_statusRow(
|
||||
Icons.speed,
|
||||
tr.translate('pv_control.right_measured_rpm'),
|
||||
speedText(telemetry.rightMeasuredRpm, 'rpm'),
|
||||
),
|
||||
_statusRow(
|
||||
Icons.speed,
|
||||
tr.translate('pv_control.left_target_rpm'),
|
||||
speedText(telemetry.leftTargetRpm, 'rpm'),
|
||||
),
|
||||
_statusRow(
|
||||
Icons.speed,
|
||||
tr.translate('pv_control.right_target_rpm'),
|
||||
speedText(telemetry.rightTargetRpm, 'rpm'),
|
||||
),
|
||||
_statusRow(
|
||||
Icons.settings_outlined,
|
||||
tr.translate('pv_control.gear'),
|
||||
tr.translate('pv_control.gear_low'),
|
||||
unknown,
|
||||
),
|
||||
_statusRow(
|
||||
Icons.content_cut,
|
||||
tr.translate('pv_control.mower_status'),
|
||||
tr.translate('pv_control.mower_running'),
|
||||
valueColor: PvHudColors.success,
|
||||
telemetry.mowerRpm == null
|
||||
? unknown
|
||||
: tr.translate(mowerRunning
|
||||
? 'pv_control.mower_running'
|
||||
: 'pv_control.mower_stopped'),
|
||||
valueColor: mowerRunning
|
||||
? PvHudColors.success
|
||||
: PvHudColors.textSecondary,
|
||||
),
|
||||
_statusRow(
|
||||
Icons.height,
|
||||
tr.translate('pv_control.chassis_height'),
|
||||
'120 mm',
|
||||
unknown,
|
||||
),
|
||||
_statusRow(
|
||||
Icons.battery_5_bar,
|
||||
@@ -1684,7 +1735,9 @@ class _PvManualControlViewState extends State<PvManualControlView>
|
||||
child: CCJoystick(
|
||||
radius: radius,
|
||||
axisHint: AxisHint.forwardBackward,
|
||||
onDiagnostic: (event, fields) => RemoteControlDiagnostics.instance.event('joystick_' + event, fields),
|
||||
skin: _joystickSkin(),
|
||||
onPress: () => RemoteControlLinkNotice.showIfDisconnected(context),
|
||||
onValueChanged: (v) {
|
||||
final int y = v.y.toInt();
|
||||
if (y == _lastDriveY) return;
|
||||
@@ -1705,7 +1758,9 @@ class _PvManualControlViewState extends State<PvManualControlView>
|
||||
child: CCJoystick(
|
||||
radius: radius,
|
||||
axisHint: AxisHint.leftRight,
|
||||
onDiagnostic: (event, fields) => RemoteControlDiagnostics.instance.event('joystick_' + event, fields),
|
||||
skin: _joystickSkin(),
|
||||
onPress: () => RemoteControlLinkNotice.showIfDisconnected(context),
|
||||
onValueChanged: (v) {
|
||||
final int x = v.x.toInt().abs() < 1 ? 0 : v.x.toInt();
|
||||
if (x == _lastDriveX) return;
|
||||
@@ -1931,7 +1986,7 @@ class _PvManualControlViewState extends State<PvManualControlView>
|
||||
mid: 'assets/svgs/remote_scissors.svg',
|
||||
down: 'assets/svgs/remote_down.svg',
|
||||
segUp: 'pv_control.seg_mower_up',
|
||||
segMid: 'pv_control.seg_stop',
|
||||
segMid: 'pv_control.seg_mower_idle',
|
||||
segDown: 'pv_control.seg_mower_down',
|
||||
turns: 0,
|
||||
),
|
||||
@@ -2065,6 +2120,7 @@ class _PvManualControlViewState extends State<PvManualControlView>
|
||||
/// 长按起手:给一下中等强度震动做确认(手指按在按钮上就触发了,无反馈很
|
||||
/// 容易被当成没响应),并亮气泡、从中位(停)开始。
|
||||
void _onScrubStart(String sheetKey) {
|
||||
RemoteControlLinkNotice.showIfDisconnected(context);
|
||||
_sheetCloseTimer?.cancel();
|
||||
_sheetCloseTimer = null;
|
||||
HapticFeedback.mediumImpact();
|
||||
|
||||
Reference in New Issue
Block a user