Skip to content

Commit 8b6b285

Browse files
Update sdcard etc (#110)
Co-authored-by: José Simões <jose.simoes@eclo.solutions>
1 parent cf73b3a commit 8b6b285

11 files changed

Lines changed: 387 additions & 109 deletions

File tree

System.IO.FileSystem.UnitTests/DirectoryUnitTests.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public void TestEnumerateDirectories()
9898
Directory.CreateDirectory($@"{path}subdir2\");
9999
Directory.CreateDirectory($@"{path}subdir3\");
100100

101+
// Add files to test we don't see files only directories
102+
File.Create($@"{path}file1.txt").Close();
103+
File.Create($@"{path}file2.txt").Close();
104+
101105
var directories = Directory.GetDirectories(path);
102106

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

120124
Directory.CreateDirectory(path);
121125

122-
File.Create($@"{path}file1.txt").Close();
123-
File.Create($@"{path}file2.txt").Close();
124-
File.Create($@"{path}file3.txt").Close();
126+
string file1 = $@"{path}file1.txt";
127+
string file2 = $@"{path}file2.txt";
128+
string file3 = $@"{path}file3.txt";
129+
130+
// Add a mix of directories and files
131+
Directory.CreateDirectory($@"{path}TestDir1");
132+
Directory.CreateDirectory($@"{path}TestDir2");
133+
134+
File.Create(file1).Close();
135+
File.Create(file2).Close();
136+
File.Create(file3).Close();
125137

126138
var files = Directory.GetFiles(path);
127139

128140
Assert.AreEqual(3, files.Length);
129141

142+
// Check correct file names returned
143+
Assert.IsTrue((files[0] == file1), "Invalid file1 in GetFiles()");
144+
Assert.IsTrue((files[1] == file2), "Invalid file2 in GetFiles()");
145+
Assert.IsTrue((files[2] == file3), "Invalid file3 in GetFiles()");
146+
130147
// Clean up after the test
131148
Directory.Delete(path, true);
132149
}

System.IO.FileSystem.UnitTests/FileSystemUnitTestsBase.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,20 @@ public abstract class FileSystemUnitTestsBase
3838
protected SDCard InitializeSDCard()
3939
{
4040
// Example initialization logic
41-
SDCard.SDCardMmcParameters parameters = new SDCard.SDCardMmcParameters
41+
SDCardMmcParameters parameters = new SDCardMmcParameters
4242
{
43+
slotIndex = 0,
4344
dataWidth = SDCard.SDDataWidth._4_bit,
45+
};
46+
47+
CardDetectParameters cdParameters = new CardDetectParameters()
48+
{
4449
enableCardDetectPin = true,
45-
cardDetectPin = 21
50+
cardDetectPin = 21,
51+
autoMount = true
4652
};
4753

48-
return new SDCard(parameters);
54+
return new SDCard(parameters, cdParameters);
4955
}
5056

5157
/// <summary>

System.IO.FileSystem/Path.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,8 @@ internal static int GetDirectoryNameOffset(string path)
164164
return -1;
165165
}
166166

167-
while (end > rootLength && !PathInternal.IsDirectorySeparator(path[--end]))
168-
{
169-
}
170-
167+
while (end > rootLength && !PathInternal.IsDirectorySeparator(path[--end]));
168+
171169
// Trim off any remaining separators (to deal with C:\foo\\bar)
172170
while (end > rootLength && PathInternal.IsDirectorySeparator(path[end - 1]))
173171
{

System.IO.FileSystem/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
////////////////////////////////////////////////////////////////
1919
// update this whenever the native assembly signature changes //
20-
[assembly: AssemblyNativeVersion("1.1.0.3")]
20+
[assembly: AssemblyNativeVersion("1.1.0.4")]
2121
////////////////////////////////////////////////////////////////
2222

2323
[assembly: InternalsVisibleTo("NFUnitTest, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")]

System.IO.FileSystem/System.IO.FileSystem.nfproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
<Compile Include="FileMode.cs" />
5454
<Compile Include="FileShare.cs" />
5555
<Compile Include="FileStream.cs" />
56+
<Compile Include="nanoFramework\CardDetectChangedEventArgs.cs" />
57+
<Compile Include="nanoFramework\CardDetectParameters.cs" />
58+
<Compile Include="nanoFramework\SDCardMmcParameters.cs" />
59+
<Compile Include="nanoFramework\SDCardSpiParameters.cs" />
5660
<Compile Include="NativeFindFile.cs" />
5761
<Compile Include="FileSystemInfo.cs" />
5862
<Compile Include="FileSystemManager.cs" />
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
using System;
7+
8+
namespace nanoFramework.System.IO
9+
{
10+
/// <summary>
11+
/// State of card detect
12+
/// </summary>
13+
public enum CardDetectState
14+
{
15+
/// <summary>
16+
/// Card Inserted
17+
/// </summary>
18+
Inserted,
19+
20+
/// <summary>
21+
/// Card removed
22+
/// </summary>
23+
Removed
24+
};
25+
26+
/// <summary>
27+
/// Arguments for Card detect event
28+
/// </summary>
29+
public class CardDetectChangedEventArgs : EventArgs
30+
{
31+
readonly private CardDetectState _cardState;
32+
readonly private uint _slotIndex;
33+
34+
internal CardDetectChangedEventArgs(CardDetectState state, uint SlotIndex)
35+
{
36+
_cardState = state;
37+
_slotIndex = SlotIndex;
38+
}
39+
40+
/// <summary>
41+
/// State of Card Detect.
42+
/// </summary>
43+
public CardDetectState CardState => _cardState;
44+
45+
/// <summary>
46+
/// SD card slot index
47+
/// </summary>
48+
public uint SlotIndex => _slotIndex;
49+
}
50+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace nanoFramework.System.IO.FileSystem
7+
{
8+
/// <summary>
9+
/// Parameter used for Card detection when creating a SDcard instance.
10+
/// </summary>
11+
public class CardDetectParameters
12+
{
13+
/// <summary>
14+
/// Set true when an Card Detect Pin is used.
15+
/// The cardDetectPin parameter must have a valid GPIO pin.
16+
/// </summary>
17+
/// <remarks>
18+
/// Not all SD Card modules have a card detect pin or the pin connected to a GPIO pin.
19+
/// </remarks>
20+
public bool enableCardDetectPin;
21+
22+
/// <summary>
23+
/// The state of the pin when the card is detected.
24+
/// Defaults to false(low) if not specified.
25+
/// If using card detect logic then this depends on connected hardware.
26+
/// </summary>
27+
public bool cardDetectedState;
28+
29+
/// <summary>
30+
/// The optional card detect GPIO pin which must be set to a valid pin if EnableCardDetectPin is true.
31+
/// If defined a StorageEventManager event will be raised when a card is inserted or removed.
32+
/// </summary>
33+
public uint cardDetectPin;
34+
35+
/// <summary>
36+
/// When enabled will try to automatically mount the SD card when the card is inserted.
37+
/// If the card is removed unexpectedly it will try to unmount card to release resources.
38+
/// </summary>
39+
public bool autoMount;
40+
}
41+
}

0 commit comments

Comments
 (0)