diff --git a/lib/screens/device_config_screen.dart b/lib/screens/device_config_screen.dart index 0b5d39f..766acb6 100644 --- a/lib/screens/device_config_screen.dart +++ b/lib/screens/device_config_screen.dart @@ -190,6 +190,8 @@ class _DeviceConfigScreenState extends State { bool _repeatEnabled = false; bool? _gpsEnabled; // null = not supported by hardware bool _gpsLoading = false; + bool? _buzzerEnabled; + bool _buzzerLoading = false; bool? _gpsHasFix; int? _gpsSatelliteCount; int? _gpsLatE6; @@ -823,8 +825,10 @@ class _DeviceConfigScreenState extends State { final gpsLatValue = vars['gps_lat_e6']; final gpsLonValue = vars['gps_lon_e6']; final gpsLastFixAgeValue = vars['gps_last_fix_age_s']; + final buzzerValue = vars['buzzer']; setState(() { _gpsEnabled = gpsValue != null ? gpsValue == '1' : null; + _buzzerEnabled = buzzerValue != null ? buzzerValue == '1' : null; if (gpsIntervalValue != null) { _gpsIntervalController.text = gpsIntervalValue; } @@ -840,6 +844,25 @@ class _DeviceConfigScreenState extends State { } } + Future _setBuzzerMode(bool enabled) async { + setState(() => _buzzerLoading = true); + try { + await _connectionProvider.setCustomVar('buzzer', enabled ? '1' : '0'); + if (!mounted) return; + setState(() { + _buzzerEnabled = enabled; + _buzzerLoading = false; + }); + unawaited(_loadGpsMode()); + } catch (e) { + if (!mounted) return; + setState(() => _buzzerLoading = false); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Failed to set buzzer mode: $e')), + ); + } + } + Future _setGpsMode(bool enabled) async { setState(() => _gpsLoading = true); try { @@ -1758,6 +1781,32 @@ class _DeviceConfigScreenState extends State { ), ), ], + if (_buzzerEnabled != null) ...[ + const SizedBox(height: 12), + _SettingHighlightCard( + icon: _buzzerEnabled! + ? Icons.volume_up_rounded + : Icons.volume_off_rounded, + title: 'Buzzer alerts', + description: + 'Enable or mute the onboard buzzer for radio alerts.', + accentColor: _buzzerEnabled! + ? colorScheme.primary + : colorScheme.onSurfaceVariant, + trailing: _buzzerLoading + ? const SizedBox( + width: 24, + height: 24, + child: CircularProgressIndicator( + strokeWidth: 2, + ), + ) + : Switch( + value: _buzzerEnabled!, + onChanged: _setBuzzerMode, + ), + ), + ], const SizedBox(height: 16), TextField( controller: _gpsIntervalController,