Merge remote-tracking branch 'origin/dev' into feat/contact-qr-import
# Conflicts: # untranslated.json
This commit is contained in:
commit
fba97b9628
133 files changed
+17269
-3629
No files matched your search
@@ -7,6 +7,7 @@ import 'dart:io';
|
||||
import '../utils/platform_info.dart';
|
||||
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
|
||||
class ContactExport {
|
||||
final String name;
|
||||
@@ -161,7 +162,6 @@ class GpxExport {
|
||||
final xml = GpxWriter().asString(gpx, pretty: true);
|
||||
|
||||
// 2. Save to file
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final timestamp = DateTime.now()
|
||||
.toUtc()
|
||||
.toIso8601String()
|
||||
@@ -169,8 +169,29 @@ class GpxExport {
|
||||
.replaceAll('.', '-')
|
||||
.split('T')
|
||||
.join('_');
|
||||
final suggestedName = '$filename$timestamp.gpx';
|
||||
|
||||
final path = '${dir.path}/$filename$timestamp.gpx';
|
||||
// share_plus cannot share files on desktop: Linux throws outright
|
||||
// ("Sharing files not supported on Linux") and Windows only supports it
|
||||
// from build 10.0.17763 up. Desktops have a real file system and a save
|
||||
// dialog, so write the file where the user asks instead of sharing it.
|
||||
if (PlatformInfo.isDesktop) {
|
||||
final location = await getSaveLocation(
|
||||
suggestedName: suggestedName,
|
||||
acceptedTypeGroups: const [
|
||||
XTypeGroup(label: 'GPX', extensions: ['gpx']),
|
||||
],
|
||||
);
|
||||
if (location == null) {
|
||||
debugPrint('Save dialog was dismissed / cancelled by user.');
|
||||
return gpxExportCancelled;
|
||||
}
|
||||
await File(location.path).writeAsString(xml);
|
||||
return gpxExportSuccess;
|
||||
}
|
||||
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final path = '${dir.path}/$suggestedName';
|
||||
|
||||
final file = File(path);
|
||||
await file.writeAsString(xml);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
import '../services/received_image_store.dart';
|
||||
import 'platform_info.dart';
|
||||
|
||||
/// Saves a transcript image: a save dialog on desktop, the share sheet
|
||||
/// elsewhere. Reconstructed images are named as such so the file never passes
|
||||
/// for a photograph. Returns false on failure; a cancelled dialog is not one.
|
||||
Future<bool> saveImagePng(
|
||||
Uint8List png,
|
||||
ReceivedImageEntry entry, {
|
||||
String? shareText,
|
||||
}) async {
|
||||
final name = entry.synthesized
|
||||
? 'meshcore-ai-reconstructed-${entry.streamId}.png'
|
||||
: 'meshcore-${entry.streamId}.png';
|
||||
final file = XFile.fromData(png, mimeType: 'image/png', name: name);
|
||||
try {
|
||||
if (PlatformInfo.isDesktop) {
|
||||
final location = await getSaveLocation(
|
||||
suggestedName: name,
|
||||
acceptedTypeGroups: const [
|
||||
XTypeGroup(label: 'PNG', extensions: ['png']),
|
||||
],
|
||||
);
|
||||
if (location != null) await file.saveTo(location.path);
|
||||
return true;
|
||||
}
|
||||
final result = await SharePlus.instance.share(
|
||||
ShareParams(
|
||||
files: [file],
|
||||
fileNameOverrides: [name],
|
||||
text: entry.synthesized ? shareText : null,
|
||||
),
|
||||
);
|
||||
return result.status != ShareResultStatus.unavailable;
|
||||
} catch (e) {
|
||||
debugPrint('image save failed: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -55,11 +55,12 @@ const int kMeshCoreMaxTransUnit = 255;
|
||||
/// (it would compute CR 4/9..4/12), and passing a 1..4 value to
|
||||
/// [loraTimeOnAir] trips its assert in debug and understates airtime in
|
||||
/// release. Always normalise at the boundary.
|
||||
/// * **Low-data-rate optimise.** `calculateLoRaAirtime()` takes `DE` as a
|
||||
/// parameter and its one caller passes the `sf >= 11` shortcut, which is
|
||||
/// wrong for SF11/BW250 and SF12/BW500 (Tsym is 8.192 ms there, below the
|
||||
/// 16 ms threshold). This file derives `DE` from `Tsym > 16 ms`, per the
|
||||
/// datasheet. See the LDRO tests in `test/lora_airtime_test.dart`.
|
||||
/// * **Low-data-rate optimise.** `DE` is derived from `Tsym > 16 ms` (the
|
||||
/// RadioLib rule), not the `sf >= 11` shortcut, which is wrong for
|
||||
/// SF11/BW250 and SF12/BW500 (Tsym is 8.192 ms there). See the LDRO tests
|
||||
/// in `test/lora_airtime_test.dart`.
|
||||
/// * **Preamble.** Defaults to the firmware's per-SF length, see
|
||||
/// [meshCorePreambleSymbols].
|
||||
/// * **Precision and guards.** `calculateLoRaAirtime()` returns whole
|
||||
/// milliseconds and will throw `Unsupported operation: Infinity or NaN
|
||||
/// toInt` on `sf == 0` / `bw == 0`, which a half-initialised device does
|
||||
@@ -88,7 +89,7 @@ Duration loraTimeOnAir({
|
||||
required int spreadingFactor,
|
||||
required int bandwidthHz,
|
||||
required int codingRate,
|
||||
int preambleSymbols = 8,
|
||||
int? preambleSymbols,
|
||||
bool crc = true,
|
||||
bool explicitHeader = true,
|
||||
}) {
|
||||
@@ -114,12 +115,18 @@ Duration loraTimeOnAir({
|
||||
0,
|
||||
);
|
||||
|
||||
final preambleMs = (preambleSymbols + 4.25) * tsymMs;
|
||||
final preamble = preambleSymbols ?? meshCorePreambleSymbols(sf);
|
||||
final preambleMs = (preamble + 4.25) * tsymMs;
|
||||
final payloadMs = (8 + payloadSymbols) * tsymMs;
|
||||
|
||||
return Duration(microseconds: ((preambleMs + payloadMs) * 1000).round());
|
||||
}
|
||||
|
||||
/// Preamble length MeshCore firmware configures for [spreadingFactor]
|
||||
/// (`RadioLibWrapper::preambleLengthForSF`): 32 symbols up to SF8, 16 above.
|
||||
int meshCorePreambleSymbols(int spreadingFactor) =>
|
||||
spreadingFactor <= 8 ? 32 : 16;
|
||||
|
||||
/// Normalises a raw firmware coding rate into the 5..8 domain used by
|
||||
/// [loraTimeOnAir] and [LoRaCodingRate.value]. Some firmwares report 1..4.
|
||||
int normalizeCodingRate(int deviceCodingRate) =>
|
||||
|
||||
Reference in new issue
Block a user