Plan P5: a value bubble on the pitch slider while dragging, press-and-drag on the video as a speed joystick (re-sent at 10 Hz, zero on release), and a gimbal settings sheet: mode, 30° extension, yaw follow, recenter / face down / yaw recenter, roll fine-tune, auto calibration and advanced speed/smoothness rows gated by the gimbal's capability ranges. GimbalBridge reports mode, trim, calibration and stop/overload state in the gimbal telemetry group, and getter-only settings in a new gimbalSettings slow group. The reported-plus-pending overlay moves out of CameraState into a SettingsOverlay mixin shared by camera and gimbal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
137 lines
5.2 KiB
Dart
137 lines
5.2 KiB
Dart
import 'package:flutter/material.dart';
|
||
|
||
import '../../../dji_service.dart';
|
||
import '../../../fly/product_profile.dart';
|
||
import '../../../fly/state/gimbal_state.dart';
|
||
import '../../../theme.dart';
|
||
import '../hud_kit.dart';
|
||
|
||
/// Vertical gimbal pitch slider over the profile's pitch range (GO 4
|
||
/// `fpv_gimbal_pitch_view`), with the live pitch read back from the gimbal
|
||
/// beside the thumb. While a finger is on it, a value bubble shows the pitch
|
||
/// being commanded, so the pilot sees the target before the gimbal gets there.
|
||
class GimbalSlider extends StatefulWidget {
|
||
const GimbalSlider({super.key, required this.gimbal, required this.dji, required this.range, required this.onError});
|
||
|
||
final GimbalState gimbal;
|
||
final DjiService dji;
|
||
|
||
/// The gimbal's pitch range from the profile; +30° … −90° until it reports.
|
||
final AxisRange? range;
|
||
final void Function(String label, Object error) onError;
|
||
|
||
static const AxisRange defaultPitch = AxisRange(-90, 30);
|
||
|
||
@override
|
||
State<GimbalSlider> createState() => _GimbalSliderState();
|
||
}
|
||
|
||
class _GimbalSliderState extends State<GimbalSlider> {
|
||
/// The pitch the pilot is dragging to; null while the thumb follows the gimbal.
|
||
double? _dragPitch;
|
||
|
||
AxisRange get _r => widget.range ?? GimbalSlider.defaultPitch;
|
||
|
||
double _pitchAt(double frac) => _r.max - frac.clamp(0.0, 1.0) * (_r.max - _r.min);
|
||
|
||
double _fracOf(double pitch) => ((_r.max - pitch) / (_r.max - _r.min)).clamp(0.0, 1.0);
|
||
|
||
DateTime _lastSent = DateTime.fromMillisecondsSinceEpoch(0);
|
||
|
||
/// Moves the thumb at once and commands the gimbal at most 10 times a second
|
||
/// while dragging; [force] sends the final position when the finger lifts.
|
||
Future<void> _drag(double frac, {bool force = false}) async {
|
||
final double pitch = _pitchAt(frac);
|
||
setState(() => _dragPitch = pitch);
|
||
final DateTime now = DateTime.now();
|
||
if (!force && now.difference(_lastSent) < const Duration(milliseconds: 100)) return;
|
||
_lastSent = now;
|
||
try {
|
||
await widget.dji.rotateGimbalPitch(pitch);
|
||
} catch (e) {
|
||
widget.onError('Gimbal', e);
|
||
}
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return LayoutBuilder(builder: (BuildContext context, BoxConstraints c) {
|
||
final double h = c.maxHeight;
|
||
return ListenableBuilder(
|
||
listenable: widget.gimbal,
|
||
builder: (BuildContext context, _) {
|
||
final double pitch = _dragPitch ?? widget.gimbal.pitch ?? 0;
|
||
final double frac = _fracOf(pitch);
|
||
return GestureDetector(
|
||
behavior: HitTestBehavior.opaque,
|
||
onVerticalDragUpdate: (DragUpdateDetails d) => _drag(d.localPosition.dy / h),
|
||
onVerticalDragEnd: (_) {
|
||
if (_dragPitch case final double p) _drag(_fracOf(p), force: true);
|
||
setState(() => _dragPitch = null);
|
||
},
|
||
onTapDown: (TapDownDetails d) => _drag(d.localPosition.dy / h, force: true),
|
||
onTapUp: (_) => setState(() => _dragPitch = null),
|
||
child: SizedBox(
|
||
width: 44,
|
||
child: Stack(clipBehavior: Clip.none, children: <Widget>[
|
||
Positioned(
|
||
left: 5,
|
||
top: 0,
|
||
bottom: 0,
|
||
child: Container(width: 6, decoration: BoxDecoration(color: Glass.pill, borderRadius: BorderRadius.circular(6))),
|
||
),
|
||
// The 0° mark, where the camera looks at the horizon.
|
||
Positioned(left: 2, top: _fracOf(0) * h - 0.5, child: Container(width: 12, height: 1, color: HudText.dim)),
|
||
// Centred on the pitch: the thumb row is 16 high, the bubble 22.
|
||
Positioned(
|
||
top: _dragPitch == null ? (frac * h - 8).clamp(0.0, h - 16) : (frac * h - 11).clamp(-3.0, h - 19),
|
||
left: 0,
|
||
child: Row(children: <Widget>[
|
||
if (_dragPitch == null) ..._thumb(pitch) else ..._bubble(pitch),
|
||
]),
|
||
),
|
||
]),
|
||
),
|
||
);
|
||
},
|
||
);
|
||
});
|
||
}
|
||
|
||
List<Widget> _thumb(double pitch) => <Widget>[
|
||
Container(
|
||
width: 16,
|
||
height: 16,
|
||
decoration: const BoxDecoration(
|
||
color: Glass.ink,
|
||
shape: BoxShape.circle,
|
||
boxShadow: <BoxShadow>[BoxShadow(color: Color(0x80000000), blurRadius: 3, offset: Offset(0, 1))],
|
||
),
|
||
),
|
||
const SizedBox(width: 3),
|
||
Text('${pitch.round()}°', style: HudText.monoSmall),
|
||
];
|
||
|
||
/// The dragging thumb: accent-filled, with the target pitch in a pill.
|
||
List<Widget> _bubble(double pitch) => <Widget>[
|
||
Container(
|
||
width: 16,
|
||
height: 16,
|
||
decoration: BoxDecoration(
|
||
color: Glass.accent,
|
||
shape: BoxShape.circle,
|
||
border: Border.all(color: Glass.ink, width: 2),
|
||
),
|
||
),
|
||
const SizedBox(width: 5),
|
||
Container(
|
||
key: const ValueKey<String>('gimbal-bubble'),
|
||
height: 22,
|
||
padding: const EdgeInsets.symmetric(horizontal: 7),
|
||
decoration: BoxDecoration(color: Glass.accent, borderRadius: BorderRadius.circular(6)),
|
||
alignment: Alignment.center,
|
||
child: Text('${pitch.round()}°', style: HudText.value.copyWith(fontSize: 13)),
|
||
),
|
||
];
|
||
}
|