Skip to content

Commit

Permalink
Adding NETMFx projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
ianlee74 committed Jul 29, 2012
1 parent d9fe2fa commit 96d7033
Show file tree
Hide file tree
Showing 66 changed files with 3,267 additions and 8 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
bin
obj

# mstest test results
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
bin
obj

# mstest test results
TestResults
41 changes: 41 additions & 0 deletions NETMFx.Button/Button.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace NETMFx.Button
{
public delegate void ButtonPressedEventHandler(object sender, EventArgs e);

public class Button
{
private readonly InterruptPort _button;

/// <summary>
/// Debounce (glitch) filter time period in Ticks.
/// </summary>
public int DebouncePeriod = 200;

public Button(InterruptPort buttonPort)
{
_button = buttonPort;
_button.OnInterrupt += OnButtonPressed;
}

private DateTime _lastButtonPress = DateTime.Now;
private void OnButtonPressed(uint data1, uint data2, DateTime time)
{
if ((time - _lastButtonPress).Milliseconds <= DebouncePeriod) return;
_lastButtonPress = DateTime.Now;
OnButtonPressed(EventArgs.Empty);
}

public event ButtonPressedEventHandler ButtonPressed;
protected virtual void OnButtonPressed(EventArgs e)
{
if (ButtonPressed != null)
ButtonPressed(this, e);
}

}

}
41 changes: 41 additions & 0 deletions NETMFx.Button/NETMFx.Button.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AssemblyName>NETMFx.Button</AssemblyName>
<OutputType>Library</OutputType>
<RootNamespace>NETMFx.Button</RootNamespace>
<ProjectTypeGuids>{b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{1C420FEF-BE02-46AE-8EA9-9419A911B9E0}</ProjectGuid>
<TargetFrameworkVersion>v4.1</TargetFrameworkVersion>
<NetMfTargetsBaseDir Condition="'$(NetMfTargetsBaseDir)'==''">$(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\</NetMfTargetsBaseDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<Import Project="$(NetMfTargetsBaseDir)$(TargetFrameworkVersion)\CSharp.Targets" />
<ItemGroup>
<Compile Include="Button.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.SPOT.Hardware" />
<Reference Include="Microsoft.SPOT.Native">
</Reference>
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions NETMFx.Button/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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("NETMFx.Button")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NETMFx.Button")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
40 changes: 40 additions & 0 deletions NETMFx.Collections/NETMFx.Collections.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AssemblyName>NETMFx.Collections</AssemblyName>
<OutputType>Library</OutputType>
<RootNamespace>NETMFx.Collections</RootNamespace>
<ProjectTypeGuids>{b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AEB5AC51-BD1A-48F0-B600-A7EB838F1392}</ProjectGuid>
<TargetFrameworkVersion>v4.1</TargetFrameworkVersion>
<NetMfTargetsBaseDir Condition="'$(NetMfTargetsBaseDir)'==''">$(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\</NetMfTargetsBaseDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<Import Project="$(NetMfTargetsBaseDir)$(TargetFrameworkVersion)\CSharp.Targets" />
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StringFifoQueue.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.SPOT.Native">
</Reference>
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions NETMFx.Collections/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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("NETMFx.Collections")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("NETMFx.Collections")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
37 changes: 37 additions & 0 deletions NETMFx.Collections/StringFifoQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections;

namespace NETMFx.Collections
{
public class StringFifoQueue
{
protected ArrayList Queue;
public StringFifoQueue()
{
Queue = new ArrayList();
}

public int Count
{
get { return Queue.Count; }
}

public void Add(string data)
{
Queue.Add(data);
}

public string GetNext()
{
// TODO: Lock thread.
var data = PeekNext();
if (data == null) return null;
Queue.RemoveAt(0);
return data;
}

public string PeekNext()
{
return Queue.Count > 0 ? Queue[0].ToString() : null;
}
}
}
123 changes: 123 additions & 0 deletions NETMFx.GroveHeartRateSensor/CircularDateQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using System;

namespace NETMFx.GroveHeartRateSensor
{
internal class CircularDateQueue
{
private DateTime[] _queue;

/// <summary>
/// Constructor
/// </summary>
/// <param name="size">The max number of items that the queue will contain.</param>
public CircularDateQueue(int size)
{
Size = size;
}

/// <summary>
/// The max number of items that the queue will contain.
/// </summary>
public int Size
{
get { return _size; }
set
{
_size = value;
Clear();
}
}
private int _size;

/// <summary>
/// Clears the queue.
/// </summary>
public void Clear()
{
_queue = new DateTime[Size];
Top = 0;
Bottom = 0;
Count = 0;
}

/// <summary>
/// Index of the top (newest) item.
/// </summary>
public int Top
{
get { return _top; }
set { _top = value; }
}
private int _top;

/// <summary>
/// Index of the bottom (oldest) item.
/// </summary>
public int Bottom
{
get { return _bottom; }
set { _bottom = value; }
}
private int _bottom;

/// <summary>
/// Count of items currently in the queue.
/// </summary>
public int Count
{
get { return _count; }
private set { _count = value; }
}
private int _count;

/// <summary>
/// Index of the queue position where the next item will go.
/// </summary>
private int Next(int index)
{
if (Count == 0) return 0;
if (index < Size-1) return index + 1;
return 0;
}

/// <summary>
/// Add an item to the queue.
/// </summary>
/// <param name="time">The DateTime item to add.</param>
public void Add(DateTime item)
{
// Add the item to the top of the queue (overwriting the oldest item if the queue is full).
var nextNdx = Next(Top);
_queue[nextNdx] = item;
Top = nextNdx;

// Reset the bottom pointer.
Bottom = Count < Size-1 ? 0 : Next(Bottom);

if(Count < Size-1) Count++;
}

/// <summary>
/// Returns the value of the specified item.
/// </summary>
/// <param name="index">The index of the item to retrieve.</param>
/// <returns>DateTime object.</returns>
public DateTime Peek(int index)
{
return _queue[index];
}

/// <summary>
/// The total timespan as measured as the difference between the top item and the bottom items of the queue.
/// </summary>
public TimeSpan TimeSpan
{
get
{
var start = Peek(Bottom);
var end = Peek(Top);
return end.Subtract(start);
}
}
}
}
Loading

0 comments on commit 96d7033

Please sign in to comment.