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 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/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..75ed430 --- /dev/null +++ b/Tests/Test.Components.Sensors.Distance.HcSr04/Program.cs @@ -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); + } + } + + /// + /// 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..d32e889 --- /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 + 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 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