From 4b4fa308d04932aad0893a7f3eecb6d273e6d99e Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Mon, 9 Dec 2024 10:32:51 -0600 Subject: [PATCH 1/6] don't hide the ExternalStorageEvent --- Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs b/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs index 49ac5e02..3d5c80c1 100644 --- a/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs +++ b/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs @@ -11,9 +11,6 @@ namespace Meadow; /// public class F7FileSystemInfo : IPlatformOS.FileSystemInfo { - /// - public new event ExternalStorageEventHandler ExternalStorageEvent = default!; - private readonly List _drives = new(); private F7ExternalStorage? _sdCard = default; @@ -62,7 +59,7 @@ private void HandleInserted() { if (F7ExternalStorage.TryMount("/dev/mmcsd0", "/sdcard", out _sdCard)) { - ExternalStorageEvent?.Invoke(_sdCard, ExternalStorageState.Inserted); + RaiseExternalStorageEvent(_sdCard, ExternalStorageState.Inserted); } } } @@ -71,7 +68,7 @@ private void HandleRemoved() { if (_sdCard != null) { - ExternalStorageEvent?.Invoke(_sdCard, ExternalStorageState.Ejected); + RaiseExternalStorageEvent(_sdCard, ExternalStorageState.Ejected); _sdCard = null; } } From 9c9640f48094b2556cc699d5ec6fec0d2b352681 Mon Sep 17 00:00:00 2001 From: halyssonJr Date: Mon, 9 Dec 2024 17:29:15 -0300 Subject: [PATCH 2/6] add eject method when the SD card is removed. --- Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs b/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs index 3d5c80c1..4812faf4 100644 --- a/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs +++ b/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs @@ -24,7 +24,7 @@ public class F7FileSystemInfo : IPlatformOS.FileSystemInfo internal F7FileSystemInfo(StorageCapabilities capabilities, bool sdSupported) { - _drives.Add(F7StorageInformation.Create(Resolver.Device)); + // _drives.Add(F7StorageInformation.Create(Resolver.Device)); _sdSupported = sdSupported; @@ -59,6 +59,7 @@ private void HandleInserted() { if (F7ExternalStorage.TryMount("/dev/mmcsd0", "/sdcard", out _sdCard)) { + _drives.Add(_sdCard); RaiseExternalStorageEvent(_sdCard, ExternalStorageState.Inserted); } } @@ -69,6 +70,8 @@ private void HandleRemoved() if (_sdCard != null) { RaiseExternalStorageEvent(_sdCard, ExternalStorageState.Ejected); + _sdCard.Eject(); + _drives.Clear(); _sdCard = null; } } From 2553a510e7d4c613db1b56cb906cf3c9aa055c1d Mon Sep 17 00:00:00 2001 From: halyssonJr Date: Wed, 11 Dec 2024 11:29:49 -0300 Subject: [PATCH 3/6] Add a new property to validate if the SD car was mounted. --- .../f7/Meadow.F7/F7FileSystemInfo.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs b/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs index 4812faf4..46134365 100644 --- a/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs +++ b/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs @@ -1,4 +1,4 @@ -using Meadow.Devices; +using Meadow.Devices; using System.Collections.Generic; using System.Threading; using static Meadow.F7PlatformOS; @@ -13,7 +13,7 @@ public class F7FileSystemInfo : IPlatformOS.FileSystemInfo { private readonly List _drives = new(); private F7ExternalStorage? _sdCard = default; - + private bool IsMount = false; private readonly bool _sdSupported; /// @@ -24,7 +24,7 @@ public class F7FileSystemInfo : IPlatformOS.FileSystemInfo internal F7FileSystemInfo(StorageCapabilities capabilities, bool sdSupported) { - // _drives.Add(F7StorageInformation.Create(Resolver.Device)); + _drives.Add(F7StorageInformation.Create(Resolver.Device)); _sdSupported = sdSupported; @@ -35,8 +35,12 @@ internal F7FileSystemInfo(StorageCapabilities capabilities, bool sdSupported) if (F7ExternalStorage.TryMount("/dev/mmcsd0", "/sdcard", out _sdCard)) { _drives.Add(_sdCard); + IsMount = true; + } + else + { + IsMount = false; } - if (Resolver.Device is F7CoreComputeBase ccm) { // thread an not interrupt because we don't want to consume int group 6 for this and speed isn't critical @@ -55,12 +59,13 @@ internal F7FileSystemInfo(StorageCapabilities capabilities, bool sdSupported) private void HandleInserted() { - if (_drives.Count == 0) + if (!IsMount) { if (F7ExternalStorage.TryMount("/dev/mmcsd0", "/sdcard", out _sdCard)) { _drives.Add(_sdCard); RaiseExternalStorageEvent(_sdCard, ExternalStorageState.Inserted); + IsMount = true; } } } @@ -70,8 +75,8 @@ private void HandleRemoved() if (_sdCard != null) { RaiseExternalStorageEvent(_sdCard, ExternalStorageState.Ejected); - _sdCard.Eject(); - _drives.Clear(); + _drives.Remove(_sdCard); + IsMount = false; _sdCard = null; } } From 38e172c2cc7df37d0c082eaf5191e2abc9f05680 Mon Sep 17 00:00:00 2001 From: halyssonJr Date: Wed, 11 Dec 2024 12:35:46 -0300 Subject: [PATCH 4/6] fix nitpick --- .../f7/Meadow.F7/F7FileSystemInfo.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs b/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs index 46134365..2c469ab1 100644 --- a/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs +++ b/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs @@ -1,4 +1,4 @@ -using Meadow.Devices; +using Meadow.Devices; using System.Collections.Generic; using System.Threading; using static Meadow.F7PlatformOS; @@ -13,7 +13,7 @@ public class F7FileSystemInfo : IPlatformOS.FileSystemInfo { private readonly List _drives = new(); private F7ExternalStorage? _sdCard = default; - private bool IsMount = false; + private bool _IsMount = false; private readonly bool _sdSupported; /// @@ -35,11 +35,11 @@ internal F7FileSystemInfo(StorageCapabilities capabilities, bool sdSupported) if (F7ExternalStorage.TryMount("/dev/mmcsd0", "/sdcard", out _sdCard)) { _drives.Add(_sdCard); - IsMount = true; + _IsMount = true; } else { - IsMount = false; + _IsMount = false; } if (Resolver.Device is F7CoreComputeBase ccm) { @@ -59,13 +59,13 @@ internal F7FileSystemInfo(StorageCapabilities capabilities, bool sdSupported) private void HandleInserted() { - if (!IsMount) + if (!_IsMount) { if (F7ExternalStorage.TryMount("/dev/mmcsd0", "/sdcard", out _sdCard)) { _drives.Add(_sdCard); RaiseExternalStorageEvent(_sdCard, ExternalStorageState.Inserted); - IsMount = true; + _IsMount = true; } } } @@ -76,7 +76,7 @@ private void HandleRemoved() { RaiseExternalStorageEvent(_sdCard, ExternalStorageState.Ejected); _drives.Remove(_sdCard); - IsMount = false; + _IsMount = false; _sdCard = null; } } From d6210f4ace4d7d57b7b3fe9591adca11adc26547 Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Wed, 11 Dec 2024 09:45:33 -0600 Subject: [PATCH 5/6] Update F7FileSystemInfo.cs --- .../implementations/f7/Meadow.F7/F7FileSystemInfo.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs b/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs index 2c469ab1..721722e3 100644 --- a/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs +++ b/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs @@ -13,7 +13,7 @@ public class F7FileSystemInfo : IPlatformOS.FileSystemInfo { private readonly List _drives = new(); private F7ExternalStorage? _sdCard = default; - private bool _IsMount = false; + private bool _isMounted = false; private readonly bool _sdSupported; /// @@ -35,11 +35,11 @@ internal F7FileSystemInfo(StorageCapabilities capabilities, bool sdSupported) if (F7ExternalStorage.TryMount("/dev/mmcsd0", "/sdcard", out _sdCard)) { _drives.Add(_sdCard); - _IsMount = true; + _isMounted = true; } else { - _IsMount = false; + _isMounted = false; } if (Resolver.Device is F7CoreComputeBase ccm) { @@ -65,7 +65,7 @@ private void HandleInserted() { _drives.Add(_sdCard); RaiseExternalStorageEvent(_sdCard, ExternalStorageState.Inserted); - _IsMount = true; + _isMounted = true; } } } @@ -76,7 +76,7 @@ private void HandleRemoved() { RaiseExternalStorageEvent(_sdCard, ExternalStorageState.Ejected); _drives.Remove(_sdCard); - _IsMount = false; + _isMounted = false; _sdCard = null; } } From ad9c61c0040e9db68dfcbadb180a6c91d1b798fa Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Wed, 11 Dec 2024 09:55:29 -0600 Subject: [PATCH 6/6] missed a rename --- Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs b/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs index 721722e3..e979465e 100644 --- a/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs +++ b/Source/implementations/f7/Meadow.F7/F7FileSystemInfo.cs @@ -59,7 +59,7 @@ internal F7FileSystemInfo(StorageCapabilities capabilities, bool sdSupported) private void HandleInserted() { - if (!_IsMount) + if (!_isMounted) { if (F7ExternalStorage.TryMount("/dev/mmcsd0", "/sdcard", out _sdCard)) {