You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2565 lines
87 KiB
2565 lines
87 KiB
import 'dart:async';
|
|
|
|
import '../utils/dialog_utils.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:meshcore_open/utils/gpx_export.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../connector/meshcore_connector.dart';
|
|
import '../connector/meshcore_protocol.dart';
|
|
import '../l10n/l10n.dart';
|
|
import '../models/radio_preset.dart';
|
|
import '../models/radio_settings.dart';
|
|
import '../services/app_debug_log_service.dart';
|
|
import '../services/app_exit_info_service.dart';
|
|
import '../services/app_settings_service.dart';
|
|
import '../services/radio_preset_service.dart';
|
|
import '../connector/observer_config_client.dart';
|
|
import '../helpers/snack_bar_builder.dart';
|
|
import '../utils/build_info.dart';
|
|
import '../utils/platform_info.dart';
|
|
import 'settings/settings_shell.dart';
|
|
import 'settings/about_view.dart';
|
|
import 'settings/app_settings_view.dart';
|
|
import 'settings/debug_logs_view.dart';
|
|
import 'settings/message_settings_view.dart';
|
|
import 'settings/observer_settings_view.dart';
|
|
import 'settings/blocked_view.dart';
|
|
import 'settings/badge_battery_view.dart';
|
|
import 'settings/badge_screen_view.dart';
|
|
import 'settings/indicators_view.dart';
|
|
import 'settings/device_ui_view.dart';
|
|
import 'settings/location_view.dart';
|
|
import '../helpers/device_name_validator.dart';
|
|
import 'device_cli_screen.dart';
|
|
import 'export_config_screen.dart';
|
|
import 'import_config_screen.dart';
|
|
import 'serial_capture_screen.dart';
|
|
import 'topology_debug_screen.dart';
|
|
import 'companion_radio_stats_screen.dart';
|
|
import '../widgets/radio_preset_picker.dart';
|
|
import '../widgets/sync_progress_overlay.dart';
|
|
|
|
/// True only in a build that passed `--dart-define=OFFBAND_ANR_TEST=true`.
|
|
///
|
|
/// Gates the force-an-ANR row in the Experimental section. The Experimental
|
|
/// section itself ships in release behind a 7-tap unlock, which is not enough
|
|
/// protection for a control whose whole job is to hang the app, so the row is
|
|
/// compiled out entirely unless a build asks for it (#906). Deliberately NOT
|
|
/// read from `dart_defines.json`, because that file feeds every build.
|
|
const bool _anrTestBuild = bool.fromEnvironment('OFFBAND_ANR_TEST');
|
|
|
|
/// Show the row only where it can actually do something. Exit records are
|
|
/// Android-only, so on a desktop test build the flag alone would leave a button
|
|
/// that does nothing.
|
|
bool get _showAnrTestRow =>
|
|
_anrTestBuild && AppExitInfoService.isSupportedPlatform;
|
|
|
|
/// Convert device coding-rate value (1-4 on some firmware, 5-8 on others)
|
|
/// to the UI enum range (always 5-8).
|
|
int _toUiCodingRate(int deviceCr) {
|
|
return deviceCr <= 4 ? deviceCr + 4 : deviceCr;
|
|
}
|
|
|
|
/// Convert UI coding-rate value (5-8) back to firmware encoding.
|
|
/// Uses the current device CR to detect which encoding the firmware expects.
|
|
int _toDeviceCodingRate(int uiCr, int? deviceCr) {
|
|
if (deviceCr != null && deviceCr <= 4) {
|
|
return uiCr - 4;
|
|
}
|
|
return uiCr;
|
|
}
|
|
|
|
class SettingsScreen extends StatefulWidget {
|
|
const SettingsScreen({super.key});
|
|
|
|
@override
|
|
State<SettingsScreen> createState() => _SettingsScreenState();
|
|
}
|
|
|
|
class _SettingsScreenState extends State<SettingsScreen> {
|
|
bool _showBatteryVoltage = false;
|
|
|
|
// #509 hidden unlock: 7 taps on the version row within a rolling window
|
|
// reveals the Experimental settings section.
|
|
static const int _experimentalUnlockTaps = 7;
|
|
static const Duration _experimentalTapWindow = Duration(seconds: 3);
|
|
int _versionTapCount = 0;
|
|
DateTime? _lastVersionTap;
|
|
// Inline feedback shown in the version row itself (no snackbar: a bottom
|
|
// snackbar overlaps the very row being tapped and blocks the next tap).
|
|
String? _versionHint;
|
|
Timer? _versionHintTimer;
|
|
|
|
@override
|
|
void dispose() {
|
|
_versionHintTimer?.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
void _handleUnlockTap() {
|
|
final l10n = context.l10n;
|
|
final settingsService = context.read<AppSettingsService>();
|
|
|
|
if (settingsService.settings.experimentalUnlocked) {
|
|
_versionTapCount = 0;
|
|
_setVersionHint(l10n.settings_experimentalAlreadyUnlocked);
|
|
return;
|
|
}
|
|
|
|
final now = DateTime.now();
|
|
if (_lastVersionTap == null ||
|
|
now.difference(_lastVersionTap!) > _experimentalTapWindow) {
|
|
_versionTapCount = 0;
|
|
}
|
|
_lastVersionTap = now;
|
|
_versionTapCount++;
|
|
|
|
final remaining = _experimentalUnlockTaps - _versionTapCount;
|
|
if (remaining <= 0) {
|
|
_versionTapCount = 0;
|
|
settingsService.setExperimentalUnlocked(true);
|
|
_setVersionHint(l10n.settings_experimentalUnlocked);
|
|
} else if (remaining <= 3) {
|
|
_setVersionHint(l10n.settings_experimentalCountdown(remaining));
|
|
}
|
|
}
|
|
|
|
void _setVersionHint(String hint) {
|
|
_versionHintTimer?.cancel();
|
|
setState(() => _versionHint = hint);
|
|
_versionHintTimer = Timer(const Duration(seconds: 2), () {
|
|
if (mounted) setState(() => _versionHint = null);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
return SettingsShell(
|
|
title: l10n.settings_title,
|
|
appBarBottom: const SyncProgressAppBarBottom(),
|
|
categories: _categories(context),
|
|
);
|
|
}
|
|
|
|
List<SettingsCategory> _categories(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
// Rebuild ONLY when the observer gate flips, NOT on every connector update.
|
|
// A blanket context.watch here rebuilt the whole settings screen on every
|
|
// sync frame, thrashing the UI thread and slowing the channel sync (#81).
|
|
final showObserver = context.select<MeshCoreConnector, bool>(
|
|
(c) =>
|
|
ObserverConfigClient.supportsConfig(offbandCaps: c.offbandCaps ?? 0),
|
|
);
|
|
// Owner-only Experimental section (#509), revealed by the 7-tap gesture on
|
|
// the Device Info Build row. Selects narrowly so the category list only
|
|
// rebuilds when the flag flips, not on every connector update (same reason
|
|
// as above).
|
|
final experimentalUnlocked = context.select<AppSettingsService, bool>(
|
|
(s) => s.settings.experimentalUnlocked,
|
|
);
|
|
return [
|
|
SettingsCategory(
|
|
icon: Icons.badge_outlined,
|
|
title: l10n.settings_nodeSettings,
|
|
builder: _identityPane,
|
|
),
|
|
SettingsCategory(
|
|
icon: Icons.settings_input_antenna,
|
|
title: l10n.settings_radioSettings,
|
|
subtitle: l10n.settings_radioSettingsSubtitle,
|
|
builder: _radioRangePane,
|
|
),
|
|
// #977: the single home for GPS, directly under Radio Settings.
|
|
SettingsCategory(
|
|
icon: Icons.location_on_outlined,
|
|
title: l10n.settings_location,
|
|
subtitle: l10n.settings_locationCategorySubtitle,
|
|
builder: (_) => const LocationView(),
|
|
),
|
|
SettingsCategory(
|
|
icon: Icons.sensors_outlined,
|
|
title: l10n.radioStats_settingsTile,
|
|
subtitle: l10n.radioStats_settingsSubtitle,
|
|
builder: _radioStatsPane,
|
|
),
|
|
SettingsCategory(
|
|
icon: Icons.shield_outlined,
|
|
title: l10n.settings_privacy,
|
|
subtitle: l10n.settings_privacySubtitle,
|
|
builder: _privacyPane,
|
|
),
|
|
SettingsCategory(
|
|
icon: Icons.contacts_outlined,
|
|
title: l10n.contacts_title,
|
|
subtitle: l10n.settings_contactSettingsSubtitle,
|
|
builder: _contactsPane,
|
|
),
|
|
SettingsCategory(
|
|
icon: Icons.block,
|
|
title: l10n.block_settingsTitle,
|
|
subtitle: l10n.block_settingsSubtitle,
|
|
builder: _blockedPane,
|
|
),
|
|
SettingsCategory(
|
|
icon: Icons.sms_outlined,
|
|
title: l10n.settings_messageSettings,
|
|
subtitle: l10n.settings_messageSettingsSubtitle,
|
|
builder: _messageSettingsPane,
|
|
),
|
|
if (showObserver)
|
|
SettingsCategory(
|
|
icon: Icons.cloud_outlined,
|
|
title: 'Observer',
|
|
subtitle: 'WiFi · MQTT brokers · display',
|
|
builder: _observerPane,
|
|
),
|
|
SettingsCategory(
|
|
icon: Icons.tune,
|
|
title: l10n.settings_appSettings,
|
|
subtitle: l10n.settings_appSettingsSubtitle,
|
|
builder: _appPane,
|
|
),
|
|
SettingsCategory(
|
|
icon: Icons.info_outline,
|
|
title: l10n.settings_deviceInfo,
|
|
builder: _devicePane,
|
|
),
|
|
SettingsCategory(
|
|
icon: Icons.bolt_outlined,
|
|
title: l10n.settings_actions,
|
|
builder: _actionsPane,
|
|
),
|
|
// App Store guideline 2.5.19 bars hidden features, so iOS has no unlock
|
|
// and never shows this section (#1051).
|
|
if (experimentalUnlocked && !PlatformInfo.isIOS)
|
|
SettingsCategory(
|
|
icon: Icons.science_outlined,
|
|
title: l10n.settings_experimental,
|
|
subtitle: l10n.settings_experimentalSubtitle,
|
|
builder: _experimentalPane,
|
|
),
|
|
SettingsCategory(
|
|
icon: Icons.build_outlined,
|
|
title: l10n.settings_debug,
|
|
builder: _diagnosticsPane,
|
|
),
|
|
SettingsCategory(
|
|
icon: Icons.info_outline,
|
|
title: l10n.settings_about,
|
|
builder: (_) => const AboutView(),
|
|
),
|
|
];
|
|
}
|
|
|
|
Widget _experimentalPane(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
final settingsService = context.watch<AppSettingsService>();
|
|
final supportsPktHash = context.select<MeshCoreConnector, bool>(
|
|
(c) => c.supportsPktHash,
|
|
);
|
|
return ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Text(l10n.settings_experimentalDescription),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
// CoreScope observer counts (#524). Disabled until the connected radio
|
|
// advertises the 0xC6 packet-hash capability.
|
|
Card(
|
|
child: SwitchListTile(
|
|
secondary: const Icon(Icons.cloud_outlined),
|
|
title: Text(l10n.settings_coreScopeObserverCount),
|
|
subtitle: Text(
|
|
supportsPktHash
|
|
? l10n.settings_coreScopeObserverCountSubtitle
|
|
: l10n.settings_coreScopeObserverCountUnsupported,
|
|
),
|
|
value: settingsService.settings.coreScopeObserverCountEnabled,
|
|
onChanged: supportsPktHash
|
|
? (value) =>
|
|
settingsService.setCoreScopeObserverCountEnabled(value)
|
|
: null,
|
|
),
|
|
),
|
|
if (_showAnrTestRow) const SizedBox(height: 16),
|
|
if (_showAnrTestRow)
|
|
// Test-only, and absent from any normal build: the constant below is
|
|
// false unless the build passes OFFBAND_ANR_TEST, so this row is
|
|
// compiled out of the shipped artifact. Hanging the main thread is the
|
|
// only way to produce a real ANR record to read back (#906/#911); no
|
|
// adb command induces one. Label is deliberately not localized, since
|
|
// it never reaches a user.
|
|
//
|
|
// The subtitle says to keep tapping for a reason. Android's only
|
|
// relevant trigger is "has not responded to an input event within 5
|
|
// seconds", and it documents no time-based trigger for a blocked main
|
|
// thread. A freeze with nothing pending can therefore recover with no
|
|
// ANR, no process death and no exit record to read back.
|
|
Card(
|
|
child: ListTile(
|
|
leading: const Icon(Icons.hourglass_disabled),
|
|
title: const Text('Force an ANR, native side (test build only)'),
|
|
subtitle: const Text(
|
|
'Freezes the UI for 20 seconds in the Android layer. KEEP '
|
|
'TAPPING the screen while it is frozen: Android raises an ANR '
|
|
'only when an input event goes unanswered for 5 seconds, so a '
|
|
'freeze with nothing pending just recovers. Then let the dialog '
|
|
'close the app, reopen, and export the debug log.',
|
|
),
|
|
onTap: () => AppExitInfoService.instance.forceMainThreadBlock(),
|
|
),
|
|
),
|
|
if (_showAnrTestRow) const SizedBox(height: 16),
|
|
if (_showAnrTestRow)
|
|
// The second trigger exists because the first one cannot answer the
|
|
// question the Epic was filed for (#931). Blocking the Android main
|
|
// thread yields a Java stack, which proved the capture works but says
|
|
// nothing about our Dart frames. The real ANRs block on the Dart UI
|
|
// isolate inside the JSON stringifier, so this one blocks there, the
|
|
// same way, and its trace should match the Play clusters' shape.
|
|
Card(
|
|
child: ListTile(
|
|
leading: const Icon(Icons.data_object),
|
|
title: const Text('Force an ANR, Dart side (test build only)'),
|
|
subtitle: const Text(
|
|
'Freezes the UI for 20 seconds by encoding JSON on the Dart '
|
|
'isolate, which is what the real ANRs do. Same procedure: KEEP '
|
|
'TAPPING while frozen, let the dialog close the app, reopen, '
|
|
'then export. Use this one to see whether our own Dart function '
|
|
'names show up in the trace.',
|
|
),
|
|
onTap: () => AppExitInfoService.instance.forceDartIsolateBlock(),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
// Disable, not just hide: turns off every experimental toggle and
|
|
// re-locks the section, so nothing keeps running invisibly (#553).
|
|
Card(
|
|
child: ListTile(
|
|
leading: const Icon(Icons.block),
|
|
title: Text(l10n.settings_experimentalDisable),
|
|
subtitle: Text(l10n.settings_experimentalDisableSubtitle),
|
|
onTap: () => settingsService.disableExperimental(),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _observerPane(BuildContext context) => const ObserverSettingsView();
|
|
|
|
Widget _blockedPane(BuildContext context) => const BlockedView();
|
|
|
|
Widget _radioRangePane(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
final connector = context.watch<MeshCoreConnector>();
|
|
return ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
l10n.settings_radioSettings,
|
|
style: const TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
_RadioSettingsForm(
|
|
key: ValueKey(
|
|
'${connector.currentFreqHz}-${connector.currentBwHz}-'
|
|
'${connector.currentSf}-${connector.currentCr}-'
|
|
'${connector.currentTxPower}-${connector.clientRepeat}',
|
|
),
|
|
connector: connector,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Card(child: _PathHashSizeTile(connector: connector)),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _radioStatsPane(BuildContext context) =>
|
|
const CompanionRadioStatsBody();
|
|
|
|
void _pushBadgePage(BuildContext context, String title, Widget body) {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => Scaffold(
|
|
appBar: AppBar(title: Text(title), centerTitle: true),
|
|
body: body,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _identityPane(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
final connector = context.watch<MeshCoreConnector>();
|
|
return ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
Card(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
ListTile(
|
|
leading: const Icon(Icons.person_outline),
|
|
title: Text(l10n.settings_nodeName),
|
|
subtitle: Text(
|
|
connector.selfName ?? l10n.settings_nodeNameNotSet,
|
|
),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () => _editNodeName(context, connector),
|
|
),
|
|
// Location and the GPS toggle moved to their own category (#977).
|
|
// Button actions (#474), directly above the public key. The
|
|
// buzzer moved to Message Settings (#978): boards with a buzzer
|
|
// and no button exist, so the two are separate entries on
|
|
// separate bits.
|
|
//
|
|
// Gated STRICTLY on the capability bit. A radio without a button
|
|
// gets no tile, no screen and no command. This is the negative
|
|
// test in #474: "A device that does not advertise the bit shows
|
|
// no screen and the client emits no command."
|
|
if (connector.supportsButtonMatrix) ...[
|
|
const Divider(height: 1),
|
|
ListTile(
|
|
leading: const Icon(Icons.radio_button_checked_outlined),
|
|
title: Text(l10n.settings_buttonActions),
|
|
subtitle: Text(l10n.settings_buttonActionsSubtitle),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(l10n.settings_buttonActions),
|
|
centerTitle: true,
|
|
),
|
|
body: const DeviceUiView(part: DeviceUiPart.buttons),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
// The badge's own screen and battery settings (#987), beside
|
|
// Button actions (owner decision 2026-10-25). Strictly on the
|
|
// 0x40 bit: no bit, no rows, no command.
|
|
if (connector.supportsScreenSettings) ...[
|
|
const Divider(height: 1),
|
|
ListTile(
|
|
leading: const Icon(Icons.monitor),
|
|
title: Text(l10n.settings_badgeScreen),
|
|
subtitle: Text(l10n.settings_badgeScreenSubtitle),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () => _pushBadgePage(
|
|
context,
|
|
l10n.settings_badgeScreen,
|
|
const BadgeScreenView(),
|
|
),
|
|
),
|
|
const Divider(height: 1),
|
|
ListTile(
|
|
leading: const Icon(Icons.battery_std),
|
|
title: Text(l10n.settings_badgeBattery),
|
|
subtitle: Text(
|
|
connector.screenSettings == null
|
|
? l10n.settings_badgeBatteryReading
|
|
: l10n.settings_badgeBatterySubtitle(
|
|
connector.screenSettings!.batteryFullMv,
|
|
),
|
|
),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () => _pushBadgePage(
|
|
context,
|
|
l10n.settings_badgeBattery,
|
|
const BadgeBatteryView(),
|
|
),
|
|
),
|
|
],
|
|
// Display mode, rotation and LED (#523). Shown when the radio
|
|
// has display control or LED control (#1132).
|
|
if (connector.supportsIndicators) ...[
|
|
const Divider(height: 1),
|
|
ListTile(
|
|
leading: const Icon(Icons.brightness_6_outlined),
|
|
title: Text(l10n.settings_indicators),
|
|
subtitle: Text(l10n.settings_indicatorsSubtitle),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () => _pushBadgePage(
|
|
context,
|
|
l10n.settings_indicators,
|
|
const IndicatorsView(),
|
|
),
|
|
),
|
|
],
|
|
if (connector.selfPublicKey != null) ...[
|
|
const Divider(height: 1),
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
|
|
child: _buildInfoRow(
|
|
l10n.settings_infoPublicKey,
|
|
pubKeyToHex(connector.selfPublicKey!),
|
|
copyValue: pubKeyToHex(connector.selfPublicKey!),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _privacyPane(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
final connector = context.watch<MeshCoreConnector>();
|
|
return ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
Card(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 4),
|
|
child: Text(
|
|
l10n.settings_privacy,
|
|
style: const TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
_PrivacySection(
|
|
key: ValueKey(
|
|
'${connector.telemetryModeBase}-${connector.telemetryModeLoc}-'
|
|
'${connector.telemetryModeEnv}-${connector.advertLocationPolicy}-'
|
|
'${connector.multiAcks}',
|
|
),
|
|
connector: connector,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _contactsPane(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
final connector = context.watch<MeshCoreConnector>();
|
|
return ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
Card(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 4),
|
|
child: Text(
|
|
l10n.contactsSettings_autoAddTitle,
|
|
style: const TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
_AutoAddSection(
|
|
key: ValueKey(
|
|
'${connector.autoAddUsers}-${connector.autoAddRepeaters}-'
|
|
'${connector.autoAddRoomServers}-${connector.autoAddSensors}-'
|
|
'${connector.autoAddOverwriteOldest}',
|
|
),
|
|
connector: connector,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _devicePane(BuildContext context) {
|
|
final connector = context.watch<MeshCoreConnector>();
|
|
return ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [_buildDeviceInfoCard(context, connector)],
|
|
);
|
|
}
|
|
|
|
Widget _appPane(BuildContext context) => const AppSettingsView();
|
|
|
|
Widget _messageSettingsPane(BuildContext context) =>
|
|
const MessageSettingsView();
|
|
|
|
Widget _actionsPane(BuildContext context) {
|
|
final connector = context.watch<MeshCoreConnector>();
|
|
// Config import/export and the GPX exports moved here from Debug (#902):
|
|
// they are user operations, not diagnostics.
|
|
return ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
_buildActionsCard(context, connector),
|
|
const SizedBox(height: 16),
|
|
_buildExportCard(connector),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _diagnosticsPane(BuildContext context) {
|
|
return ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [_buildDebugCard(context)],
|
|
);
|
|
}
|
|
|
|
Widget _buildDeviceInfoCard(
|
|
BuildContext context,
|
|
MeshCoreConnector connector,
|
|
) {
|
|
final l10n = context.l10n;
|
|
final firmwareVersion = connector.firmwareVersion;
|
|
final deviceModel = connector.deviceModel;
|
|
|
|
return Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_buildInfoRow(l10n.settings_infoName, connector.deviceDisplayName),
|
|
_buildInfoRow(l10n.settings_infoId, connector.deviceIdLabel),
|
|
_buildInfoRow(
|
|
l10n.settings_infoStatus,
|
|
connector.isConnected
|
|
? l10n.common_connected
|
|
: l10n.common_disconnected,
|
|
),
|
|
if (firmwareVersion != null)
|
|
_buildInfoRow(l10n.settings_infoFirmware, firmwareVersion),
|
|
if (deviceModel != null)
|
|
_buildInfoRow(l10n.settings_infoModel, deviceModel),
|
|
// Capability-gated controls vanish silently when a bit is clear,
|
|
// which is indistinguishable from a bug. Surface the raw inputs so
|
|
// "missing feature" can be diagnosed without enabling logging. (#304)
|
|
// caps2 is shown as "absent" rather than omitted: on a radio running
|
|
// byte-2 firmware the whole point is telling "the radio sent it" and
|
|
// "the radio is too old to send it" apart at a glance, without
|
|
// opening the debug log. All-bits-zero is a valid present value.
|
|
// (#480)
|
|
if (connector.offbandCaps != null)
|
|
_buildInfoRow(
|
|
l10n.settings_infoOffbandCaps,
|
|
'0x${connector.offbandCaps!.toRadixString(16).padLeft(2, '0')}'
|
|
' (v${connector.firmwareVerCode ?? 0})'
|
|
' · caps2 '
|
|
'${connector.offbandCaps2 == null ? 'absent' : '0x${connector.offbandCaps2!.toRadixString(16).padLeft(2, '0')}'}'
|
|
'${connector.supportsOffbandFemLna ? ' · FEM LNA' : ''}'
|
|
'${connector.supportsOffbandBlock ? ' · block' : ''}',
|
|
),
|
|
_buildBatteryInfoRow(context, connector),
|
|
if (connector.selfName != null)
|
|
_buildInfoRow(l10n.settings_nodeName, connector.selfName!),
|
|
if (connector.selfPublicKey != null) ...[
|
|
_buildInfoRow(
|
|
l10n.settings_infoPublicKey,
|
|
pubKeyToHex(connector.selfPublicKey!),
|
|
copyValue: pubKeyToHex(connector.selfPublicKey!),
|
|
),
|
|
// #295: stores are keyed by the first 10 hex of the connected
|
|
// radio's public key, so switching radios silently swaps which
|
|
// history you are looking at. Surface the key that is in effect.
|
|
...() {
|
|
final hex = pubKeyToHex(connector.selfPublicKey!);
|
|
final scope = hex.length > 10 ? hex.substring(0, 10) : hex;
|
|
if (scope.isEmpty) return <Widget>[];
|
|
return <Widget>[
|
|
_buildInfoRow(
|
|
l10n.settings_infoDataScope,
|
|
scope,
|
|
copyValue: scope,
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 4),
|
|
child: Text(
|
|
l10n.settings_infoDataScopeSubtitle,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
),
|
|
];
|
|
}(),
|
|
],
|
|
_buildInfoRow(
|
|
l10n.settings_infoContactsCount,
|
|
'${connector.contacts.length}',
|
|
),
|
|
_buildInfoRow(
|
|
l10n.settings_infoChannelCount,
|
|
'${connector.channels.length}',
|
|
),
|
|
// #397: identity of the running binary, injected at build time and
|
|
// independent of the marketing version. Its own line so "which build
|
|
// am I on" is answerable at a glance; copyable for bug reports.
|
|
// Also the hidden 7-tap Experimental unlock anchor (#509/#553),
|
|
// mirroring Android's Software-info build-number gesture.
|
|
_buildInfoRow(
|
|
l10n.settings_infoBuild,
|
|
BuildInfo.stamp,
|
|
copyValue: BuildInfo.stamp,
|
|
onTap: PlatformInfo.isIOS ? null : _handleUnlockTap,
|
|
),
|
|
if (_versionHint != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 2, bottom: 6),
|
|
child: Text(
|
|
_versionHint!,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildBatteryInfoRow(
|
|
BuildContext context,
|
|
MeshCoreConnector connector,
|
|
) {
|
|
final l10n = context.l10n;
|
|
final percent = connector.batteryPercent;
|
|
final millivolts = connector.batteryMillivolts;
|
|
|
|
// figure out display value
|
|
final String displayValue;
|
|
if (millivolts == null) {
|
|
displayValue = l10n.common_notAvailable;
|
|
} else if (_showBatteryVoltage) {
|
|
displayValue = l10n.common_voltageValue(
|
|
(millivolts / 1000.0).toStringAsFixed(2),
|
|
);
|
|
} else {
|
|
displayValue = percent != null
|
|
? l10n.common_percentValue(percent)
|
|
: l10n.common_notAvailable;
|
|
}
|
|
|
|
final IconData icon;
|
|
final Color? iconColor;
|
|
final Color? valueColor;
|
|
|
|
if (percent == null) {
|
|
icon = Icons.battery_unknown;
|
|
iconColor = Colors.grey;
|
|
valueColor = null;
|
|
} else if (percent <= 15) {
|
|
icon = Icons.battery_alert;
|
|
iconColor = Colors.orange;
|
|
valueColor = Colors.orange;
|
|
} else {
|
|
icon = Icons.battery_full;
|
|
iconColor = null;
|
|
valueColor = null;
|
|
}
|
|
|
|
return _buildInfoRow(
|
|
l10n.settings_infoBattery,
|
|
displayValue,
|
|
leading: Icon(icon, size: 18, color: iconColor),
|
|
valueColor: valueColor,
|
|
onTap: millivolts != null
|
|
? () {
|
|
setState(() {
|
|
_showBatteryVoltage = !_showBatteryVoltage;
|
|
});
|
|
}
|
|
: null,
|
|
);
|
|
}
|
|
|
|
Widget _buildActionsCard(BuildContext context, MeshCoreConnector connector) {
|
|
final l10n = context.l10n;
|
|
return Card(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
|
child: Text(
|
|
l10n.settings_actions,
|
|
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.delete_outline, color: Colors.red),
|
|
title: Text(l10n.settings_deleteAllPaths),
|
|
subtitle: Text(
|
|
l10n.settings_deleteAllPathsSubtitle,
|
|
style: TextStyle(color: Colors.red[700]),
|
|
),
|
|
onTap: () => connector.deleteAllPaths(),
|
|
),
|
|
const Divider(height: 1),
|
|
ListTile(
|
|
leading: const Icon(Icons.sync),
|
|
title: Text(l10n.settings_syncTime),
|
|
subtitle: Text(l10n.settings_syncTimeSubtitle),
|
|
onTap: () => _syncTime(context, connector),
|
|
),
|
|
const Divider(height: 1),
|
|
ListTile(
|
|
leading: const Icon(Icons.refresh),
|
|
title: Text(l10n.settings_refreshContacts),
|
|
subtitle: Text(l10n.settings_refreshContactsSubtitle),
|
|
onTap: () async {
|
|
try {
|
|
await connector.getContacts();
|
|
} catch (_) {
|
|
if (context.mounted) {
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: const Text(
|
|
'Could not refresh contacts. Please try again.',
|
|
),
|
|
);
|
|
}
|
|
}
|
|
},
|
|
),
|
|
const Divider(height: 1),
|
|
ListTile(
|
|
leading: const Icon(Icons.sync_problem_outlined),
|
|
title: Text(l10n.settings_syncQueuedMessages),
|
|
subtitle: Text(l10n.settings_syncQueuedMessagesSubtitle),
|
|
trailing: const Icon(Icons.download),
|
|
onTap: () {
|
|
context.read<MeshCoreConnector>().syncQueuedMessages(force: true);
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(l10n.settings_syncQueuedMessagesRequested),
|
|
);
|
|
},
|
|
),
|
|
_buildBlePinTile(context),
|
|
const Divider(height: 1),
|
|
ListTile(
|
|
leading: const Icon(Icons.restart_alt, color: Colors.orange),
|
|
title: Text(l10n.settings_rebootDevice),
|
|
subtitle: Text(l10n.settings_rebootDeviceSubtitle),
|
|
onTap: () => _confirmReboot(context, connector),
|
|
),
|
|
const Divider(height: 1),
|
|
ListTile(
|
|
leading: const Icon(Icons.delete_sweep_outlined, color: Colors.red),
|
|
title: Text(l10n.settings_deleteMessageHistory),
|
|
subtitle: Text(l10n.settings_deleteMessageHistorySubtitle),
|
|
onTap: () => unawaited(_confirmDeleteMessageHistory(connector)),
|
|
),
|
|
const Divider(height: 1),
|
|
ListTile(
|
|
leading: const Icon(Icons.delete_forever, color: Colors.red),
|
|
title: Text(l10n.settings_factoryReset),
|
|
subtitle: Text(l10n.settings_factoryResetSubtitle),
|
|
onTap: () => _confirmFactoryReset(context, connector),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// #1100: the radio's BLE pairing pin, shown in plain text (owner decision
|
|
/// 2026-11-06: no masking, matching other mesh clients; any connected
|
|
/// client can read it from device info anyway). Hidden until a device-info
|
|
/// frame carries the field. select() so only this tile rebuilds when the
|
|
/// pin changes (the #81 lesson).
|
|
Widget _buildBlePinTile(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
final blePin = context.select<MeshCoreConnector, int?>(
|
|
(c) => c.deviceBlePin,
|
|
);
|
|
if (blePin == null) return const SizedBox.shrink();
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Divider(height: 1),
|
|
ListTile(
|
|
leading: const Icon(Icons.password),
|
|
title: Text(l10n.settings_blePin),
|
|
subtitle: Text(
|
|
// Firmware prints the pin as %06d; mirror it, and CLI-set values
|
|
// outside the 6-digit range still display as the radio shows them.
|
|
blePin == 0
|
|
? l10n.settings_blePinDefault
|
|
: blePin.toString().padLeft(6, '0'),
|
|
),
|
|
onTap: () => _editBlePin(context, context.read<MeshCoreConnector>()),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
void _editBlePin(BuildContext context, MeshCoreConnector connector) {
|
|
final l10n = context.l10n;
|
|
final current = connector.deviceBlePin ?? 0;
|
|
// Prefill only a value cmd 37 would accept back. The firmware CLI can
|
|
// store out-of-range pins (unvalidated atoi); offering one for re-save
|
|
// would only invite the validation refusal (#1100 review).
|
|
final controller = TextEditingController(
|
|
text: current >= 100000 && current <= 999999 ? current.toString() : '',
|
|
);
|
|
String? errorText;
|
|
showDialog(
|
|
context: context,
|
|
builder: (dialogContext) => StatefulBuilder(
|
|
builder: (dialogContext, setDialogState) => AlertDialog(
|
|
title: Text(l10n.settings_blePin),
|
|
content: TextField(
|
|
controller: controller,
|
|
autofocus: true,
|
|
keyboardType: TextInputType.number,
|
|
maxLength: 6,
|
|
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
|
decoration: InputDecoration(
|
|
helperText: l10n.settings_blePinHelp,
|
|
helperMaxLines: 4,
|
|
errorText: errorText,
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.pop(dialogContext);
|
|
_sendBlePin(
|
|
context,
|
|
connector,
|
|
0,
|
|
l10n.settings_blePinResetDone,
|
|
);
|
|
},
|
|
child: Text(l10n.settings_blePinResetAction),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(dialogContext),
|
|
child: Text(l10n.common_cancel),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
final pin = int.tryParse(controller.text);
|
|
if (pin == null || pin < 100000 || pin > 999999) {
|
|
// Refuse the write at the attempt and say why, inline:
|
|
// the range is firmware's own validation (#1100).
|
|
setDialogState(() {
|
|
errorText = l10n.settings_blePinInvalid;
|
|
});
|
|
return;
|
|
}
|
|
Navigator.pop(dialogContext);
|
|
_sendBlePin(
|
|
context,
|
|
connector,
|
|
pin,
|
|
l10n.settings_blePinSaved(controller.text),
|
|
);
|
|
},
|
|
child: Text(l10n.common_save),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
).whenComplete(controller.dispose);
|
|
}
|
|
|
|
/// The success notice shows only once the frame was actually written; a
|
|
/// transport failure surfaces as a persistent error instead of silently
|
|
/// showing a pin the radio never received (#1100 review).
|
|
Future<void> _sendBlePin(
|
|
BuildContext context,
|
|
MeshCoreConnector connector,
|
|
int pin,
|
|
String successText,
|
|
) async {
|
|
final l10n = context.l10n;
|
|
try {
|
|
await connector.setDevicePin(pin);
|
|
} catch (e) {
|
|
if (!context.mounted) return;
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(l10n.settings_blePinSendFailed(e.toString())),
|
|
backgroundColor: Theme.of(context).colorScheme.error,
|
|
persist: true,
|
|
);
|
|
return;
|
|
}
|
|
if (!context.mounted) return;
|
|
showDismissibleSnackBar(context, content: Text(successText), persist: true);
|
|
}
|
|
|
|
Widget _buildDebugCard(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
// #884: the Device CLI console is offered only when the connected radio
|
|
// speaks the frame-66 CLI (stock 1.18+, or Offband advertising 0x06,
|
|
// #1157). select() so only this gate flipping rebuilds the pane, not every
|
|
// connector update (the #81 lesson).
|
|
final cliCapable = context.select<MeshCoreConnector, bool>(
|
|
(c) => c.supportsLocalCli,
|
|
);
|
|
return Card(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
|
child: Text(
|
|
l10n.settings_debug,
|
|
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
if (cliCapable) ...[
|
|
ListTile(
|
|
leading: const Icon(Icons.terminal),
|
|
title: Text(l10n.deviceCli_title),
|
|
subtitle: Text(l10n.deviceCli_entrySubtitle),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (_) => const DeviceCliScreen()),
|
|
),
|
|
),
|
|
const Divider(height: 1),
|
|
],
|
|
// The app-level rows, shared with the scanner's app-only settings
|
|
// (#693). The rows below them need the radio and stay here only.
|
|
const DebugLogTiles(),
|
|
const Divider(height: 1),
|
|
// Serial capture (#430). English-only for now; localization follow-up.
|
|
ListTile(
|
|
leading: const Icon(Icons.download_outlined),
|
|
title: const Text('Serial capture'),
|
|
subtitle: const Text(
|
|
"Capture the radio's serial log and share it as a file",
|
|
),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const SerialCaptureScreen(),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
const Divider(height: 1),
|
|
ListTile(
|
|
leading: const Icon(Icons.hub_outlined),
|
|
title: const Text('Mesh topology'),
|
|
subtitle: const Text(
|
|
'Passively-learned node/edge graph (trace inference)',
|
|
),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const TopologyDebugScreen(),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildInfoRow(
|
|
String label,
|
|
String value, {
|
|
Widget? leading,
|
|
Color? valueColor,
|
|
VoidCallback? onTap,
|
|
String? copyValue,
|
|
}) {
|
|
final theme = Theme.of(context);
|
|
|
|
final row = Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 10),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
if (leading != null) ...[leading, const SizedBox(width: 8)],
|
|
Expanded(
|
|
child: Text(
|
|
label,
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 4),
|
|
if (copyValue == null)
|
|
Text(
|
|
value,
|
|
style: theme.textTheme.bodyLarge?.copyWith(
|
|
color: valueColor,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
)
|
|
else
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
// When the row is tappable, use a plain Text so the value is
|
|
// part of the InkWell tap target (a SelectableText would eat
|
|
// the tap for selection). Copy is still available via the
|
|
// button. (#553)
|
|
child: onTap != null
|
|
? Text(
|
|
value,
|
|
style: theme.textTheme.bodyLarge?.copyWith(
|
|
color: valueColor,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
)
|
|
: SelectableText(
|
|
value,
|
|
style: theme.textTheme.bodyLarge?.copyWith(
|
|
color: valueColor,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.copy, size: 18),
|
|
tooltip: context.l10n.common_copy,
|
|
visualDensity: VisualDensity.compact,
|
|
onPressed: () async {
|
|
await Clipboard.setData(ClipboardData(text: copyValue));
|
|
if (!mounted) return;
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(context.l10n.settings_publicKeyCopied),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
if (onTap != null) {
|
|
return InkWell(
|
|
borderRadius: BorderRadius.circular(6),
|
|
onTap: onTap,
|
|
child: row,
|
|
);
|
|
}
|
|
|
|
return row;
|
|
}
|
|
|
|
void _editNodeName(BuildContext context, MeshCoreConnector connector) {
|
|
final l10n = context.l10n;
|
|
final controller = TextEditingController(text: connector.selfName ?? '');
|
|
String? errorText;
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => StatefulBuilder(
|
|
builder: (context, setLocalState) {
|
|
// #885: mirror the firmware's `set name` character rejection so a
|
|
// bad name is caught here, not bounced as a cryptic device ERROR.
|
|
void revalidate(String value) {
|
|
final bad = forbiddenCharsIn(value);
|
|
setLocalState(() {
|
|
errorText = bad.isEmpty
|
|
? null
|
|
: l10n.settings_nodeNameInvalidChars(bad.join(' '));
|
|
});
|
|
}
|
|
|
|
return AlertDialog(
|
|
title: Text(l10n.settings_nodeName),
|
|
content: TextField(
|
|
controller: controller,
|
|
onChanged: revalidate,
|
|
decoration: InputDecoration(
|
|
hintText: l10n.settings_nodeNameHint,
|
|
border: const OutlineInputBorder(),
|
|
errorText: errorText,
|
|
),
|
|
maxLength: 31,
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: Text(l10n.common_cancel),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
if (!isValidDeviceName(controller.text)) {
|
|
revalidate(controller.text); // show the error, keep open
|
|
return;
|
|
}
|
|
Navigator.pop(context);
|
|
await connector.setNodeName(controller.text);
|
|
await connector.refreshDeviceInfo();
|
|
if (!context.mounted) return;
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(l10n.settings_nodeNameUpdated),
|
|
);
|
|
},
|
|
child: Text(l10n.common_save),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _syncTime(
|
|
BuildContext context,
|
|
MeshCoreConnector connector,
|
|
) async {
|
|
final l10n = context.l10n;
|
|
try {
|
|
await connector.syncTime();
|
|
} catch (_) {
|
|
if (context.mounted) {
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: const Text('Could not sync time. Please try again.'),
|
|
);
|
|
}
|
|
return;
|
|
}
|
|
if (!context.mounted) return;
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(l10n.settings_timeSynchronized),
|
|
);
|
|
}
|
|
|
|
void _confirmReboot(BuildContext context, MeshCoreConnector connector) {
|
|
final l10n = context.l10n;
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: Text(l10n.settings_rebootDevice),
|
|
content: Text(l10n.settings_rebootDeviceConfirm),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: Text(l10n.common_cancel),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
connector.rebootDevice();
|
|
},
|
|
child: Text(
|
|
l10n.common_reboot,
|
|
style: const TextStyle(color: Colors.orange),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// #1163: start fresh for this radio. Channels and direct messages together
|
|
/// (owner, 2026-11-19); contacts, channels and settings stay.
|
|
Future<void> _confirmDeleteMessageHistory(MeshCoreConnector connector) async {
|
|
final l10n = context.l10n;
|
|
final confirmed = await confirmDelete(
|
|
context,
|
|
title: l10n.settings_deleteMessageHistory,
|
|
body: l10n.settings_deleteMessageHistoryConfirm,
|
|
);
|
|
if (!confirmed) return;
|
|
final refusal = await connector.deleteMessageHistoryForThisRadio();
|
|
if (!mounted) return;
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(switch (refusal) {
|
|
null => l10n.settings_deleteMessageHistoryDone,
|
|
HistoryWipeRefusal.notConnected =>
|
|
l10n.settings_deleteMessageHistoryNotConnected,
|
|
HistoryWipeRefusal.failed => l10n.settings_deleteMessageHistoryFailed,
|
|
}),
|
|
backgroundColor: refusal == null ? null : Colors.red,
|
|
persist: refusal != null,
|
|
);
|
|
}
|
|
|
|
void _confirmFactoryReset(BuildContext context, MeshCoreConnector connector) {
|
|
final l10n = context.l10n;
|
|
var deleteAppData = true;
|
|
showDialog(
|
|
context: context,
|
|
builder: (dialogContext) => StatefulBuilder(
|
|
builder: (dialogContext, setState) => AlertDialog(
|
|
title: Text(l10n.settings_factoryReset),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(l10n.settings_factoryResetConfirm),
|
|
const SizedBox(height: 8),
|
|
CheckboxListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
controlAffinity: ListTileControlAffinity.leading,
|
|
value: deleteAppData,
|
|
onChanged: (value) =>
|
|
setState(() => deleteAppData = value ?? deleteAppData),
|
|
title: Text(l10n.settings_factoryResetDeleteAppData),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(dialogContext),
|
|
child: Text(l10n.common_cancel),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
Navigator.pop(dialogContext);
|
|
final refusal = await connector.factoryResetDevice(
|
|
deleteAppData: deleteAppData,
|
|
);
|
|
if (refusal == null || !context.mounted) return;
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(switch (refusal) {
|
|
FactoryResetRefusal.notConnected =>
|
|
l10n.settings_factoryResetNotConnected,
|
|
}),
|
|
backgroundColor: Colors.red,
|
|
persist: true,
|
|
);
|
|
},
|
|
child: Text(
|
|
l10n.settings_factoryReset,
|
|
style: const TextStyle(color: Colors.red),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _gpxExport(
|
|
GpxExport exporter,
|
|
String name,
|
|
String description,
|
|
String filename,
|
|
String shareText,
|
|
String subject,
|
|
) async {
|
|
final l10n = context.l10n;
|
|
final result = await exporter.exportGPX(
|
|
name,
|
|
description,
|
|
filename,
|
|
shareText,
|
|
subject,
|
|
);
|
|
if (!mounted) return;
|
|
switch (result) {
|
|
case gpxExportSuccess:
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(l10n.settings_gpxExportSuccess),
|
|
);
|
|
case gpxExportNoContacts:
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(l10n.settings_gpxExportNoContacts),
|
|
);
|
|
break;
|
|
case gpxExportNotAvailable:
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(l10n.settings_gpxExportNotAvailable),
|
|
);
|
|
break;
|
|
case gpxExportFailed:
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(l10n.settings_gpxExportError),
|
|
);
|
|
break;
|
|
}
|
|
}
|
|
|
|
Widget _buildExportCard(MeshCoreConnector connector) {
|
|
final l10n = context.l10n;
|
|
return Card(
|
|
child: Column(
|
|
children: [
|
|
// Stock-compatible whole-device backup and restore (#568), distinct
|
|
// from the GPX exports below, which are map data only.
|
|
ListTile(
|
|
leading: const Icon(Icons.save_alt),
|
|
title: Text(l10n.settings_exportConfig),
|
|
subtitle: Text(l10n.settings_configBackupSubtitle),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () => Navigator.of(context).push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => const ExportConfigScreen(),
|
|
),
|
|
),
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.upload_file),
|
|
title: Text(l10n.settings_importConfig),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () => Navigator.of(context).push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => const ImportConfigScreen(),
|
|
),
|
|
),
|
|
),
|
|
const Divider(height: 1),
|
|
ListTile(
|
|
leading: const Icon(Icons.download_outlined),
|
|
title: Text(l10n.settings_gpxExportRepeaters),
|
|
subtitle: Text(l10n.settings_gpxExportRepeatersSubtitle),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () async {
|
|
final exporter = GpxExport(connector);
|
|
exporter.addRepeaters();
|
|
_gpxExport(
|
|
exporter,
|
|
l10n.map_repeater,
|
|
l10n.settings_gpxExportRepeatersRoom,
|
|
"meshcore_repeaters_",
|
|
l10n.settings_gpxExportShareText,
|
|
l10n.settings_gpxExportShareSubject,
|
|
);
|
|
},
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.download_outlined),
|
|
title: Text(l10n.settings_gpxExportContacts),
|
|
subtitle: Text(l10n.settings_gpxExportContactsSubtitle),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () async {
|
|
final exporter = GpxExport(connector);
|
|
exporter.addContacts();
|
|
_gpxExport(
|
|
exporter,
|
|
l10n.map_repeater,
|
|
l10n.settings_gpxExportChat,
|
|
"meshcore_contacts_",
|
|
l10n.settings_gpxExportShareText,
|
|
l10n.settings_gpxExportShareSubject,
|
|
);
|
|
},
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.download_outlined),
|
|
title: Text(l10n.settings_gpxExportAll),
|
|
subtitle: Text(l10n.settings_gpxExportAllSubtitle),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () async {
|
|
final exporter = GpxExport(connector);
|
|
exporter.addAll();
|
|
_gpxExport(
|
|
exporter,
|
|
l10n.map_repeater,
|
|
l10n.settings_gpxExportAllContacts,
|
|
"meshcore_all_",
|
|
l10n.settings_gpxExportShareText,
|
|
l10n.settings_gpxExportShareSubject,
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Inline privacy controls for the Privacy pane.
|
|
///
|
|
/// Advert-location, multi-ACKs, and the three telemetry-access modes all commit
|
|
/// through a single [MeshCoreConnector.setTelemetryModeBase] call, so each
|
|
/// control sends the full current state on change (coalesced) and reverts to the
|
|
/// device's values on failure. The host re-keys this widget on the connector's
|
|
/// current values, so a device-reported change rebuilds it with fresh values.
|
|
class _PrivacySection extends StatefulWidget {
|
|
final MeshCoreConnector connector;
|
|
|
|
const _PrivacySection({super.key, required this.connector});
|
|
|
|
@override
|
|
State<_PrivacySection> createState() => _PrivacySectionState();
|
|
}
|
|
|
|
class _PrivacySectionState extends State<_PrivacySection> {
|
|
late int _telemetryMode;
|
|
late int _telemetryLocMode;
|
|
late int _telemetryEnvMode;
|
|
late bool _advertLocPolicy;
|
|
late int _multiAcks;
|
|
|
|
bool _applying = false;
|
|
bool _applyAgain = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_seedFromConnector();
|
|
}
|
|
|
|
void _seedFromConnector() {
|
|
final c = widget.connector;
|
|
_telemetryMode = c.telemetryModeBase;
|
|
_telemetryLocMode = c.telemetryModeLoc;
|
|
_telemetryEnvMode = c.telemetryModeEnv;
|
|
_advertLocPolicy = c.advertLocationPolicy != 0;
|
|
_multiAcks = c.multiAcks;
|
|
}
|
|
|
|
Future<void> _apply() async {
|
|
if (_applying) {
|
|
_applyAgain = true;
|
|
return;
|
|
}
|
|
_applying = true;
|
|
try {
|
|
do {
|
|
_applyAgain = false;
|
|
await widget.connector.setTelemetryModeBase(
|
|
_telemetryMode,
|
|
_telemetryLocMode,
|
|
_telemetryEnvMode,
|
|
_advertLocPolicy ? 1 : 0,
|
|
_multiAcks,
|
|
);
|
|
} while (_applyAgain);
|
|
} catch (e) {
|
|
if (!mounted) return;
|
|
setState(_seedFromConnector);
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(context.l10n.settings_error(e.toString())),
|
|
);
|
|
} finally {
|
|
_applying = false;
|
|
}
|
|
}
|
|
|
|
Widget _telemetryDropdown({
|
|
required String label,
|
|
required int value,
|
|
required ValueChanged<int> onChanged,
|
|
}) {
|
|
final l10n = context.l10n;
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
|
child: DropdownButtonFormField<int>(
|
|
key: ValueKey('$label-$value'),
|
|
initialValue: value,
|
|
decoration: InputDecoration(
|
|
labelText: label,
|
|
border: const OutlineInputBorder(),
|
|
),
|
|
items: [
|
|
DropdownMenuItem(
|
|
value: teleModeDeny,
|
|
child: Text(l10n.settings_denyAll),
|
|
),
|
|
DropdownMenuItem(
|
|
value: teleModeAllowFlags,
|
|
child: Text(l10n.settings_allowByContact),
|
|
),
|
|
DropdownMenuItem(
|
|
value: teleModeAllowAll,
|
|
child: Text(l10n.settings_allowAll),
|
|
),
|
|
],
|
|
onChanged: (v) {
|
|
if (v == null) return;
|
|
onChanged(v);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
|
child: Text(l10n.settings_privacySettingsDescription),
|
|
),
|
|
SwitchListTile(
|
|
secondary: const Icon(Icons.share_location_outlined),
|
|
title: Text(l10n.settings_advertLocation),
|
|
subtitle: Text(l10n.settings_advertLocationSubtitle),
|
|
value: _advertLocPolicy,
|
|
onChanged: (value) {
|
|
setState(() => _advertLocPolicy = value);
|
|
_apply();
|
|
},
|
|
),
|
|
SwitchListTile(
|
|
secondary: const Icon(Icons.done_all),
|
|
title: Text(l10n.settings_multiAck),
|
|
value: _multiAcks == 1,
|
|
onChanged: (value) {
|
|
setState(() => _multiAcks = value ? 1 : 0);
|
|
_apply();
|
|
},
|
|
),
|
|
_telemetryDropdown(
|
|
label: l10n.settings_telemetryBaseMode,
|
|
value: _telemetryMode,
|
|
onChanged: (v) {
|
|
setState(() => _telemetryMode = v);
|
|
_apply();
|
|
},
|
|
),
|
|
_telemetryDropdown(
|
|
label: l10n.settings_telemetryLocationMode,
|
|
value: _telemetryLocMode,
|
|
onChanged: (v) {
|
|
setState(() => _telemetryLocMode = v);
|
|
_apply();
|
|
},
|
|
),
|
|
_telemetryDropdown(
|
|
label: l10n.settings_telemetryEnvironmentMode,
|
|
value: _telemetryEnvMode,
|
|
onChanged: (v) {
|
|
setState(() => _telemetryEnvMode = v);
|
|
_apply();
|
|
},
|
|
),
|
|
const SizedBox(height: 8),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Inline path-hash size selector for the connected device.
|
|
///
|
|
/// 1/2/3-byte hop hashes trade repeater-ID space against the maximum hop
|
|
/// count. The width a region standardises on (commonly 2-byte) belongs here
|
|
/// in Radio & range, not buried under "experimental". Reads the current width
|
|
/// from device info and writes via [MeshCoreConnector.setPathHashMode].
|
|
class _PathHashSizeTile extends StatefulWidget {
|
|
final MeshCoreConnector connector;
|
|
|
|
const _PathHashSizeTile({required this.connector});
|
|
|
|
@override
|
|
State<_PathHashSizeTile> createState() => _PathHashSizeTileState();
|
|
}
|
|
|
|
class _PathHashSizeTileState extends State<_PathHashSizeTile> {
|
|
// Hop ceilings per hash width (1/2/3 bytes), from the firmware path-hash spec.
|
|
static const List<int> _maxHopsPerWidth = [64, 32, 21];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
final connector = widget.connector;
|
|
final mode = (connector.pathHashByteWidth - 1).clamp(0, 2);
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
|
|
child: DropdownButtonFormField<int>(
|
|
key: ValueKey<int>(mode),
|
|
initialValue: mode,
|
|
isExpanded: true,
|
|
decoration: InputDecoration(
|
|
labelText: l10n.repeater_pathHashMode,
|
|
helperText: l10n.repeater_pathHashModeHelper,
|
|
helperMaxLines: 5,
|
|
prefixIcon: const Icon(Icons.alt_route),
|
|
border: const OutlineInputBorder(),
|
|
),
|
|
items: [
|
|
for (var m = 0; m < 3; m++)
|
|
DropdownMenuItem<int>(
|
|
value: m,
|
|
child: Text('${m + 1}-byte · max ${_maxHopsPerWidth[m]} hops'),
|
|
),
|
|
],
|
|
onChanged: connector.isConnected
|
|
? (value) async {
|
|
if (value == null) return;
|
|
try {
|
|
await connector.setPathHashMode(value);
|
|
await connector.refreshDeviceInfo();
|
|
if (!context.mounted) return;
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(
|
|
'${l10n.repeater_pathHashMode}: ${value + 1}-byte',
|
|
),
|
|
);
|
|
} catch (e) {
|
|
if (!context.mounted) return;
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(l10n.settings_error(e.toString())),
|
|
);
|
|
}
|
|
}
|
|
: null,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Inline auto-add controls for the Contacts pane.
|
|
///
|
|
/// Replaces the former modal dialog: toggles apply immediately (send + refetch
|
|
/// flags). The host re-keys this widget on the connector's current flags, so a
|
|
/// device-reported change rebuilds it with fresh values.
|
|
class _AutoAddSection extends StatefulWidget {
|
|
final MeshCoreConnector connector;
|
|
|
|
const _AutoAddSection({super.key, required this.connector});
|
|
|
|
@override
|
|
State<_AutoAddSection> createState() => _AutoAddSectionState();
|
|
}
|
|
|
|
class _AutoAddSectionState extends State<_AutoAddSection> {
|
|
late bool _chat;
|
|
late bool _repeater;
|
|
late bool _roomServer;
|
|
late bool _sensor;
|
|
late bool _overwriteOldest;
|
|
|
|
bool _applying = false;
|
|
bool _applyAgain = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
final c = widget.connector;
|
|
_chat = c.autoAddUsers ?? false;
|
|
_repeater = c.autoAddRepeaters ?? false;
|
|
_roomServer = c.autoAddRoomServers ?? false;
|
|
_sensor = c.autoAddSensors ?? false;
|
|
_overwriteOldest = c.autoAddOverwriteOldest ?? false;
|
|
}
|
|
|
|
Future<void> _apply() async {
|
|
// Coalesce rapid toggles: if a send is already in flight, flag a re-apply
|
|
// with the latest state for when it finishes instead of overlapping sends.
|
|
if (_applying) {
|
|
_applyAgain = true;
|
|
return;
|
|
}
|
|
_applying = true;
|
|
try {
|
|
do {
|
|
_applyAgain = false;
|
|
await widget.connector.sendFrame(
|
|
buildSetAutoAddConfigFrame(
|
|
autoAddChat: _chat,
|
|
autoAddRepeater: _repeater,
|
|
autoAddRoomServer: _roomServer,
|
|
autoAddSensor: _sensor,
|
|
overwriteOldest: _overwriteOldest,
|
|
),
|
|
);
|
|
await widget.connector.sendFrame(buildGetAutoAddFlagsFrame());
|
|
} while (_applyAgain);
|
|
} catch (e) {
|
|
if (!mounted) return;
|
|
// Revert the optimistic toggles to the device's last-known flags.
|
|
final c = widget.connector;
|
|
setState(() {
|
|
_chat = c.autoAddUsers ?? false;
|
|
_repeater = c.autoAddRepeaters ?? false;
|
|
_roomServer = c.autoAddRoomServers ?? false;
|
|
_sensor = c.autoAddSensors ?? false;
|
|
_overwriteOldest = c.autoAddOverwriteOldest ?? false;
|
|
});
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(context.l10n.settings_error(e.toString())),
|
|
);
|
|
} finally {
|
|
_applying = false;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
return Column(
|
|
children: [
|
|
SwitchListTile(
|
|
secondary: const Icon(Icons.person_add_outlined),
|
|
title: Text(l10n.contactsSettings_autoAddUsersTitle),
|
|
subtitle: Text(l10n.contactsSettings_autoAddUsersSubtitle),
|
|
value: _chat,
|
|
onChanged: (value) {
|
|
setState(() => _chat = value);
|
|
_apply();
|
|
},
|
|
),
|
|
SwitchListTile(
|
|
secondary: const Icon(Icons.router_outlined),
|
|
title: Text(l10n.contactsSettings_autoAddRepeatersTitle),
|
|
subtitle: Text(l10n.contactsSettings_autoAddRepeatersSubtitle),
|
|
value: _repeater,
|
|
onChanged: (value) {
|
|
setState(() => _repeater = value);
|
|
_apply();
|
|
},
|
|
),
|
|
SwitchListTile(
|
|
secondary: const Icon(Icons.meeting_room_outlined),
|
|
title: Text(l10n.contactsSettings_autoAddRoomServersTitle),
|
|
subtitle: Text(l10n.contactsSettings_autoAddRoomServersSubtitle),
|
|
value: _roomServer,
|
|
onChanged: (value) {
|
|
setState(() => _roomServer = value);
|
|
_apply();
|
|
},
|
|
),
|
|
SwitchListTile(
|
|
secondary: const Icon(Icons.sensors_outlined),
|
|
title: Text(l10n.contactsSettings_autoAddSensorsTitle),
|
|
subtitle: Text(l10n.contactsSettings_autoAddSensorsSubtitle),
|
|
value: _sensor,
|
|
onChanged: (value) {
|
|
setState(() => _sensor = value);
|
|
_apply();
|
|
},
|
|
),
|
|
const Divider(height: 1),
|
|
SwitchListTile(
|
|
secondary: const Icon(Icons.autorenew),
|
|
title: Text(l10n.contactsSettings_overwriteOldestTitle),
|
|
subtitle: Text(l10n.contactsSettings_overwriteOldestSubtitle),
|
|
value: _overwriteOldest,
|
|
onChanged: (value) {
|
|
setState(() => _overwriteOldest = value);
|
|
_apply();
|
|
},
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _RadioSettingsForm extends StatefulWidget {
|
|
final MeshCoreConnector connector;
|
|
|
|
const _RadioSettingsForm({super.key, required this.connector});
|
|
|
|
@override
|
|
State<_RadioSettingsForm> createState() => _RadioSettingsFormState();
|
|
}
|
|
|
|
class _RadioSettingsFormState extends State<_RadioSettingsForm> {
|
|
final _frequencyController = TextEditingController();
|
|
LoRaBandwidth _bandwidth = LoRaBandwidth.bw125;
|
|
LoRaSpreadingFactor _spreadingFactor = LoRaSpreadingFactor.sf7;
|
|
LoRaCodingRate _codingRate = LoRaCodingRate.cr4_5;
|
|
final _txPowerController = TextEditingController(text: '20');
|
|
bool _clientRepeat = false;
|
|
String? _selectedPresetId;
|
|
_RadioSettingsSnapshot? _lastNonRepeatSnapshot;
|
|
late final RadioPresetService _presetService;
|
|
|
|
AppDebugLogService get _appLog =>
|
|
Provider.of<AppDebugLogService>(context, listen: false);
|
|
|
|
List<RadioPreset> get _presets => _presetService.presets;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_presetService = Provider.of<RadioPresetService>(context, listen: false);
|
|
|
|
// Populate with current settings if available
|
|
if (widget.connector.currentFreqHz != null) {
|
|
_frequencyController.text = (widget.connector.currentFreqHz! / 1000.0)
|
|
.toStringAsFixed(3);
|
|
} else {
|
|
_frequencyController.text = '915.0';
|
|
}
|
|
|
|
if (widget.connector.currentBwHz != null) {
|
|
// Find matching bandwidth enum
|
|
final bwValue = widget.connector.currentBwHz!;
|
|
for (var bw in LoRaBandwidth.values) {
|
|
if (bw.hz == bwValue) {
|
|
_bandwidth = bw;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (widget.connector.currentSf != null) {
|
|
// Find matching spreading factor enum
|
|
final sfValue = widget.connector.currentSf!;
|
|
for (var sf in LoRaSpreadingFactor.values) {
|
|
if (sf.value == sfValue) {
|
|
_spreadingFactor = sf;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (widget.connector.currentCr != null) {
|
|
// Find matching coding rate enum
|
|
final crValue = _toUiCodingRate(widget.connector.currentCr!);
|
|
for (var cr in LoRaCodingRate.values) {
|
|
if (cr.value == crValue) {
|
|
_codingRate = cr;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (widget.connector.currentTxPower != null) {
|
|
_txPowerController.text = widget.connector.currentTxPower.toString();
|
|
}
|
|
|
|
_clientRepeat = widget.connector.clientRepeat ?? false;
|
|
_selectedPresetId = _findMatchingPresetId();
|
|
if (_clientRepeat) {
|
|
_lastNonRepeatSnapshot =
|
|
_sessionRememberedNonRepeatSnapshot() ??
|
|
_inferNonRepeatSnapshotForRepeatEnabled();
|
|
_selectedPresetId = _findMatchingPresetIdForSnapshot(
|
|
_lastNonRepeatSnapshot!,
|
|
);
|
|
} else {
|
|
_lastNonRepeatSnapshot = _nonRepeatSnapshotForCurrentSelection();
|
|
}
|
|
_presetService.addListener(_onPresetsChanged);
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (!mounted) return;
|
|
_logRadioSettingsState('Dialog initialized');
|
|
_presetService.refreshIfStale();
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_presetService.removeListener(_onPresetsChanged);
|
|
_frequencyController.dispose();
|
|
_txPowerController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
/// A refresh can change the list under an open form; re-match the selection.
|
|
void _onPresetsChanged() {
|
|
if (!mounted) return;
|
|
setState(_syncPresetSelection);
|
|
}
|
|
|
|
RadioPreset? _presetById(String? id) {
|
|
if (id == null) return null;
|
|
return _presets.where((p) => p.id == id).firstOrNull;
|
|
}
|
|
|
|
void _applyPreset(RadioPreset preset) {
|
|
setState(() {
|
|
_applyPresetState(preset);
|
|
});
|
|
_logRadioSettingsState('Applied preset ${preset.title} (${preset.id})');
|
|
}
|
|
|
|
String? _findMatchingPresetId() {
|
|
return _findMatchingPresetIdForSnapshot(_currentSnapshot());
|
|
}
|
|
|
|
/// A preset without TX power (every upstream one) matches any power.
|
|
bool _presetMatches(
|
|
RadioPreset preset,
|
|
_RadioSettingsSnapshot snapshot, {
|
|
int? frequencyHz,
|
|
}) {
|
|
// _RadioSettingsSnapshot.frequencyHz is also kHz, despite its name.
|
|
return (frequencyHz ?? preset.frequencyKHz) == snapshot.frequencyHz &&
|
|
preset.bandwidth == snapshot.bandwidth &&
|
|
preset.spreadingFactor == snapshot.spreadingFactor &&
|
|
preset.codingRate == snapshot.codingRate &&
|
|
(preset.txPowerDbm == null ||
|
|
preset.txPowerDbm == snapshot.txPowerDbm) &&
|
|
presetPathHashMatches(preset, widget.connector.pathHashByteWidth);
|
|
}
|
|
|
|
String? _findMatchingPresetIdForSnapshot(_RadioSettingsSnapshot snapshot) {
|
|
for (final preset in _visiblePresets()) {
|
|
if (_presetMatches(preset, snapshot)) {
|
|
return preset.id;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
Iterable<RadioPreset> _visiblePresets() => _presets.where((p) => !p.offGrid);
|
|
|
|
/// The snapshot a preset sets; TX power stays as it is when the preset has
|
|
/// none.
|
|
_RadioSettingsSnapshot _snapshotForPreset(
|
|
RadioPreset preset,
|
|
int currentTxPowerDbm,
|
|
) {
|
|
return _RadioSettingsSnapshot(
|
|
frequencyMHz: preset.frequencyMHz,
|
|
bandwidth: preset.bandwidth,
|
|
spreadingFactor: preset.spreadingFactor,
|
|
codingRate: preset.codingRate,
|
|
txPowerDbm: preset.txPowerDbm ?? currentTxPowerDbm,
|
|
);
|
|
}
|
|
|
|
_RadioSettingsSnapshot _currentSnapshot() {
|
|
final frequencyMHz = double.tryParse(_frequencyController.text) ?? 915.0;
|
|
final txPowerDbm = int.tryParse(_txPowerController.text) ?? 20;
|
|
return _RadioSettingsSnapshot(
|
|
frequencyMHz: frequencyMHz,
|
|
bandwidth: _bandwidth,
|
|
spreadingFactor: _spreadingFactor,
|
|
codingRate: _codingRate,
|
|
txPowerDbm: txPowerDbm,
|
|
);
|
|
}
|
|
|
|
bool _isOffGridPreset(String? id) => _presetById(id)?.offGrid ?? false;
|
|
|
|
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;
|
|
}
|
|
|
|
_RadioSettingsSnapshot _fallbackNonRepeatSnapshot(
|
|
double currentFrequencyMHz,
|
|
) {
|
|
return _RadioSettingsSnapshot(
|
|
frequencyMHz: _normalFrequencyForBand(currentFrequencyMHz),
|
|
bandwidth: _bandwidth,
|
|
spreadingFactor: _spreadingFactor,
|
|
codingRate: _codingRate,
|
|
txPowerDbm: int.tryParse(_txPowerController.text) ?? 20,
|
|
);
|
|
}
|
|
|
|
_RadioSettingsSnapshot _nonRepeatSnapshotForCurrentSelection() {
|
|
final current = _currentSnapshot();
|
|
if (!_isOffGridPreset(_selectedPresetId)) {
|
|
return current;
|
|
}
|
|
return _fallbackNonRepeatSnapshot(current.frequencyMHz);
|
|
}
|
|
|
|
_RadioSettingsSnapshot? _sessionRememberedNonRepeatSnapshot() {
|
|
final snapshot = widget.connector.rememberedNonRepeatRadioState;
|
|
if (snapshot == null) return null;
|
|
return _RadioSettingsSnapshot.fromMeshCoreSnapshot(snapshot);
|
|
}
|
|
|
|
_RadioSettingsSnapshot _inferNonRepeatSnapshotForRepeatEnabled() {
|
|
final current = _currentSnapshot();
|
|
for (final preset in _visiblePresets()) {
|
|
final offGridFreqHz =
|
|
(_offGridFrequencyForBaseFrequency(preset.frequencyMHz) * 1000)
|
|
.round();
|
|
if (_presetMatches(preset, current, frequencyHz: offGridFreqHz)) {
|
|
return _snapshotForPreset(preset, current.txPowerDbm);
|
|
}
|
|
}
|
|
return _fallbackNonRepeatSnapshot(current.frequencyMHz);
|
|
}
|
|
|
|
void _applySnapshot(_RadioSettingsSnapshot snapshot) {
|
|
_frequencyController.text = snapshot.frequencyMHz.toStringAsFixed(3);
|
|
_bandwidth = snapshot.bandwidth;
|
|
_spreadingFactor = snapshot.spreadingFactor;
|
|
_codingRate = snapshot.codingRate;
|
|
_txPowerController.text = snapshot.txPowerDbm.toString();
|
|
}
|
|
|
|
void _applyPresetState(RadioPreset preset) {
|
|
final baseSnapshot = _snapshotForPreset(
|
|
preset,
|
|
int.tryParse(_txPowerController.text) ?? 20,
|
|
);
|
|
final frequencyMHz = _clientRepeat
|
|
? _offGridFrequencyForBaseFrequency(baseSnapshot.frequencyMHz)
|
|
: baseSnapshot.frequencyMHz;
|
|
_frequencyController.text = frequencyMHz.toString();
|
|
_bandwidth = preset.bandwidth;
|
|
_spreadingFactor = preset.spreadingFactor;
|
|
_codingRate = preset.codingRate;
|
|
_txPowerController.text = baseSnapshot.txPowerDbm.toString();
|
|
_selectedPresetId = preset.id;
|
|
_lastNonRepeatSnapshot = baseSnapshot;
|
|
}
|
|
|
|
void _syncPresetSelection() {
|
|
final previousPresetId = _selectedPresetId;
|
|
final previousLastNonRepeat = _lastNonRepeatSnapshot;
|
|
if (_clientRepeat) {
|
|
final baseSnapshot =
|
|
previousLastNonRepeat ?? _inferNonRepeatSnapshotForRepeatEnabled();
|
|
if (_bandwidth != baseSnapshot.bandwidth ||
|
|
_spreadingFactor != baseSnapshot.spreadingFactor ||
|
|
_codingRate != baseSnapshot.codingRate ||
|
|
(int.tryParse(_txPowerController.text) ?? 20) !=
|
|
baseSnapshot.txPowerDbm) {
|
|
_lastNonRepeatSnapshot = _RadioSettingsSnapshot(
|
|
frequencyMHz: baseSnapshot.frequencyMHz,
|
|
bandwidth: _bandwidth,
|
|
spreadingFactor: _spreadingFactor,
|
|
codingRate: _codingRate,
|
|
txPowerDbm: int.tryParse(_txPowerController.text) ?? 20,
|
|
);
|
|
}
|
|
_selectedPresetId = _findMatchingPresetIdForSnapshot(
|
|
_lastNonRepeatSnapshot ?? baseSnapshot,
|
|
);
|
|
if (previousPresetId != _selectedPresetId ||
|
|
previousLastNonRepeat != _lastNonRepeatSnapshot) {
|
|
_logRadioSettingsState(
|
|
'Preset match updated while repeat enabled: ${_presetLabel(previousPresetId)} -> ${_presetLabel(_selectedPresetId)}',
|
|
);
|
|
}
|
|
return;
|
|
}
|
|
_lastNonRepeatSnapshot = _nonRepeatSnapshotForCurrentSelection();
|
|
_selectedPresetId = _findMatchingPresetIdForSnapshot(
|
|
_lastNonRepeatSnapshot!,
|
|
);
|
|
if (previousPresetId != _selectedPresetId ||
|
|
previousLastNonRepeat != _lastNonRepeatSnapshot) {
|
|
_logRadioSettingsState(
|
|
'Preset sync updated state from ${_presetLabel(previousPresetId)} to ${_presetLabel(_selectedPresetId)}',
|
|
);
|
|
}
|
|
}
|
|
|
|
void _handleManualSettingsChanged(String source) {
|
|
_logRadioSettingsState('Manual settings edit: $source');
|
|
setState(_syncPresetSelection);
|
|
}
|
|
|
|
void _handleClientRepeatChanged(bool enabled) {
|
|
_logRadioSettingsState(
|
|
'Off-grid repeat toggle requested: $_clientRepeat -> $enabled',
|
|
);
|
|
setState(() {
|
|
final currentSnapshot = _currentSnapshot();
|
|
if (enabled) {
|
|
if (!_clientRepeat) {
|
|
_syncPresetSelection();
|
|
}
|
|
final baseSnapshot = _lastNonRepeatSnapshot ?? currentSnapshot;
|
|
_clientRepeat = true;
|
|
_frequencyController.text = _offGridFrequencyForBaseFrequency(
|
|
baseSnapshot.frequencyMHz,
|
|
).toStringAsFixed(3);
|
|
return;
|
|
}
|
|
|
|
_clientRepeat = false;
|
|
_applySnapshot(
|
|
_lastNonRepeatSnapshot ??
|
|
_fallbackNonRepeatSnapshot(currentSnapshot.frequencyMHz),
|
|
);
|
|
_syncPresetSelection();
|
|
});
|
|
_logRadioSettingsState('Off-grid repeat toggle applied');
|
|
}
|
|
|
|
Future<void> _saveSettings() async {
|
|
final l10n = context.l10n;
|
|
final freqMHz = double.tryParse(_frequencyController.text);
|
|
final txPower = int.tryParse(_txPowerController.text);
|
|
|
|
if (freqMHz == null || freqMHz < 300 || freqMHz > 2500) {
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(l10n.settings_frequencyInvalid),
|
|
);
|
|
return;
|
|
}
|
|
|
|
final maxTxPower = widget.connector.maxTxPower ?? 22;
|
|
if (txPower == null || txPower < 0 || txPower > maxTxPower) {
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text('${l10n.settings_txPowerInvalid} (0-$maxTxPower dBm)'),
|
|
);
|
|
return;
|
|
}
|
|
|
|
final freqHz = (freqMHz * 1000).round();
|
|
final bwHz = _bandwidth.hz;
|
|
final sf = _spreadingFactor.value;
|
|
final cr = _toDeviceCodingRate(
|
|
_codingRate.value,
|
|
widget.connector.currentCr,
|
|
);
|
|
|
|
// if the client repeat isnt null then we know its supported
|
|
//otherwise we leave it out of the frame to avoid accidentally enabling
|
|
final knownRepeat = widget.connector.clientRepeat != null;
|
|
|
|
if (knownRepeat) {
|
|
const validRepeatFreqsKHz = {433000, 869000, 918000};
|
|
if (_clientRepeat && !validRepeatFreqsKHz.contains(freqHz)) {
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(l10n.settings_clientRepeatFreqWarning),
|
|
);
|
|
return;
|
|
}
|
|
}
|
|
|
|
try {
|
|
_logRadioSettingsState('Saving radio settings');
|
|
await widget.connector.sendFrame(
|
|
buildSetRadioParamsFrame(
|
|
freqHz,
|
|
bwHz,
|
|
sf,
|
|
cr,
|
|
clientRepeat: knownRepeat ? _clientRepeat : null,
|
|
),
|
|
);
|
|
await widget.connector.sendFrame(buildSetRadioTxPowerFrame(txPower));
|
|
// A preset that carries a path hash size sets it too (stock
|
|
// CMD_SET_PATH_HASH_MODE, #730). Sent whenever the preset has one,
|
|
// rather than compared against the reported width, which reads as 1
|
|
// when device info is short (#240). Setting the same mode is harmless.
|
|
final pathHashMode = _presetById(_selectedPresetId)?.pathHashMode;
|
|
if (pathHashMode != null) {
|
|
_logRadioSettingsState('Setting preset path hash mode $pathHashMode');
|
|
await widget.connector.setPathHashMode(pathHashMode);
|
|
}
|
|
await widget.connector.refreshDeviceInfo();
|
|
final rememberedSnapshot = _clientRepeat
|
|
? _lastNonRepeatSnapshot
|
|
: _currentSnapshot();
|
|
if (rememberedSnapshot != null) {
|
|
widget.connector.rememberNonRepeatRadioState(
|
|
rememberedSnapshot.toMeshCoreSnapshot(widget.connector.currentCr),
|
|
);
|
|
}
|
|
|
|
if (!mounted) return;
|
|
_logRadioSettingsState('Radio settings saved successfully');
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(l10n.settings_radioSettingsUpdated),
|
|
);
|
|
} catch (e) {
|
|
_appLog.warn('Radio settings save failed: $e', tag: 'RadioSettings');
|
|
if (!mounted) return;
|
|
showDismissibleSnackBar(
|
|
context,
|
|
content: Text(l10n.settings_error(e.toString())),
|
|
);
|
|
}
|
|
}
|
|
|
|
String _presetLabel(String? id) {
|
|
if (id == null) {
|
|
return 'custom';
|
|
}
|
|
final preset = _presetById(id);
|
|
return preset == null ? id : '${preset.title} ($id)';
|
|
}
|
|
|
|
String _formatSnapshot(_RadioSettingsSnapshot? snapshot) {
|
|
if (snapshot == null) {
|
|
return 'null';
|
|
}
|
|
return '${snapshot.frequencyMHz.toStringAsFixed(3)}MHz/'
|
|
'${snapshot.bandwidth.label}/'
|
|
'${snapshot.spreadingFactor.label}/'
|
|
'${snapshot.codingRate.label}/'
|
|
'${snapshot.txPowerDbm}dBm';
|
|
}
|
|
|
|
void _logRadioSettingsState(String message) {
|
|
if (!kDebugMode) return;
|
|
_appLog.info(
|
|
'$message | '
|
|
'freq=${_frequencyController.text}MHz '
|
|
'bw=${_bandwidth.label} '
|
|
'sf=${_spreadingFactor.label} '
|
|
'cr=${_codingRate.label} '
|
|
'tx=${_txPowerController.text}dBm '
|
|
'repeat=$_clientRepeat '
|
|
'preset=${_presetLabel(_selectedPresetId)} '
|
|
'lastNonRepeat=${_formatSnapshot(_lastNonRepeatSnapshot)}',
|
|
tag: 'RadioSettings',
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
final presetService = context.watch<RadioPresetService>();
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
RadioPresetPicker(
|
|
service: presetService,
|
|
presets: _visiblePresets().toList(),
|
|
selectedId: _selectedPresetId,
|
|
onSelected: _applyPreset,
|
|
),
|
|
const SizedBox(height: 8),
|
|
TextField(
|
|
controller: _frequencyController,
|
|
onChanged: (_) => _handleManualSettingsChanged('frequency'),
|
|
decoration: InputDecoration(
|
|
labelText: l10n.settings_frequency,
|
|
border: const OutlineInputBorder(),
|
|
helperText: l10n.settings_frequencyHelper,
|
|
),
|
|
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
|
),
|
|
const SizedBox(height: 16),
|
|
DropdownButtonFormField<LoRaBandwidth>(
|
|
initialValue: _bandwidth,
|
|
decoration: InputDecoration(
|
|
labelText: l10n.settings_bandwidth,
|
|
border: const OutlineInputBorder(),
|
|
),
|
|
items: LoRaBandwidth.values
|
|
.map((bw) => DropdownMenuItem(value: bw, child: Text(bw.label)))
|
|
.toList(),
|
|
onChanged: (value) {
|
|
if (value != null) {
|
|
setState(() {
|
|
_bandwidth = value;
|
|
_syncPresetSelection();
|
|
});
|
|
_logRadioSettingsState('Manual settings edit: bandwidth');
|
|
}
|
|
},
|
|
),
|
|
const SizedBox(height: 16),
|
|
DropdownButtonFormField<LoRaSpreadingFactor>(
|
|
initialValue: _spreadingFactor,
|
|
decoration: InputDecoration(
|
|
labelText: l10n.settings_spreadingFactor,
|
|
border: const OutlineInputBorder(),
|
|
),
|
|
items: LoRaSpreadingFactor.values
|
|
.map((sf) => DropdownMenuItem(value: sf, child: Text(sf.label)))
|
|
.toList(),
|
|
onChanged: (value) {
|
|
if (value != null) {
|
|
setState(() {
|
|
_spreadingFactor = value;
|
|
_syncPresetSelection();
|
|
});
|
|
_logRadioSettingsState('Manual settings edit: spreading factor');
|
|
}
|
|
},
|
|
),
|
|
const SizedBox(height: 16),
|
|
DropdownButtonFormField<LoRaCodingRate>(
|
|
initialValue: _codingRate,
|
|
decoration: InputDecoration(
|
|
labelText: l10n.settings_codingRate,
|
|
border: const OutlineInputBorder(),
|
|
),
|
|
items: LoRaCodingRate.values
|
|
.map((cr) => DropdownMenuItem(value: cr, child: Text(cr.label)))
|
|
.toList(),
|
|
onChanged: (value) {
|
|
if (value != null) {
|
|
setState(() {
|
|
_codingRate = value;
|
|
_syncPresetSelection();
|
|
});
|
|
_logRadioSettingsState('Manual settings edit: coding rate');
|
|
}
|
|
},
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextField(
|
|
controller: _txPowerController,
|
|
onChanged: (_) => _handleManualSettingsChanged('tx power'),
|
|
decoration: InputDecoration(
|
|
labelText: l10n.settings_txPower,
|
|
border: const OutlineInputBorder(),
|
|
helperText: widget.connector.maxTxPower != null
|
|
? '${l10n.settings_txPowerHelper} (max: ${widget.connector.maxTxPower} dBm)'
|
|
: l10n.settings_txPowerHelper,
|
|
),
|
|
keyboardType: TextInputType.number,
|
|
),
|
|
if (widget.connector.clientRepeat != null) ...[
|
|
const SizedBox(height: 16),
|
|
SwitchListTile(
|
|
title: Text(l10n.settings_clientRepeat),
|
|
subtitle: Text(l10n.settings_clientRepeatSubtitle),
|
|
value: _clientRepeat,
|
|
onChanged: _handleClientRepeatChanged,
|
|
contentPadding: EdgeInsets.zero,
|
|
),
|
|
],
|
|
// Only this radio's own FEM probe decides whether this appears, never
|
|
// model or version (#304). Deliberately not mirrored into local state:
|
|
// firmware returns post-apply hardware truth, so the switch renders
|
|
// what the radio reports rather than what we asked for.
|
|
if (widget.connector.supportsOffbandFemLna) ...[
|
|
const SizedBox(height: 16),
|
|
ListenableBuilder(
|
|
listenable: widget.connector,
|
|
builder: (context, _) => SwitchListTile(
|
|
title: Text(l10n.settings_femLna),
|
|
subtitle: Text(l10n.settings_femLnaSubtitle),
|
|
value: widget.connector.femLnaEnabled ?? true,
|
|
onChanged: (value) => widget.connector.setFemLna(value),
|
|
contentPadding: EdgeInsets.zero,
|
|
),
|
|
),
|
|
],
|
|
const SizedBox(height: 16),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: FilledButton.icon(
|
|
onPressed: _saveSettings,
|
|
icon: const Icon(Icons.save_outlined),
|
|
label: Text(l10n.common_save),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _RadioSettingsSnapshot {
|
|
final double frequencyMHz;
|
|
final LoRaBandwidth bandwidth;
|
|
final LoRaSpreadingFactor spreadingFactor;
|
|
final LoRaCodingRate codingRate;
|
|
final int txPowerDbm;
|
|
|
|
const _RadioSettingsSnapshot({
|
|
required this.frequencyMHz,
|
|
required this.bandwidth,
|
|
required this.spreadingFactor,
|
|
required this.codingRate,
|
|
required this.txPowerDbm,
|
|
});
|
|
|
|
/// Frequency in integer Hz, avoids floating-point comparison issues.
|
|
int get frequencyHz => (frequencyMHz * 1000).round();
|
|
|
|
/// Convert from the connector's raw-int snapshot to UI-enum snapshot.
|
|
static _RadioSettingsSnapshot? fromMeshCoreSnapshot(
|
|
MeshCoreRadioStateSnapshot snapshot,
|
|
) {
|
|
final bw = LoRaBandwidth.values
|
|
.where((b) => b.hz == snapshot.bwHz)
|
|
.firstOrNull;
|
|
final sf = LoRaSpreadingFactor.values
|
|
.where((s) => s.value == snapshot.sf)
|
|
.firstOrNull;
|
|
final cr = LoRaCodingRate.values
|
|
.where((c) => c.value == _toUiCodingRate(snapshot.cr))
|
|
.firstOrNull;
|
|
if (bw == null || sf == null || cr == null) return null;
|
|
return _RadioSettingsSnapshot(
|
|
frequencyMHz: snapshot.freqHz / 1000.0,
|
|
bandwidth: bw,
|
|
spreadingFactor: sf,
|
|
codingRate: cr,
|
|
txPowerDbm: snapshot.txPowerDbm,
|
|
);
|
|
}
|
|
|
|
/// Convert back to the connector's raw-int snapshot.
|
|
MeshCoreRadioStateSnapshot toMeshCoreSnapshot(int? deviceCr) {
|
|
return MeshCoreRadioStateSnapshot(
|
|
freqHz: frequencyHz,
|
|
bwHz: bandwidth.hz,
|
|
sf: spreadingFactor.value,
|
|
cr: _toDeviceCodingRate(codingRate.value, deviceCr),
|
|
txPowerDbm: txPowerDbm,
|
|
);
|
|
}
|
|
|
|
@override
|
|
bool operator ==(Object other) {
|
|
return other is _RadioSettingsSnapshot &&
|
|
frequencyHz == other.frequencyHz &&
|
|
bandwidth == other.bandwidth &&
|
|
spreadingFactor == other.spreadingFactor &&
|
|
codingRate == other.codingRate &&
|
|
txPowerDbm == other.txPowerDbm;
|
|
}
|
|
|
|
@override
|
|
int get hashCode => Object.hash(
|
|
frequencyHz,
|
|
bandwidth,
|
|
spreadingFactor,
|
|
codingRate,
|
|
txPowerDbm,
|
|
);
|
|
}
|