mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-21 00:01:06 +10:00
Reapply "Fixed Preset on offgrid repeat toggle enhancemet #183"
This reverts commit 758619bbaa6ce5895c7146bbfc3b89054e759527.
This commit is contained in:
committed by
Enot (ded) Skelly
parent
f299608296
commit
82e04e8090
@@ -1088,6 +1088,7 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
|||||||
LoRaCodingRate _codingRate = LoRaCodingRate.cr4_5;
|
LoRaCodingRate _codingRate = LoRaCodingRate.cr4_5;
|
||||||
final _txPowerController = TextEditingController(text: '20');
|
final _txPowerController = TextEditingController(text: '20');
|
||||||
bool _clientRepeat = false;
|
bool _clientRepeat = false;
|
||||||
|
int? _selectedPresetIndex;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -1139,6 +1140,7 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_clientRepeat = widget.connector.clientRepeat ?? false;
|
_clientRepeat = widget.connector.clientRepeat ?? false;
|
||||||
|
_selectedPresetIndex = _findMatchingPresetIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -1158,6 +1160,55 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int? _findMatchingPresetIndex() {
|
||||||
|
final freqMHz = double.tryParse(_frequencyController.text);
|
||||||
|
final txPower = int.tryParse(_txPowerController.text);
|
||||||
|
if (freqMHz == null || txPower == null) return null;
|
||||||
|
|
||||||
|
const epsilon = 0.001;
|
||||||
|
for (var i = 0; i < RadioSettings.presets.length; i++) {
|
||||||
|
final preset = RadioSettings.presets[i].$2;
|
||||||
|
if ((preset.frequencyMHz - freqMHz).abs() < epsilon &&
|
||||||
|
preset.bandwidth == _bandwidth &&
|
||||||
|
preset.spreadingFactor == _spreadingFactor &&
|
||||||
|
preset.codingRate == _codingRate &&
|
||||||
|
preset.txPowerDbm == txPower) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
double _offGridFrequencyForBaseFrequency(double baseFrequencyMHz) {
|
||||||
|
if (baseFrequencyMHz < 500) return 433.0;
|
||||||
|
if (baseFrequencyMHz < 900) return 869.0;
|
||||||
|
return 918.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double _normalFrequencyForBand(double frequencyMHz) {
|
||||||
|
if (frequencyMHz < 500) return 433.650;
|
||||||
|
if (frequencyMHz < 900) return 869.432;
|
||||||
|
return 915.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handleClientRepeatChanged(bool enabled) {
|
||||||
|
setState(() {
|
||||||
|
_clientRepeat = enabled;
|
||||||
|
|
||||||
|
final baseFrequencyMHz = _selectedPresetIndex != null
|
||||||
|
? RadioSettings.presets[_selectedPresetIndex!].$2.frequencyMHz
|
||||||
|
: (double.tryParse(_frequencyController.text) ?? 915.0);
|
||||||
|
|
||||||
|
final nextFrequencyMHz = enabled
|
||||||
|
? _offGridFrequencyForBaseFrequency(baseFrequencyMHz)
|
||||||
|
: (_selectedPresetIndex != null
|
||||||
|
? RadioSettings.presets[_selectedPresetIndex!].$2.frequencyMHz
|
||||||
|
: _normalFrequencyForBand(baseFrequencyMHz));
|
||||||
|
|
||||||
|
_frequencyController.text = nextFrequencyMHz.toStringAsFixed(3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _saveSettings() async {
|
Future<void> _saveSettings() async {
|
||||||
final l10n = context.l10n;
|
final l10n = context.l10n;
|
||||||
final freqMHz = double.tryParse(_frequencyController.text);
|
final freqMHz = double.tryParse(_frequencyController.text);
|
||||||
@@ -1250,6 +1301,7 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
DropdownButtonFormField<int>(
|
DropdownButtonFormField<int>(
|
||||||
|
initialValue: _selectedPresetIndex,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: l10n.settings_presets,
|
labelText: l10n.settings_presets,
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
@@ -1263,6 +1315,7 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
|||||||
],
|
],
|
||||||
onChanged: (index) {
|
onChanged: (index) {
|
||||||
if (index != null) {
|
if (index != null) {
|
||||||
|
_selectedPresetIndex = index;
|
||||||
_applyPreset(RadioSettings.presets[index].$2);
|
_applyPreset(RadioSettings.presets[index].$2);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -1345,7 +1398,7 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
|||||||
title: Text(l10n.settings_clientRepeat),
|
title: Text(l10n.settings_clientRepeat),
|
||||||
subtitle: Text(l10n.settings_clientRepeatSubtitle),
|
subtitle: Text(l10n.settings_clientRepeatSubtitle),
|
||||||
value: _clientRepeat,
|
value: _clientRepeat,
|
||||||
onChanged: (value) => setState(() => _clientRepeat = value),
|
onChanged: _handleClientRepeatChanged,
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user