From eb2883808d45030e509ce8f703128476d2212e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20K?= Date: Sun, 8 Jan 2017 08:57:26 +0100 Subject: [PATCH 1/5] Fix PWM channel enum --- Raspberry.IO.Components/Controllers/Pca9685/PwmChannel.cs | 4 ++++ 1 file changed, 4 insertions(+) mode change 100644 => 100755 Raspberry.IO.Components/Controllers/Pca9685/PwmChannel.cs diff --git a/Raspberry.IO.Components/Controllers/Pca9685/PwmChannel.cs b/Raspberry.IO.Components/Controllers/Pca9685/PwmChannel.cs old mode 100644 new mode 100755 index 696d332..99ae1ec --- a/Raspberry.IO.Components/Controllers/Pca9685/PwmChannel.cs +++ b/Raspberry.IO.Components/Controllers/Pca9685/PwmChannel.cs @@ -17,5 +17,9 @@ public enum PwmChannel C9 = 9, C10 = 10, C11 = 11, + C12 = 12, + C13 = 13, + C14 = 14, + C15 = 15 } } \ No newline at end of file From 70404e87e8c5980c35044c8e8c5f481360382753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kr=C3=B3likowski?= Date: Sun, 8 Jan 2017 17:37:16 +0100 Subject: [PATCH 2/5] Add test program for distance sensor HcSr04 --- RaspberrySharp.IO.sln | 9 +- .../App.config | 6 + .../Program.cs | 161 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++ ....Components.Sensors.Distance.HcSr04.csproj | 79 +++++++++ .../packages.config | 4 + 6 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 Tests/Test.Components.Sensors.Distance.HcSr04/App.config create mode 100644 Tests/Test.Components.Sensors.Distance.HcSr04/Program.cs create mode 100644 Tests/Test.Components.Sensors.Distance.HcSr04/Properties/AssemblyInfo.cs create mode 100644 Tests/Test.Components.Sensors.Distance.HcSr04/Test.Components.Sensors.Distance.HcSr04.csproj create mode 100644 Tests/Test.Components.Sensors.Distance.HcSr04/packages.config diff --git a/RaspberrySharp.IO.sln b/RaspberrySharp.IO.sln index def0123..a905ee0 100644 --- a/RaspberrySharp.IO.sln +++ b/RaspberrySharp.IO.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raspberry.IO.GeneralPurpose", "Raspberry.IO.GeneralPurpose\Raspberry.IO.GeneralPurpose.csproj", "{281C71ED-C36D-408E-8BAA-75C381DC17E7}" EndProject @@ -66,6 +66,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raspberry.IO.Interop", "Ras EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.Gpio.Ds1307", "Tests\Test.Gpio.Ds1307\Test.Gpio.Ds1307.csproj", "{E9412139-F9EA-4E39-AB7C-CE775ED06C82}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.Components.Sensors.Distance.HcSr04", "Tests\Test.Components.Sensors.Distance.HcSr04\Test.Components.Sensors.Distance.HcSr04.csproj", "{A2D800AF-749C-4B8F-8CC6-7B5E99F3EAC5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -172,6 +174,10 @@ Global {E9412139-F9EA-4E39-AB7C-CE775ED06C82}.Debug|Any CPU.Build.0 = Debug|Any CPU {E9412139-F9EA-4E39-AB7C-CE775ED06C82}.Release|Any CPU.ActiveCfg = Release|Any CPU {E9412139-F9EA-4E39-AB7C-CE775ED06C82}.Release|Any CPU.Build.0 = Release|Any CPU + {A2D800AF-749C-4B8F-8CC6-7B5E99F3EAC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A2D800AF-749C-4B8F-8CC6-7B5E99F3EAC5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A2D800AF-749C-4B8F-8CC6-7B5E99F3EAC5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A2D800AF-749C-4B8F-8CC6-7B5E99F3EAC5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -198,6 +204,7 @@ Global {99EB3D1A-F0B7-454E-BB50-9B2F5349BC5B} = {C39D0CC3-C0F2-4B58-8779-2CCB5B52534C} {CAF876A0-0FCB-44F7-96F1-53704CB6015F} = {C39D0CC3-C0F2-4B58-8779-2CCB5B52534C} {E9412139-F9EA-4E39-AB7C-CE775ED06C82} = {15ECD485-B3FD-4B6F-8491-7489DFFC89BC} + {A2D800AF-749C-4B8F-8CC6-7B5E99F3EAC5} = {15ECD485-B3FD-4B6F-8491-7489DFFC89BC} EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution Policies = $0 diff --git a/Tests/Test.Components.Sensors.Distance.HcSr04/App.config b/Tests/Test.Components.Sensors.Distance.HcSr04/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/Tests/Test.Components.Sensors.Distance.HcSr04/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Tests/Test.Components.Sensors.Distance.HcSr04/Program.cs b/Tests/Test.Components.Sensors.Distance.HcSr04/Program.cs new file mode 100644 index 0000000..d931b83 --- /dev/null +++ b/Tests/Test.Components.Sensors.Distance.HcSr04/Program.cs @@ -0,0 +1,161 @@ +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); + } + } + + /// + /// Console read key support + /// + 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(); + } + + /// + /// Get GPIO pins from console + /// + /// GPIO pin usage + /// Error message + /// + 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 + } +} diff --git a/Tests/Test.Components.Sensors.Distance.HcSr04/Properties/AssemblyInfo.cs b/Tests/Test.Components.Sensors.Distance.HcSr04/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3f53fc0 --- /dev/null +++ b/Tests/Test.Components.Sensors.Distance.HcSr04/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Tests/Test.Components.Sensors.Distance.HcSr04/Test.Components.Sensors.Distance.HcSr04.csproj b/Tests/Test.Components.Sensors.Distance.HcSr04/Test.Components.Sensors.Distance.HcSr04.csproj new file mode 100644 index 0000000..b899e27 --- /dev/null +++ b/Tests/Test.Components.Sensors.Distance.HcSr04/Test.Components.Sensors.Distance.HcSr04.csproj @@ -0,0 +1,79 @@ + + + + + Debug + AnyCPU + {A2D800AF-749C-4B8F-8CC6-7B5E99F3EAC5} + Exe + Properties + Test.Components.Sensors.Distance.HcSr04 + Test.Components.Sensors.Distance.HcSr04 + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + \\192.168.0.16\robo\raspberry-sharp-io\Tests\Test.Components.Sensors.Distance.HcSr04\bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + ..\..\packages\UnitsNet.3.49.0\lib\net35\UnitsNet.dll + True + + + + + + + + + + + + + {8388cfca-e3db-43f7-b049-2cb195211ce8} + Raspberry.IO.Components + + + {281c71ed-c36d-408e-8baa-75c381dc17e7} + Raspberry.IO.GeneralPurpose + + + {ace64f17-87e5-43e7-97a0-bdde19059c61} + Raspberry.IO + + + + + \ No newline at end of file diff --git a/Tests/Test.Components.Sensors.Distance.HcSr04/packages.config b/Tests/Test.Components.Sensors.Distance.HcSr04/packages.config new file mode 100644 index 0000000..4d06382 --- /dev/null +++ b/Tests/Test.Components.Sensors.Distance.HcSr04/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From a7e8a8660ebd3fd12aace102d24586e2d3937193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kr=C3=B3likowski?= Date: Sun, 8 Jan 2017 17:56:36 +0100 Subject: [PATCH 3/5] Fix output path --- Raspberry.IO/Raspberry.IO.csproj | 2 +- .../Test.Components.Sensors.Distance.HcSr04.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Raspberry.IO/Raspberry.IO.csproj b/Raspberry.IO/Raspberry.IO.csproj index e58e755..b40fd49 100644 --- a/Raspberry.IO/Raspberry.IO.csproj +++ b/Raspberry.IO/Raspberry.IO.csproj @@ -59,4 +59,4 @@ --> - + \ No newline at end of file diff --git a/Tests/Test.Components.Sensors.Distance.HcSr04/Test.Components.Sensors.Distance.HcSr04.csproj b/Tests/Test.Components.Sensors.Distance.HcSr04/Test.Components.Sensors.Distance.HcSr04.csproj index b899e27..831c539 100644 --- a/Tests/Test.Components.Sensors.Distance.HcSr04/Test.Components.Sensors.Distance.HcSr04.csproj +++ b/Tests/Test.Components.Sensors.Distance.HcSr04/Test.Components.Sensors.Distance.HcSr04.csproj @@ -27,7 +27,7 @@ AnyCPU pdbonly true - \\192.168.0.16\robo\raspberry-sharp-io\Tests\Test.Components.Sensors.Distance.HcSr04\bin\Release\ + C:\bin\Release\ TRACE prompt 4 From baad0b1ae8a5c5559f0c13386d884b5ba0102006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kr=C3=B3likowski?= Date: Sun, 8 Jan 2017 18:02:24 +0100 Subject: [PATCH 4/5] Fix output path --- .../Test.Components.Sensors.Distance.HcSr04.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Test.Components.Sensors.Distance.HcSr04/Test.Components.Sensors.Distance.HcSr04.csproj b/Tests/Test.Components.Sensors.Distance.HcSr04/Test.Components.Sensors.Distance.HcSr04.csproj index 831c539..d32e889 100644 --- a/Tests/Test.Components.Sensors.Distance.HcSr04/Test.Components.Sensors.Distance.HcSr04.csproj +++ b/Tests/Test.Components.Sensors.Distance.HcSr04/Test.Components.Sensors.Distance.HcSr04.csproj @@ -27,7 +27,7 @@ AnyCPU pdbonly true - C:\bin\Release\ + bin\Release\ TRACE prompt 4 From 69f9fb3b5b37046f48b7c86e3f92024a56c5f715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kr=C3=B3likowski?= Date: Sun, 8 Jan 2017 18:05:40 +0100 Subject: [PATCH 5/5] Fix output path --- Tests/Test.Components.Sensors.Distance.HcSr04/Program.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Tests/Test.Components.Sensors.Distance.HcSr04/Program.cs b/Tests/Test.Components.Sensors.Distance.HcSr04/Program.cs index d931b83..75ed430 100644 --- a/Tests/Test.Components.Sensors.Distance.HcSr04/Program.cs +++ b/Tests/Test.Components.Sensors.Distance.HcSr04/Program.cs @@ -43,7 +43,6 @@ static void Main(string[] args) if (Console.KeyAvailable) KeyPressed(); - try { //Get data from sensor and print them @@ -56,8 +55,7 @@ static void Main(string[] args) { readError++; } - - + Thread.Sleep(delay); } } @@ -132,8 +130,7 @@ private static void PrintHeader() if(triggerGpioPinSetting != 0) Console.WriteLine(" Trigger pin GPIO{0}", triggerGpioPinSetting); if(echoGpioPinSetting != 0) - Console.WriteLine(" Echo pin GPIO{0}", echoGpioPinSetting); - + Console.WriteLine(" Echo pin GPIO{0}", echoGpioPinSetting); } private static void PrintData(Length length) @@ -153,7 +150,6 @@ private static void PrintFooter() 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 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy