mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-30 07:18:45 +10:00
Refactor radio settings to use nullable types and update command generation logic for improved safety
This commit is contained in:
@@ -46,9 +46,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
|||||||
// Radio settings
|
// Radio settings
|
||||||
final TextEditingController _freqController = TextEditingController();
|
final TextEditingController _freqController = TextEditingController();
|
||||||
final TextEditingController _txPowerController = TextEditingController();
|
final TextEditingController _txPowerController = TextEditingController();
|
||||||
int _bandwidth = 125000;
|
int? _bandwidth;
|
||||||
int _spreadingFactor = 9;
|
int? _spreadingFactor;
|
||||||
int _codingRate = 7;
|
int? _codingRate;
|
||||||
|
|
||||||
// Location settings
|
// Location settings
|
||||||
final TextEditingController _latController = TextEditingController();
|
final TextEditingController _latController = TextEditingController();
|
||||||
@@ -56,7 +56,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
|||||||
|
|
||||||
// Feature toggles
|
// Feature toggles
|
||||||
bool _repeatEnabled = true;
|
bool _repeatEnabled = true;
|
||||||
bool _allowReadOnly = false;
|
bool _allowReadOnly = true;
|
||||||
bool _privacyMode = false;
|
bool _privacyMode = false;
|
||||||
|
|
||||||
// Advertisement settings
|
// Advertisement settings
|
||||||
@@ -177,8 +177,8 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
|||||||
if (bw != null) {
|
if (bw != null) {
|
||||||
_bandwidth = (bw * 1000).toInt();
|
_bandwidth = (bw * 1000).toInt();
|
||||||
appLog.info('Bandwidth Hz: $_bandwidth', tag: 'RadioSettings');
|
appLog.info('Bandwidth Hz: $_bandwidth', tag: 'RadioSettings');
|
||||||
if (!_bandwidthOptions.contains(_bandwidth)) {
|
if (_bandwidth != null && !_bandwidthOptions.contains(_bandwidth)) {
|
||||||
_bandwidthOptions.add(_bandwidth);
|
_bandwidthOptions.add(_bandwidth!);
|
||||||
_bandwidthOptions.sort();
|
_bandwidthOptions.sort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -544,9 +544,16 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Radio parameters
|
// Radio parameters
|
||||||
final freqMHz = double.tryParse(_freqController.text) ?? 915.0;
|
if (_freqController.text.isNotEmpty &&
|
||||||
final bwKHz = _bandwidth / 1000;
|
_bandwidth != null &&
|
||||||
commands.add('set radio ${freqMHz.toStringAsFixed(1)} $bwKHz $_spreadingFactor $_codingRate');
|
_spreadingFactor != null &&
|
||||||
|
_codingRate != null) {
|
||||||
|
final freqMHz = double.tryParse(_freqController.text);
|
||||||
|
if (freqMHz != null) {
|
||||||
|
final bwKHz = _bandwidth! / 1000;
|
||||||
|
commands.add('set radio ${freqMHz.toStringAsFixed(1)} $bwKHz $_spreadingFactor $_codingRate');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Location
|
// Location
|
||||||
if (_latController.text.isNotEmpty) {
|
if (_latController.text.isNotEmpty) {
|
||||||
@@ -888,7 +895,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
DropdownButtonFormField<int>(
|
DropdownButtonFormField<int>(
|
||||||
initialValue: _bandwidth,
|
value: _bandwidth,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: l10n.repeater_bandwidth,
|
labelText: l10n.repeater_bandwidth,
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
@@ -910,7 +917,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
DropdownButtonFormField<int>(
|
DropdownButtonFormField<int>(
|
||||||
initialValue: _spreadingFactor,
|
value: _spreadingFactor,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: l10n.repeater_spreadingFactor,
|
labelText: l10n.repeater_spreadingFactor,
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
@@ -932,7 +939,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
DropdownButtonFormField<int>(
|
DropdownButtonFormField<int>(
|
||||||
initialValue: _codingRate,
|
value: _codingRate,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: l10n.repeater_codingRate,
|
labelText: l10n.repeater_codingRate,
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
|
|||||||
Reference in New Issue
Block a user