Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sdcard etc #110

Merged
merged 12 commits into from
Dec 6, 2024
23 changes: 20 additions & 3 deletions System.IO.FileSystem.UnitTests/DirectoryUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public void TestEnumerateDirectories()
Directory.CreateDirectory($@"{path}subdir2\");
Directory.CreateDirectory($@"{path}subdir3\");

// Add files to test we don't see files only directories
File.Create($@"{path}file1.txt").Close();
File.Create($@"{path}file2.txt").Close();

var directories = Directory.GetDirectories(path);

Assert.AreEqual(3, directories.Length);
Expand All @@ -119,14 +123,27 @@ public void TestEnumerateFiles()

Directory.CreateDirectory(path);

File.Create($@"{path}file1.txt").Close();
File.Create($@"{path}file2.txt").Close();
File.Create($@"{path}file3.txt").Close();
string file1 = $@"{path}file1.txt";
string file2 = $@"{path}file2.txt";
string file3 = $@"{path}file3.txt";

// Add a mix of directories and files
Directory.CreateDirectory($@"{path}TestDir1");
Directory.CreateDirectory($@"{path}TestDir2");

File.Create(file1).Close();
File.Create(file2).Close();
File.Create(file3).Close();

var files = Directory.GetFiles(path);

Assert.AreEqual(3, files.Length);

// Check correct file names returned
Assert.IsTrue((files[0] == file1), "Invalid file1 in GetFiles()");
Assert.IsTrue((files[1] == file2), "Invalid file2 in GetFiles()");
Assert.IsTrue((files[2] == file3), "Invalid file3 in GetFiles()");

// Clean up after the test
Directory.Delete(path, true);
}
Expand Down
12 changes: 9 additions & 3 deletions System.IO.FileSystem.UnitTests/FileSystemUnitTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@ public abstract class FileSystemUnitTestsBase
protected SDCard InitializeSDCard()
{
// Example initialization logic
SDCard.SDCardMmcParameters parameters = new SDCard.SDCardMmcParameters
SDCardMmcParameters parameters = new SDCardMmcParameters
{
slotIndex = 0,
dataWidth = SDCard.SDDataWidth._4_bit,
};

CardDetectParameters cdParameters = new CardDetectParameters()
{
enableCardDetectPin = true,
cardDetectPin = 21
cardDetectPin = 21,
autoMount = true
};

return new SDCard(parameters);
return new SDCard(parameters, cdParameters);
}

/// <summary>
Expand Down
6 changes: 2 additions & 4 deletions System.IO.FileSystem/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,8 @@ internal static int GetDirectoryNameOffset(string path)
return -1;
}

while (end > rootLength && !PathInternal.IsDirectorySeparator(path[--end]))
{
}

while (end > rootLength && !PathInternal.IsDirectorySeparator(path[--end]));

// Trim off any remaining separators (to deal with C:\foo\\bar)
while (end > rootLength && PathInternal.IsDirectorySeparator(path[end - 1]))
{
Expand Down
2 changes: 1 addition & 1 deletion System.IO.FileSystem/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

////////////////////////////////////////////////////////////////
// update this whenever the native assembly signature changes //
[assembly: AssemblyNativeVersion("1.1.0.3")]
[assembly: AssemblyNativeVersion("1.1.0.4")]
////////////////////////////////////////////////////////////////

[assembly: InternalsVisibleTo("NFUnitTest, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")]
4 changes: 4 additions & 0 deletions System.IO.FileSystem/System.IO.FileSystem.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
<Compile Include="FileMode.cs" />
<Compile Include="FileShare.cs" />
<Compile Include="FileStream.cs" />
<Compile Include="nanoFramework\CardDetectChangedEventArgs.cs" />
<Compile Include="nanoFramework\CardDetectParameters.cs" />
<Compile Include="nanoFramework\SDCardMmcParameters.cs" />
<Compile Include="nanoFramework\SDCardSpiParameters.cs" />
<Compile Include="NativeFindFile.cs" />
<Compile Include="FileSystemInfo.cs" />
<Compile Include="FileSystemManager.cs" />
Expand Down
50 changes: 50 additions & 0 deletions System.IO.FileSystem/nanoFramework/CardDetectChangedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

using System;

namespace nanoFramework.System.IO
{
/// <summary>
/// State of card detect
/// </summary>
public enum CardDetectState
{
/// <summary>
/// Card Inserted
/// </summary>
Inserted,

/// <summary>
/// Card removed
/// </summary>
Removed
};

/// <summary>
/// Arguments for Card detect event
/// </summary>
public class CardDetectChangedEventArgs : EventArgs
{
readonly private CardDetectState _cardState;
readonly private uint _slotIndex;

internal CardDetectChangedEventArgs(CardDetectState state, uint SlotIndex)
{
_cardState = state;
_slotIndex = SlotIndex;
}

/// <summary>
/// State of Card Detect.
/// </summary>
public CardDetectState CardState => _cardState;

/// <summary>
/// SD card slot index
/// </summary>
public uint SlotIndex => _slotIndex;
}
}
41 changes: 41 additions & 0 deletions System.IO.FileSystem/nanoFramework/CardDetectParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

namespace nanoFramework.System.IO.FileSystem
{
/// <summary>
/// Parameter used for Card detection when creating a SDcard instance.
/// </summary>
public class CardDetectParameters
{
/// <summary>
/// Set true when an Card Detect Pin is used.
/// The cardDetectPin parameter must have a valid GPIO pin.
/// </summary>
/// <remarks>
/// Not all SD Card modules have a card detect pin or the pin connected to a GPIO pin.
/// </remarks>
public bool enableCardDetectPin;

/// <summary>
/// The state of the pin when the card is detected.
/// Defaults to false(low) if not specified.
/// If using card detect logic then this depends on connected hardware.
/// </summary>
public bool cardDetectedState;

/// <summary>
/// The optional card detect GPIO pin which must be set to a valid pin if EnableCardDetectPin is true.
/// If defined a StorageEventManager event will be raised when a card is inserted or removed.
/// </summary>
public uint cardDetectPin;

/// <summary>
/// When enabled will try to automatically mount the SD card when the card is inserted.
/// If the card is removed unexpectedly it will try to unmount card to release resources.
/// </summary>
public bool autoMount;
}
}
Loading