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

Add Removable Storage Events. #41

Closed
wants to merge 12 commits into from
6 changes: 3 additions & 3 deletions System.IO.FileSystem/System.IO.FileSystem.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@
</ProjectCapabilities>
</ProjectExtensions>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
<Import Project="..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets')" />
<Import Project="..\packages\Nerdbank.GitVersioning.3.4.231\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.4.231\build\Nerdbank.GitVersioning.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets'))" />
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.4.231\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.4.231\build\Nerdbank.GitVersioning.targets'))" />
</Target>
</Project>
</Project>
2 changes: 1 addition & 1 deletion System.IO.FileSystem/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="nanoFramework.CoreLibrary" version="1.10.5" targetFramework="netnanoframework10" />
<package id="Nerdbank.GitVersioning" version="3.3.37" developmentDependency="true" targetFramework="netnanoframework10" />
<package id="Nerdbank.GitVersioning" version="3.4.231" developmentDependency="true" targetFramework="netnanoframework10" />
</packages>
2 changes: 2 additions & 0 deletions Tests/NFUnitTestMemoryStream/NFUnitTestMemoryStream.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
<Reference Include="nanoFramework.TestFramework, Version=1.0.150.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>..\..\packages\nanoFramework.TestFramework.1.0.150\lib\nanoFramework.TestFramework.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="nanoFramework.UnitTestLauncher, Version=0.0.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>..\..\packages\nanoFramework.TestFramework.1.0.150\lib\nanoFramework.UnitTestLauncher.exe</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
8 changes: 7 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ steps:
# all build, update and publish steps
- template: azure-pipelines-templates/class-lib-build.yml@templates
parameters:
classLibName: $(nugetPackageName)
classLibName: 'nanoFramework.System.IO.FileSystem'
sonarCloudProject: 'nanoframework_lib-System.IO.FileSystem'
runUnitTests: true
unitTestRunsettings: '$(System.DefaultWorkingDirectory)\Tests\NFUnitTestMemoryStream\nano.runsettings'

- template: azure-pipelines-templates/class-lib-build.yml@templates
parameters:
classLibName: 'nanoFramework.Storage'
sonarCloudProject: 'nanoframework_lib-nanoFramework.Storage'
runUnitTests: false

# step from template @ nf-tools repo
# report error
- template: azure-pipelines-templates/discord-webhook-task.yml@templates
Expand Down
3 changes: 2 additions & 1 deletion config/filelist.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/System.IO.FileSystem.*
**/System.IO.FileSystem.*
**/nanoFramework.Storage.*
35 changes: 35 additions & 0 deletions nanoFramework.Storage.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>nanoFramework.Storage</id>
<version>$version$</version>
<title>nanoFramework.Storage</title>
<authors>nanoFramework project contributors</authors>
<owners>nanoFramework,dotnetfoundation</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="file">LICENSE.md</license>
<releaseNotes>
</releaseNotes>
<developmentDependency>false</developmentDependency>
<projectUrl>https://github.com/nanoframework/System.IO.FileSystem</projectUrl>
<icon>images\nf-logo.png</icon>
<repository type="git" url="https://github.com/nanoframework/System.IO.FileSystem" commit="$commit$" />
<copyright>Copyright (c) .NET Foundation and Contributors</copyright>
<description>This package includes the nanoFramework.Storage assembly for nanoFramework C# projects.
This package requires a target with nanoFramework.Storage v$nativeVersion$ (checksum $checksum$).</description>
<tags>nanoFramework C# csharp netmf netnf nanoFramework.Storage</tags>
<dependencies>
<dependency id="nanoFramework.CoreLibrary" version="1.10.5" />
</dependencies>
</metadata>
<files>
<file src="nanoFramework.Storage\bin\Release\nanoFramework.Storage.dll" target="lib\nanoFramework.Storage.dll" />
<file src="nanoFramework.Storage\bin\Release\nanoFramework.Storage.pdb" target="lib\nanoFramework.Storage.pdb" />
<file src="nanoFramework.Storage\bin\Release\nanoFramework.Storage.pdbx" target="lib\nanoFramework.Storage.pdbx" />
<file src="nanoFramework.Storage\bin\Release\nanoFramework.Storage.pe" target="lib\nanoFramework.Storage.pe" />
<file src="nanoFramework.Storage\bin\Release\nanoFramework.Storage.xml" target="lib\nanoFramework.Storage.xml" />
<file src="assets\readme.txt" target="" />
<file src="assets\nf-logo.png" target="images\" />
<file src="LICENSE.md" target="" />
</files>
</package>
90 changes: 90 additions & 0 deletions nanoFramework.Storage/ExternalDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Runtime.CompilerServices;

// TODO: it is debatible whether this class should exist, and parts of it could be auto detected in the native initialization!
namespace nanoFramework.Storage
{
/// <summary>
/// Class to allow a single SDCard to be mounted on the system.
/// Only allows for 1 device to be mounted, either via MMC or SPI
/// </summary>
public static class ExternalDriver //TODO: this was based on https://raw.githubusercontent.com/nanoframework/Windows.Storage/develop/Windows.Storage/StorageDevices.cs incase of reference.
{

#pragma warning disable 0649

// this field is set in native code
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
private static bool _mounted = false;

#pragma warning restore 0649

/// <summary>
/// Indcates if the SDscard has been mounted
/// </summary>
public static bool IsMounted => _mounted;

/// <summary>
/// Mount the SDcard device on the MMC interface
/// </summary>
/// <param name="Data1bit">If true denotes 1 bit data path will be used otherwise it will be 4 bits.</param>
/// <remarks>
/// This will try to mount the SDCard on the specified interface.
/// If the Card is not present or the card is unable to be read then an exception will be thrown.
/// </remarks>
[System.Diagnostics.DebuggerStepThrough]
public static void MountMMC(bool Data1bit)
{
MountMMCNative(Data1bit);
_mounted = true;
}

/// <summary>
/// Mount the SPI SDcard device on the specified SPI bus
/// </summary>
/// <param name="SpiController">The name for the SPI device, i.e "SPI1" </param>
/// <param name="ChipSelect">The GPIO pin used for chip select on SDcard.</param>
/// <remarks>
/// This will try to mount the SDCard on the specified interface.
/// If the Card is not present or the card is unable to be read then an exception will be thrown.
/// </remarks>
[System.Diagnostics.DebuggerStepThrough]
public static void MountSpi(int SpiBus, int ChipSelect)
{
MountSpiNative(SpiBus, ChipSelect);

// If no exception then set mounted flag
_mounted = true;
}

/// <summary>
/// Unmount the mounted SDcard.
/// </summary>
[System.Diagnostics.DebuggerStepThrough]
public static void Unmount()
{
UnmountNative();

// If no exception then set mounted flag
_mounted = false;
}

#region Native Calls

[System.Diagnostics.DebuggerStepThrough]
[MethodImpl(MethodImplOptions.InternalCall)]
private extern static void MountMMCNative(bool Data1bit);

[System.Diagnostics.DebuggerStepThrough]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void MountSpiNative(int SpiBus, int ChipSelect);

[System.Diagnostics.DebuggerStepThrough]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void UnmountNative();

#endregion

}
}

21 changes: 21 additions & 0 deletions nanoFramework.Storage/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("nanoFramework.Storage")]
[assembly: AssemblyCompany("nanoFramework Contributors")]
[assembly: AssemblyProduct("nanoFramework.Storage")]
[assembly: AssemblyCopyright("Copyright (c) .NET Foundation and Contributors")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

////////////////////////////////////////////////////////////////
// update this whenever the native assembly signature changes //
[assembly: AssemblyNativeVersion("1.0.0.0")]
////////////////////////////////////////////////////////////////
5 changes: 5 additions & 0 deletions nanoFramework.Storage/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
After updating the Nuget package(s)

1. After updating the Nuget packages, the project file (nfproj extension) has to be manually edited too in order to update the path for the new package for all <NFMDP_PE_LoadHints> tags.

2. The nuspec files have to be manually updated for the dependency versions to match the referenced packages.
65 changes: 65 additions & 0 deletions nanoFramework.Storage/RemovableStorageDeviceEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

using System;

namespace nanoFramework.Storage
{
/// <summary>
/// Contains argument values for Removable Storage Device events.
/// </summary>
public class RemovableStorageDeviceEventArgs : EventArgs //TODO: this was based on https://raw.githubusercontent.com/nanoframework/Windows.Storage/develop/Windows.Storage/RemovableDeviceEventArgs.cs incase of reference.
{
private readonly string _path;
private readonly RemovableStorageDeviceEvent _event;

internal RemovableStorageDeviceEventArgs(string path, RemovableStorageDeviceEvent deviceEvent)
{
_path = path;
_event = deviceEvent;
}

/// <summary>
/// The path of the Removable Storage Device.
/// </summary>
public string Path
{
get
{
return _path;
}
}

/// <summary>
/// The <see cref="RemovableStorageDeviceEvent"/> occurred.
/// </summary>
public RemovableStorageDeviceEvent Event
{
get
{
return _event;
}
}

/// <summary>
/// Specifies the type of event occurred with the Removable Storage Device specified.
/// </summary>
/// <remarks>
/// This enum is specific to nanoFramework. There is no equivalent in the .Net API.
/// </remarks>
public enum RemovableStorageDeviceEvent
{
/// <summary>
/// A Removable Device has been inserted.
/// </summary>
Inserted,

/// <summary>
/// A Removable Device has been removed.
/// </summary>
Removed,
}
}
}
Loading