- Notifications
You must be signed in to change notification settings - Fork135
Test program for distance sensor HcSr04#80
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
lkroliko wants to merge5 commits intoraspberry-sharp:masterChoose a base branch fromlkroliko:master
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletionsRaspberry.IO.Components/Controllers/Pca9685/PwmChannel.cs 100644 → 100755
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -17,5 +17,9 @@ public enum PwmChannel | ||
| C9 = 9, | ||
| C10 = 10, | ||
| C11 = 11, | ||
| C12 = 12, | ||
| C13 = 13, | ||
| C14 = 14, | ||
| C15 = 15 | ||
| } | ||
| } | ||
2 changes: 1 addition & 1 deletionRaspberry.IO/Raspberry.IO.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -59,4 +59,4 @@ | ||
| <Target Name="AfterBuild"> | ||
| </Target> | ||
| --> | ||
| </Project> | ||
9 changes: 8 additions & 1 deletionRaspberrySharp.IO.sln
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletionsTests/Test.Components.Sensors.Distance.HcSr04/App.config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <configuration> | ||
| <startup> | ||
| <supportedRuntimeversion="v4.0"sku=".NETFramework,Version=v4.6.1" /> | ||
| </startup> | ||
| </configuration> |
157 changes: 157 additions & 0 deletionsTests/Test.Components.Sensors.Distance.HcSr04/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| using System; | ||
| using Raspberry.IO.Components.Sensors.Distance.HcSr04; | ||
| using Raspberry.IO.GeneralPurpose; | ||
| using UnitsNet; | ||
| using System.Threading; | ||
| namespace Test.Components.Sensors.Distance.HcSr04 | ||
| { | ||
| class Program | ||
| { | ||
| private static GpioConnectionDriver driver; | ||
| private static HcSr04Connection sensor; | ||
| private static GpioOutputBinaryPin triggerGpioPin; | ||
| private static GpioInputBinaryPin echoGpioPin; | ||
| private static int triggerGpioPinSetting = 0; | ||
| private static int echoGpioPinSetting = 0; | ||
| private static int delay = 500; | ||
| private static int readError = 0; | ||
| static void Main(string[] args) | ||
| { | ||
| //Configure GPIO pins bellow or provide in console | ||
| //triggerGpioPinSetting = 20; | ||
| //echoGpioPinSetting = 26; | ||
| //Reads GPIO pins from console | ||
| if (triggerGpioPinSetting == 0) | ||
| triggerGpioPinSetting = GetGpioPin("trigger"); | ||
| if (echoGpioPinSetting == 0) | ||
| echoGpioPinSetting = GetGpioPin("echo"); | ||
| Console.CursorVisible = false; | ||
| //Creating sensor | ||
| driver = new GpioConnectionDriver(); | ||
| triggerGpioPin = new GpioOutputBinaryPin(driver, (ProcessorPin)triggerGpioPinSetting); | ||
| echoGpioPin = new GpioInputBinaryPin(driver, (ProcessorPin)echoGpioPinSetting); | ||
| sensor = new HcSr04Connection(triggerGpioPin, echoGpioPin); | ||
| while(true) | ||
| { | ||
| if (Console.KeyAvailable) | ||
| KeyPressed(); | ||
| try | ||
| { | ||
| //Get data from sensor and print them | ||
| Length distance = sensor.GetDistance(); | ||
| PrintHeader(); | ||
| PrintData(distance); | ||
| PrintFooter(); | ||
| } | ||
| catch | ||
| { | ||
| readError++; | ||
| } | ||
| Thread.Sleep(delay); | ||
| } | ||
| } | ||
| /// <summary> | ||
| /// Console read key support | ||
| /// </summary> | ||
| private static void KeyPressed() | ||
| { | ||
| ConsoleKeyInfo cki = Console.ReadKey(); | ||
| switch (cki.Key) | ||
| { | ||
| case ConsoleKey.UpArrow: | ||
| delay = delay > 50 ? delay - 50 : delay; | ||
| break; | ||
| case ConsoleKey.DownArrow: | ||
| delay = delay < 1000 ? delay + 50 : delay; | ||
| break; | ||
| case ConsoleKey.Escape: | ||
| Environment.Exit(0); | ||
| break; | ||
| } | ||
| if (Console.KeyAvailable) | ||
| KeyPressed(); | ||
| } | ||
| /// <summary> | ||
| /// Get GPIO pins from console | ||
| /// </summary> | ||
| /// <param name="pinName">GPIO pin usage</param> | ||
| /// <param name="message">Error message</param> | ||
| /// <returns></returns> | ||
| private static int GetGpioPin(string pinName, string message = "") | ||
| { | ||
| PrintHeader(); | ||
| Console.WriteLine(); | ||
| if (!string.IsNullOrEmpty(message)) | ||
| { | ||
| Console.WriteLine(message); | ||
| Console.WriteLine(); | ||
| } | ||
| Console.Write(string.Format(" Please enter GPIO pin number for {0} pin: ", pinName)); | ||
| string answer = Console.ReadLine(); | ||
| int pin; | ||
| bool result = int.TryParse(answer, out pin); | ||
| if(result) | ||
| { | ||
| if (pin > 32) | ||
| return GetGpioPin(pinName, string.Format(" Error. Value {0} is to big", pin)); | ||
| return pin; | ||
| } | ||
| else | ||
| { | ||
| return GetGpioPin(string.Format(pinName, "Error. Unable parse string {0}", answer)); | ||
| } | ||
| } | ||
| #region Print Methods | ||
| private static void PrintHeader() | ||
| { | ||
| Console.Clear(); | ||
| Console.WriteLine(); | ||
| Console.WriteLine(" #################################"); | ||
| Console.WriteLine(" # Demo pogram for sensor HCSR04 #"); | ||
| Console.WriteLine(" #################################"); | ||
| Console.WriteLine(); | ||
| if(triggerGpioPinSetting != 0) | ||
| Console.WriteLine(" Trigger pin GPIO{0}", triggerGpioPinSetting); | ||
| if(echoGpioPinSetting != 0) | ||
| Console.WriteLine(" Echo pin GPIO{0}", echoGpioPinSetting); | ||
| } | ||
| private static void PrintData(Length length) | ||
| { | ||
| Console.WriteLine(" Reads {0:0.0} per secound [Hz]", 1000.0 / delay); | ||
| Console.WriteLine(); | ||
| Console.WriteLine(" Read errors {0}", readError); | ||
| Console.WriteLine(" Length {0,5:0.0} cm", length.Centimeters); | ||
| Console.WriteLine(" Length {0,5:0.0} inch", length.Inches); | ||
| } | ||
| private static void PrintFooter() | ||
| { | ||
| if (Console.WindowHeight < 17) | ||
| return; | ||
| Console.SetCursorPosition(0, Console.WindowHeight - 4); | ||
| Console.WriteLine(" Press arrow up to increase read sppead"); | ||
| Console.WriteLine(" Press arrow down to decrease read sppead"); | ||
| Console.WriteLine(" Press escape key to exit"); | ||
| } | ||
| #endregion | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletionsTests/Test.Components.Sensors.Distance.HcSr04/Properties/AssemblyInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| 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("Test.Components.Sensors.Distance.HcSr04")] | ||
| [assembly: AssemblyDescription("")] | ||
| [assembly: AssemblyConfiguration("")] | ||
| [assembly: AssemblyCompany("")] | ||
| [assembly: AssemblyProduct("Test.Components.Sensors.Distance.HcSr04")] | ||
| [assembly: AssemblyCopyright("Copyright © 2017")] | ||
| [assembly: AssemblyTrademark("")] | ||
| [assembly: AssemblyCulture("")] | ||
| // 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)] | ||
| // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
| [assembly: Guid("a2d800af-749c-4b8f-8cc6-7b5e99f3eac5")] | ||
| // Version information for an assembly consists of the following four values: | ||
| // | ||
| // Major Version | ||
| // Minor Version | ||
| // Build Number | ||
| // Revision | ||
| // | ||
| // You can specify all the values or you can default the Build and Revision Numbers | ||
| // by using the '*' as shown below: | ||
| // [assembly: AssemblyVersion("1.0.*")] | ||
| [assembly: AssemblyVersion("1.0.0.0")] | ||
| [assembly: AssemblyFileVersion("1.0.0.0")] |
79 changes: 79 additions & 0 deletionsTests/Test.Components.Sensors.Distance.HcSr04/Test.Components.Sensors.Distance.HcSr04.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
| <PropertyGroup> | ||
| <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
| <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
| <ProjectGuid>{A2D800AF-749C-4B8F-8CC6-7B5E99F3EAC5}</ProjectGuid> | ||
| <OutputType>Exe</OutputType> | ||
| <AppDesignerFolder>Properties</AppDesignerFolder> | ||
| <RootNamespace>Test.Components.Sensors.Distance.HcSr04</RootNamespace> | ||
| <AssemblyName>Test.Components.Sensors.Distance.HcSr04</AssemblyName> | ||
| <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
| <FileAlignment>512</FileAlignment> | ||
| <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
| <PlatformTarget>AnyCPU</PlatformTarget> | ||
| <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' "> | ||
| <PlatformTarget>AnyCPU</PlatformTarget> | ||
| <DebugType>pdbonly</DebugType> | ||
| <Optimize>true</Optimize> | ||
| <OutputPath>bin\Release\</OutputPath> | ||
| <DefineConstants>TRACE</DefineConstants> | ||
| <ErrorReport>prompt</ErrorReport> | ||
| <WarningLevel>4</WarningLevel> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Reference Include="System" /> | ||
| <Reference Include="System.Core" /> | ||
| <Reference Include="System.Xml.Linq" /> | ||
| <Reference Include="System.Data.DataSetExtensions" /> | ||
| <Reference Include="Microsoft.CSharp" /> | ||
| <Reference Include="System.Data" /> | ||
| <Reference Include="System.Net.Http" /> | ||
| <Reference Include="System.Xml" /> | ||
| <Reference Include="UnitsNet, Version=3.49.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
| <HintPath>..\..\packages\UnitsNet.3.49.0\lib\net35\UnitsNet.dll</HintPath> | ||
| <Private>True</Private> | ||
| </Reference> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Compile Include="Program.cs" /> | ||
| <Compile Include="Properties\AssemblyInfo.cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <None Include="App.config" /> | ||
| <None Include="packages.config" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\Raspberry.IO.Components\Raspberry.IO.Components.csproj"> | ||
| <Project>{8388cfca-e3db-43f7-b049-2cb195211ce8}</Project> | ||
| <Name>Raspberry.IO.Components</Name> | ||
| </ProjectReference> | ||
| <ProjectReference Include="..\..\Raspberry.IO.GeneralPurpose\Raspberry.IO.GeneralPurpose.csproj"> | ||
| <Project>{281c71ed-c36d-408e-8baa-75c381dc17e7}</Project> | ||
| <Name>Raspberry.IO.GeneralPurpose</Name> | ||
| </ProjectReference> | ||
| <ProjectReference Include="..\..\Raspberry.IO\Raspberry.IO.csproj"> | ||
| <Project>{ace64f17-87e5-43e7-97a0-bdde19059c61}</Project> | ||
| <Name>Raspberry.IO</Name> | ||
| </ProjectReference> | ||
| </ItemGroup> | ||
| <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
| <!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
| Other similar extension points exist, see Microsoft.Common.targets. | ||
| <Target Name="BeforeBuild"> | ||
| </Target> | ||
| <Target Name="AfterBuild"> | ||
| </Target> | ||
| --> | ||
| </Project> |
4 changes: 4 additions & 0 deletionsTests/Test.Components.Sensors.Distance.HcSr04/packages.config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="UnitsNet" version="3.49.0" targetFramework="net461" /> | ||
| </packages> |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.