Coding styles
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
namespace Unosquare.RaspberryIO.Native
|
||||
{
|
||||
/// <summary>
|
||||
/// A delegate defining a callback for an Interrupt Service Routine
|
||||
/// </summary>
|
||||
public delegate void InterruptServiceRoutineCallback();
|
||||
|
||||
/// <summary>
|
||||
/// Defines the body of a thread worker
|
||||
/// </summary>
|
||||
public delegate void ThreadWorker();
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
/// <summary>
|
||||
/// A delegate defining a callback for an Interrupt Service Routine
|
||||
/// </summary>
|
||||
public delegate void InterruptServiceRoutineCallback();
|
||||
|
||||
/// <summary>
|
||||
/// Defines the body of a thread worker
|
||||
/// </summary>
|
||||
public delegate void ThreadWorker();
|
||||
}
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
namespace Unosquare.RaspberryIO.Native
|
||||
{
|
||||
using Swan;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using Unosquare.Swan;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
/// <summary>
|
||||
/// Represents a low-level exception, typically thrown when return codes from a
|
||||
/// low-level operation is non-zero or in some cases when it is less than zero.
|
||||
/// </summary>
|
||||
/// <seealso cref="Exception" />
|
||||
public class HardwareException : Exception {
|
||||
/// <summary>
|
||||
/// Represents a low-level exception, typically thrown when return codes from a
|
||||
/// low-level operation is non-zero or in some cases when it is less than zero.
|
||||
/// Initializes a new instance of the <see cref="HardwareException" /> class.
|
||||
/// </summary>
|
||||
/// <seealso cref="Exception" />
|
||||
public class HardwareException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HardwareException" /> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">The error code.</param>
|
||||
/// <param name="component">The component.</param>
|
||||
public HardwareException(int errorCode, string component)
|
||||
: base($"A hardware exception occurred. Error Code: {errorCode}")
|
||||
{
|
||||
ExtendedMessage = null;
|
||||
|
||||
try
|
||||
{
|
||||
ExtendedMessage = Standard.Strerror(errorCode);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: strerror not working great...
|
||||
$"Could not retrieve native error description using {nameof(Standard.Strerror)}".Error(Pi.LoggerSource);
|
||||
}
|
||||
|
||||
ErrorCode = errorCode;
|
||||
Component = component;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The error code.
|
||||
/// </value>
|
||||
public int ErrorCode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the component.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The component.
|
||||
/// </value>
|
||||
public string Component { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the extended message (could be null).
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The extended message.
|
||||
/// </value>
|
||||
public string ExtendedMessage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new instance of a hardware error by retrieving the last error number (errno).
|
||||
/// </summary>
|
||||
/// <param name="className">Name of the class.</param>
|
||||
/// <param name="methodName">Name of the method.</param>
|
||||
/// <exception cref="HardwareException">When an error thrown by an API call occurs</exception>
|
||||
public static void Throw(string className, string methodName) => throw new HardwareException(Marshal.GetLastWin32Error(), $"{className}.{methodName}");
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => $"{GetType()}{(string.IsNullOrWhiteSpace(Component) ? string.Empty : $" on {Component}")}: ({ErrorCode}) - {Message}";
|
||||
}
|
||||
/// <param name="errorCode">The error code.</param>
|
||||
/// <param name="component">The component.</param>
|
||||
public HardwareException(Int32 errorCode, String component)
|
||||
: base($"A hardware exception occurred. Error Code: {errorCode}") {
|
||||
this.ExtendedMessage = null;
|
||||
|
||||
try {
|
||||
this.ExtendedMessage = Standard.Strerror(errorCode);
|
||||
} catch {
|
||||
// TODO: strerror not working great...
|
||||
$"Could not retrieve native error description using {nameof(Standard.Strerror)}".Error(Pi.LoggerSource);
|
||||
}
|
||||
|
||||
this.ErrorCode = errorCode;
|
||||
this.Component = component;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The error code.
|
||||
/// </value>
|
||||
public Int32 ErrorCode {
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the component.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The component.
|
||||
/// </value>
|
||||
public String Component {
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the extended message (could be null).
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The extended message.
|
||||
/// </value>
|
||||
public String ExtendedMessage {
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new instance of a hardware error by retrieving the last error number (errno).
|
||||
/// </summary>
|
||||
/// <param name="className">Name of the class.</param>
|
||||
/// <param name="methodName">Name of the method.</param>
|
||||
/// <exception cref="HardwareException">When an error thrown by an API call occurs</exception>
|
||||
public static void Throw(String className, String methodName) => throw new HardwareException(Marshal.GetLastWin32Error(), $"{className}.{methodName}");
|
||||
|
||||
/// <inheritdoc />
|
||||
public override String ToString() => $"{this.GetType()}{(String.IsNullOrWhiteSpace(this.Component) ? String.Empty : $" on {this.Component}")}: ({this.ErrorCode}) - {this.Message}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,30 @@
|
||||
namespace Unosquare.RaspberryIO.Native
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
/// <summary>
|
||||
/// Provides access to a high- esolution, time measuring device.
|
||||
/// </summary>
|
||||
/// <seealso cref="Stopwatch" />
|
||||
public class HighResolutionTimer : Stopwatch {
|
||||
/// <summary>
|
||||
/// Provides access to a high- esolution, time measuring device.
|
||||
/// Initializes a new instance of the <see cref="HighResolutionTimer"/> class.
|
||||
/// </summary>
|
||||
/// <seealso cref="Stopwatch" />
|
||||
public class HighResolutionTimer : Stopwatch
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HighResolutionTimer"/> class.
|
||||
/// </summary>
|
||||
/// <exception cref="NotSupportedException">High-resolution timer not available</exception>
|
||||
public HighResolutionTimer()
|
||||
{
|
||||
if (!IsHighResolution)
|
||||
throw new NotSupportedException("High-resolution timer not available");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the numer of microseconds per timer tick.
|
||||
/// </summary>
|
||||
public static double MicrosecondsPerTick { get; } = 1000000d / Frequency;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the elapsed microseconds.
|
||||
/// </summary>
|
||||
public long ElapsedMicroseconds => (long)(ElapsedTicks * MicrosecondsPerTick);
|
||||
}
|
||||
/// <exception cref="NotSupportedException">High-resolution timer not available</exception>
|
||||
public HighResolutionTimer() {
|
||||
if(!IsHighResolution) {
|
||||
throw new NotSupportedException("High-resolution timer not available");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the numer of microseconds per timer tick.
|
||||
/// </summary>
|
||||
public static Double MicrosecondsPerTick { get; } = 1000000d / Frequency;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the elapsed microseconds.
|
||||
/// </summary>
|
||||
public Int64 ElapsedMicroseconds => (Int64)(this.ElapsedTicks * MicrosecondsPerTick);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +1,80 @@
|
||||
namespace Unosquare.RaspberryIO.Native
|
||||
{
|
||||
using Swan;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
using Unosquare.Swan;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
/// <summary>
|
||||
/// Provides standard libc calls using platform-invoke
|
||||
/// </summary>
|
||||
internal static class Standard {
|
||||
internal const String LibCLibrary = "libc";
|
||||
|
||||
#region LibC Calls
|
||||
|
||||
/// <summary>
|
||||
/// Provides standard libc calls using platform-invoke
|
||||
/// Strerrors the specified error.
|
||||
/// </summary>
|
||||
internal static class Standard
|
||||
{
|
||||
internal const string LibCLibrary = "libc";
|
||||
|
||||
#region LibC Calls
|
||||
|
||||
/// <summary>
|
||||
/// Strerrors the specified error.
|
||||
/// </summary>
|
||||
/// <param name="error">The error.</param>
|
||||
/// <returns></returns>
|
||||
public static string Strerror(int error)
|
||||
{
|
||||
if (!Runtime.IsUsingMonoRuntime) return StrError(error);
|
||||
|
||||
try
|
||||
{
|
||||
var buffer = new StringBuilder(256);
|
||||
var result = Strerror(error, buffer, (ulong)buffer.Capacity);
|
||||
return (result != -1) ? buffer.ToString() : null;
|
||||
}
|
||||
catch (EntryPointNotFoundException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes file permissions on a Unix file system
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(LibCLibrary, EntryPoint = "chmod", SetLastError = true)]
|
||||
public static extern int Chmod(string filename, uint mode);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a string to a 32 bit integer. Use endpointer as IntPtr.Zero
|
||||
/// </summary>
|
||||
/// <param name="numberString">The number string.</param>
|
||||
/// <param name="endPointer">The end pointer.</param>
|
||||
/// <param name="numberBase">The number base.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(LibCLibrary, EntryPoint = "strtol", SetLastError = true)]
|
||||
public static extern int StringToInteger(string numberString, IntPtr endPointer, int numberBase);
|
||||
|
||||
/// <summary>
|
||||
/// The write() function attempts to write nbytes from buffer to the file associated with handle. On text files, it expands each LF to a CR/LF.
|
||||
/// The function returns the number of bytes written to the file. A return value of -1 indicates an error, with errno set appropriately.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="buffer">The buffer.</param>
|
||||
/// <param name="count">The count.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(LibCLibrary, EntryPoint = "write", SetLastError = true)]
|
||||
public static extern int Write(int fd, byte[] buffer, int count);
|
||||
|
||||
/// <summary>
|
||||
/// Fills in the structure with information about the system.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(LibCLibrary, EntryPoint = "uname", SetLastError = true)]
|
||||
public static extern int Uname(out SystemName name);
|
||||
|
||||
[DllImport(LibCLibrary, EntryPoint = "strerror", SetLastError = true)]
|
||||
private static extern string StrError(int errnum);
|
||||
|
||||
[DllImport("MonoPosixHelper", EntryPoint = "Mono_Posix_Syscall_strerror_r", SetLastError = true)]
|
||||
private static extern int Strerror(int error, [Out] StringBuilder buffer, ulong length);
|
||||
|
||||
#endregion
|
||||
}
|
||||
/// <param name="error">The error.</param>
|
||||
/// <returns></returns>
|
||||
public static String Strerror(Int32 error) {
|
||||
if(!Runtime.IsUsingMonoRuntime) {
|
||||
return StrError(error);
|
||||
}
|
||||
|
||||
try {
|
||||
StringBuilder buffer = new StringBuilder(256);
|
||||
Int32 result = Strerror(error, buffer, (UInt64)buffer.Capacity);
|
||||
return (result != -1) ? buffer.ToString() : null;
|
||||
} catch(EntryPointNotFoundException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes file permissions on a Unix file system
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(LibCLibrary, EntryPoint = "chmod", SetLastError = true)]
|
||||
public static extern Int32 Chmod(String filename, UInt32 mode);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a string to a 32 bit integer. Use endpointer as IntPtr.Zero
|
||||
/// </summary>
|
||||
/// <param name="numberString">The number string.</param>
|
||||
/// <param name="endPointer">The end pointer.</param>
|
||||
/// <param name="numberBase">The number base.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(LibCLibrary, EntryPoint = "strtol", SetLastError = true)]
|
||||
public static extern Int32 StringToInteger(String numberString, IntPtr endPointer, Int32 numberBase);
|
||||
|
||||
/// <summary>
|
||||
/// The write() function attempts to write nbytes from buffer to the file associated with handle. On text files, it expands each LF to a CR/LF.
|
||||
/// The function returns the number of bytes written to the file. A return value of -1 indicates an error, with errno set appropriately.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="buffer">The buffer.</param>
|
||||
/// <param name="count">The count.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(LibCLibrary, EntryPoint = "write", SetLastError = true)]
|
||||
public static extern Int32 Write(Int32 fd, Byte[] buffer, Int32 count);
|
||||
|
||||
/// <summary>
|
||||
/// Fills in the structure with information about the system.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(LibCLibrary, EntryPoint = "uname", SetLastError = true)]
|
||||
public static extern Int32 Uname(out SystemName name);
|
||||
|
||||
[DllImport(LibCLibrary, EntryPoint = "strerror", SetLastError = true)]
|
||||
private static extern String StrError(Int32 errnum);
|
||||
|
||||
[DllImport("MonoPosixHelper", EntryPoint = "Mono_Posix_Syscall_strerror_r", SetLastError = true)]
|
||||
private static extern Int32 Strerror(Int32 error, [Out] StringBuilder buffer, UInt64 length);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,47 +1,46 @@
|
||||
namespace Unosquare.RaspberryIO.Native
|
||||
{
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
/// <summary>
|
||||
/// OS uname structure
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
internal struct SystemName {
|
||||
/// <summary>
|
||||
/// OS uname structure
|
||||
/// System name
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
internal struct SystemName
|
||||
{
|
||||
/// <summary>
|
||||
/// System name
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
|
||||
public string SysName;
|
||||
|
||||
/// <summary>
|
||||
/// Node name
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
|
||||
public string NodeName;
|
||||
|
||||
/// <summary>
|
||||
/// Release level
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
|
||||
public string Release;
|
||||
|
||||
/// <summary>
|
||||
/// Version level
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
|
||||
public string Version;
|
||||
|
||||
/// <summary>
|
||||
/// Hardware level
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
|
||||
public string Machine;
|
||||
|
||||
/// <summary>
|
||||
/// Domain name
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
|
||||
public string DomainName;
|
||||
}
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
|
||||
public String SysName;
|
||||
|
||||
/// <summary>
|
||||
/// Node name
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
|
||||
public String NodeName;
|
||||
|
||||
/// <summary>
|
||||
/// Release level
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
|
||||
public String Release;
|
||||
|
||||
/// <summary>
|
||||
/// Version level
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
|
||||
public String Version;
|
||||
|
||||
/// <summary>
|
||||
/// Hardware level
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
|
||||
public String Machine;
|
||||
|
||||
/// <summary>
|
||||
/// Domain name
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
|
||||
public String DomainName;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,26 @@
|
||||
namespace Unosquare.RaspberryIO.Native
|
||||
{
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
/// <summary>
|
||||
/// Defines the different threading locking keys
|
||||
/// </summary>
|
||||
public enum ThreadLockKey {
|
||||
/// <summary>
|
||||
/// Defines the different threading locking keys
|
||||
/// The lock 0
|
||||
/// </summary>
|
||||
public enum ThreadLockKey
|
||||
{
|
||||
/// <summary>
|
||||
/// The lock 0
|
||||
/// </summary>
|
||||
Lock0 = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The lock 1
|
||||
/// </summary>
|
||||
Lock1 = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The lock 2
|
||||
/// </summary>
|
||||
Lock2 = 2,
|
||||
|
||||
/// <summary>
|
||||
/// The lock 3
|
||||
/// </summary>
|
||||
Lock3 = 3,
|
||||
}
|
||||
Lock0 = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The lock 1
|
||||
/// </summary>
|
||||
Lock1 = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The lock 2
|
||||
/// </summary>
|
||||
Lock2 = 2,
|
||||
|
||||
/// <summary>
|
||||
/// The lock 3
|
||||
/// </summary>
|
||||
Lock3 = 3,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,108 +1,108 @@
|
||||
namespace Unosquare.RaspberryIO.Native
|
||||
{
|
||||
using Swan;
|
||||
using Swan.Abstractions;
|
||||
using System;
|
||||
|
||||
using Unosquare.Swan;
|
||||
using Unosquare.Swan.Abstractions;
|
||||
using System;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
/// <summary>
|
||||
/// Provides access to timing and threading properties and methods
|
||||
/// </summary>
|
||||
public class Timing : SingletonBase<Timing> {
|
||||
/// <summary>
|
||||
/// Provides access to timing and threading properties and methods
|
||||
/// Prevents a default instance of the <see cref="Timing"/> class from being created.
|
||||
/// </summary>
|
||||
public class Timing : SingletonBase<Timing>
|
||||
{
|
||||
/// <summary>
|
||||
/// Prevents a default instance of the <see cref="Timing"/> class from being created.
|
||||
/// </summary>
|
||||
/// <exception cref="NotSupportedException">Could not initialize the GPIO controller</exception>
|
||||
private Timing()
|
||||
{
|
||||
// placeholder
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This returns a number representing the number of milliseconds since your program
|
||||
/// initialized the GPIO controller.
|
||||
/// It returns an unsigned 32-bit number which wraps after 49 days.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The milliseconds since setup.
|
||||
/// </value>
|
||||
public uint MillisecondsSinceSetup => WiringPi.Millis();
|
||||
|
||||
/// <summary>
|
||||
/// This returns a number representing the number of microseconds since your
|
||||
/// program initialized the GPIO controller
|
||||
/// It returns an unsigned 32-bit number which wraps after approximately 71 minutes.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The microseconds since setup.
|
||||
/// </value>
|
||||
public uint MicrosecondsSinceSetup => WiringPi.Micros();
|
||||
|
||||
/// <summary>
|
||||
/// This causes program execution to pause for at least howLong milliseconds.
|
||||
/// Due to the multi-tasking nature of Linux it could be longer.
|
||||
/// Note that the maximum delay is an unsigned 32-bit integer or approximately 49 days.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
public static void SleepMilliseconds(uint value) => WiringPi.Delay(value);
|
||||
|
||||
/// <summary>
|
||||
/// This causes program execution to pause for at least howLong microseconds.
|
||||
/// Due to the multi-tasking nature of Linux it could be longer.
|
||||
/// Note that the maximum delay is an unsigned 32-bit integer microseconds or approximately 71 minutes.
|
||||
/// Delays under 100 microseconds are timed using a hard-coded loop continually polling the system time,
|
||||
/// Delays over 100 microseconds are done using the system nanosleep() function –
|
||||
/// You may need to consider the implications of very short delays on the overall performance of the system,
|
||||
/// especially if using threads.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
public void SleepMicroseconds(uint value) => WiringPi.DelayMicroseconds(value);
|
||||
|
||||
/// <summary>
|
||||
/// This attempts to shift your program (or thread in a multi-threaded program) to a higher priority and
|
||||
/// enables a real-time scheduling. The priority parameter should be from 0 (the default) to 99 (the maximum).
|
||||
/// This won’t make your program go any faster, but it will give it a bigger slice of time when other programs
|
||||
/// are running. The priority parameter works relative to others – so you can make one program priority 1 and
|
||||
/// another priority 2 and it will have the same effect as setting one to 10 and the other to 90
|
||||
/// (as long as no other programs are running with elevated priorities)
|
||||
/// </summary>
|
||||
/// <param name="priority">The priority.</param>
|
||||
public void SetThreadPriority(int priority)
|
||||
{
|
||||
priority = priority.Clamp(0, 99);
|
||||
var result = WiringPi.PiHiPri(priority);
|
||||
if (result < 0) HardwareException.Throw(nameof(Timing), nameof(SetThreadPriority));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is really nothing more than a simplified interface to the Posix threads mechanism that Linux supports.
|
||||
/// See the manual pages on Posix threads (man pthread) if you need more control over them.
|
||||
/// </summary>
|
||||
/// <param name="worker">The worker.</param>
|
||||
/// <exception cref="ArgumentNullException">worker</exception>
|
||||
public void CreateThread(ThreadWorker worker)
|
||||
{
|
||||
if (worker == null)
|
||||
throw new ArgumentNullException(nameof(worker));
|
||||
|
||||
var result = WiringPi.PiThreadCreate(worker);
|
||||
if (result != 0) HardwareException.Throw(nameof(Timing), nameof(CreateThread));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// These allow you to synchronize variable updates from your main program to any threads running in your program.
|
||||
/// keyNum is a number from 0 to 3 and represents a “key”. When another process tries to lock the same key,
|
||||
/// it will be stalled until the first process has unlocked the same key.
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
public void Lock(ThreadLockKey key) => WiringPi.PiLock((int)key);
|
||||
|
||||
/// <summary>
|
||||
/// These allow you to synchronize variable updates from your main program to any threads running in your program.
|
||||
/// keyNum is a number from 0 to 3 and represents a “key”. When another process tries to lock the same key,
|
||||
/// it will be stalled until the first process has unlocked the same key.
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
public void Unlock(ThreadLockKey key) => WiringPi.PiUnlock((int)key);
|
||||
}
|
||||
/// <exception cref="NotSupportedException">Could not initialize the GPIO controller</exception>
|
||||
private Timing() {
|
||||
// placeholder
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This returns a number representing the number of milliseconds since your program
|
||||
/// initialized the GPIO controller.
|
||||
/// It returns an unsigned 32-bit number which wraps after 49 days.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The milliseconds since setup.
|
||||
/// </value>
|
||||
public UInt32 MillisecondsSinceSetup => WiringPi.Millis();
|
||||
|
||||
/// <summary>
|
||||
/// This returns a number representing the number of microseconds since your
|
||||
/// program initialized the GPIO controller
|
||||
/// It returns an unsigned 32-bit number which wraps after approximately 71 minutes.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The microseconds since setup.
|
||||
/// </value>
|
||||
public UInt32 MicrosecondsSinceSetup => WiringPi.Micros();
|
||||
|
||||
/// <summary>
|
||||
/// This causes program execution to pause for at least howLong milliseconds.
|
||||
/// Due to the multi-tasking nature of Linux it could be longer.
|
||||
/// Note that the maximum delay is an unsigned 32-bit integer or approximately 49 days.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
public static void SleepMilliseconds(UInt32 value) => WiringPi.Delay(value);
|
||||
|
||||
/// <summary>
|
||||
/// This causes program execution to pause for at least howLong microseconds.
|
||||
/// Due to the multi-tasking nature of Linux it could be longer.
|
||||
/// Note that the maximum delay is an unsigned 32-bit integer microseconds or approximately 71 minutes.
|
||||
/// Delays under 100 microseconds are timed using a hard-coded loop continually polling the system time,
|
||||
/// Delays over 100 microseconds are done using the system nanosleep() function –
|
||||
/// You may need to consider the implications of very short delays on the overall performance of the system,
|
||||
/// especially if using threads.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
public void SleepMicroseconds(UInt32 value) => WiringPi.DelayMicroseconds(value);
|
||||
|
||||
/// <summary>
|
||||
/// This attempts to shift your program (or thread in a multi-threaded program) to a higher priority and
|
||||
/// enables a real-time scheduling. The priority parameter should be from 0 (the default) to 99 (the maximum).
|
||||
/// This won’t make your program go any faster, but it will give it a bigger slice of time when other programs
|
||||
/// are running. The priority parameter works relative to others – so you can make one program priority 1 and
|
||||
/// another priority 2 and it will have the same effect as setting one to 10 and the other to 90
|
||||
/// (as long as no other programs are running with elevated priorities)
|
||||
/// </summary>
|
||||
/// <param name="priority">The priority.</param>
|
||||
public void SetThreadPriority(Int32 priority) {
|
||||
priority = priority.Clamp(0, 99);
|
||||
Int32 result = WiringPi.PiHiPri(priority);
|
||||
if(result < 0) {
|
||||
HardwareException.Throw(nameof(Timing), nameof(SetThreadPriority));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is really nothing more than a simplified interface to the Posix threads mechanism that Linux supports.
|
||||
/// See the manual pages on Posix threads (man pthread) if you need more control over them.
|
||||
/// </summary>
|
||||
/// <param name="worker">The worker.</param>
|
||||
/// <exception cref="ArgumentNullException">worker</exception>
|
||||
public void CreateThread(ThreadWorker worker) {
|
||||
if(worker == null) {
|
||||
throw new ArgumentNullException(nameof(worker));
|
||||
}
|
||||
|
||||
Int32 result = WiringPi.PiThreadCreate(worker);
|
||||
if(result != 0) {
|
||||
HardwareException.Throw(nameof(Timing), nameof(CreateThread));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// These allow you to synchronize variable updates from your main program to any threads running in your program.
|
||||
/// keyNum is a number from 0 to 3 and represents a “key”. When another process tries to lock the same key,
|
||||
/// it will be stalled until the first process has unlocked the same key.
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
public void Lock(ThreadLockKey key) => WiringPi.PiLock((Int32)key);
|
||||
|
||||
/// <summary>
|
||||
/// These allow you to synchronize variable updates from your main program to any threads running in your program.
|
||||
/// keyNum is a number from 0 to 3 and represents a “key”. When another process tries to lock the same key,
|
||||
/// it will be stalled until the first process has unlocked the same key.
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
public void Unlock(ThreadLockKey key) => WiringPi.PiUnlock((Int32)key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,79 +1,78 @@
|
||||
namespace Unosquare.RaspberryIO.Native
|
||||
{
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public partial class WiringPi
|
||||
{
|
||||
#region WiringPi - I2C Library Calls
|
||||
|
||||
/// <summary>
|
||||
/// Simple device read. Some devices present data when you read them without having to do any register transactions.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CRead", SetLastError = true)]
|
||||
public static extern int WiringPiI2CRead(int fd);
|
||||
|
||||
/// <summary>
|
||||
/// These read an 8-bit value from the device register indicated.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="reg">The reg.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CReadReg8", SetLastError = true)]
|
||||
public static extern int WiringPiI2CReadReg8(int fd, int reg);
|
||||
|
||||
/// <summary>
|
||||
/// These read a 16-bit value from the device register indicated.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="reg">The reg.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CReadReg16", SetLastError = true)]
|
||||
public static extern int WiringPiI2CReadReg16(int fd, int reg);
|
||||
|
||||
/// <summary>
|
||||
/// Simple device write. Some devices accept data this way without needing to access any internal registers.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CWrite", SetLastError = true)]
|
||||
public static extern int WiringPiI2CWrite(int fd, int data);
|
||||
|
||||
/// <summary>
|
||||
/// These write an 8-bit data value into the device register indicated.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="reg">The reg.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CWriteReg8", SetLastError = true)]
|
||||
public static extern int WiringPiI2CWriteReg8(int fd, int reg, int data);
|
||||
|
||||
/// <summary>
|
||||
/// These write a 16-bit data value into the device register indicated.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="reg">The reg.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CWriteReg16", SetLastError = true)]
|
||||
public static extern int WiringPiI2CWriteReg16(int fd, int reg, int data);
|
||||
|
||||
/// <summary>
|
||||
/// This initialises the I2C system with your given device identifier.
|
||||
/// The ID is the I2C number of the device and you can use the i2cdetect program to find this out. wiringPiI2CSetup()
|
||||
/// will work out which revision Raspberry Pi you have and open the appropriate device in /dev.
|
||||
/// The return value is the standard Linux filehandle, or -1 if any error – in which case, you can consult errno as usual.
|
||||
/// E.g. the popular MCP23017 GPIO expander is usually device Id 0x20, so this is the number you would pass into wiringPiI2CSetup().
|
||||
/// </summary>
|
||||
/// <param name="devId">The dev identifier.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CSetup", SetLastError = true)]
|
||||
public static extern int WiringPiI2CSetup(int devId);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
public partial class WiringPi {
|
||||
#region WiringPi - I2C Library Calls
|
||||
|
||||
/// <summary>
|
||||
/// Simple device read. Some devices present data when you read them without having to do any register transactions.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CRead", SetLastError = true)]
|
||||
public static extern Int32 WiringPiI2CRead(Int32 fd);
|
||||
|
||||
/// <summary>
|
||||
/// These read an 8-bit value from the device register indicated.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="reg">The reg.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CReadReg8", SetLastError = true)]
|
||||
public static extern Int32 WiringPiI2CReadReg8(Int32 fd, Int32 reg);
|
||||
|
||||
/// <summary>
|
||||
/// These read a 16-bit value from the device register indicated.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="reg">The reg.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CReadReg16", SetLastError = true)]
|
||||
public static extern Int32 WiringPiI2CReadReg16(Int32 fd, Int32 reg);
|
||||
|
||||
/// <summary>
|
||||
/// Simple device write. Some devices accept data this way without needing to access any internal registers.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CWrite", SetLastError = true)]
|
||||
public static extern Int32 WiringPiI2CWrite(Int32 fd, Int32 data);
|
||||
|
||||
/// <summary>
|
||||
/// These write an 8-bit data value into the device register indicated.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="reg">The reg.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CWriteReg8", SetLastError = true)]
|
||||
public static extern Int32 WiringPiI2CWriteReg8(Int32 fd, Int32 reg, Int32 data);
|
||||
|
||||
/// <summary>
|
||||
/// These write a 16-bit data value into the device register indicated.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="reg">The reg.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CWriteReg16", SetLastError = true)]
|
||||
public static extern Int32 WiringPiI2CWriteReg16(Int32 fd, Int32 reg, Int32 data);
|
||||
|
||||
/// <summary>
|
||||
/// This initialises the I2C system with your given device identifier.
|
||||
/// The ID is the I2C number of the device and you can use the i2cdetect program to find this out. wiringPiI2CSetup()
|
||||
/// will work out which revision Raspberry Pi you have and open the appropriate device in /dev.
|
||||
/// The return value is the standard Linux filehandle, or -1 if any error – in which case, you can consult errno as usual.
|
||||
/// E.g. the popular MCP23017 GPIO expander is usually device Id 0x20, so this is the number you would pass into wiringPiI2CSetup().
|
||||
/// </summary>
|
||||
/// <param name="devId">The dev identifier.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CSetup", SetLastError = true)]
|
||||
public static extern Int32 WiringPiI2CSetup(Int32 devId);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,73 +1,72 @@
|
||||
namespace Unosquare.RaspberryIO.Native
|
||||
{
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public partial class WiringPi
|
||||
{
|
||||
#region WiringPi - Serial Port
|
||||
|
||||
/// <summary>
|
||||
/// This opens and initialises the serial device and sets the baud rate. It sets the port into “raw” mode (character at a time and no translations),
|
||||
/// and sets the read timeout to 10 seconds. The return value is the file descriptor or -1 for any error, in which case errno will be set as appropriate.
|
||||
/// The wiringSerial library is intended to provide simplified control – suitable for most applications, however if you need advanced control
|
||||
/// – e.g. parity control, modem control lines (via a USB adapter, there are none on the Pi’s on-board UART!) and so on,
|
||||
/// then you need to do some of this the old fashioned way.
|
||||
/// </summary>
|
||||
/// <param name="device">The device.</param>
|
||||
/// <param name="baud">The baud.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialOpen", SetLastError = true)]
|
||||
public static extern int SerialOpen(string device, int baud);
|
||||
|
||||
/// <summary>
|
||||
/// Closes the device identified by the file descriptor given.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialClose", SetLastError = true)]
|
||||
public static extern int SerialClose(int fd);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the single byte to the serial device identified by the given file descriptor.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="c">The c.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialPutchar", SetLastError = true)]
|
||||
public static extern void SerialPutchar(int fd, byte c);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the nul-terminated string to the serial device identified by the given file descriptor.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="s">The s.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialPuts", SetLastError = true)]
|
||||
public static extern void SerialPuts(int fd, string s);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of characters available for reading, or -1 for any error condition,
|
||||
/// in which case errno will be set appropriately.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialDataAvail", SetLastError = true)]
|
||||
public static extern int SerialDataAvail(int fd);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the next character available on the serial device.
|
||||
/// This call will block for up to 10 seconds if no data is available (when it will return -1)
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialGetchar", SetLastError = true)]
|
||||
public static extern int SerialGetchar(int fd);
|
||||
|
||||
/// <summary>
|
||||
/// This discards all data received, or waiting to be send down the given device.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialFlush", SetLastError = true)]
|
||||
public static extern void SerialFlush(int fd);
|
||||
|
||||
#endregion
|
||||
}
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
public partial class WiringPi {
|
||||
#region WiringPi - Serial Port
|
||||
|
||||
/// <summary>
|
||||
/// This opens and initialises the serial device and sets the baud rate. It sets the port into “raw” mode (character at a time and no translations),
|
||||
/// and sets the read timeout to 10 seconds. The return value is the file descriptor or -1 for any error, in which case errno will be set as appropriate.
|
||||
/// The wiringSerial library is intended to provide simplified control – suitable for most applications, however if you need advanced control
|
||||
/// – e.g. parity control, modem control lines (via a USB adapter, there are none on the Pi’s on-board UART!) and so on,
|
||||
/// then you need to do some of this the old fashioned way.
|
||||
/// </summary>
|
||||
/// <param name="device">The device.</param>
|
||||
/// <param name="baud">The baud.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialOpen", SetLastError = true)]
|
||||
public static extern Int32 SerialOpen(String device, Int32 baud);
|
||||
|
||||
/// <summary>
|
||||
/// Closes the device identified by the file descriptor given.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialClose", SetLastError = true)]
|
||||
public static extern Int32 SerialClose(Int32 fd);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the single byte to the serial device identified by the given file descriptor.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="c">The c.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialPutchar", SetLastError = true)]
|
||||
public static extern void SerialPutchar(Int32 fd, Byte c);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the nul-terminated string to the serial device identified by the given file descriptor.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <param name="s">The s.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialPuts", SetLastError = true)]
|
||||
public static extern void SerialPuts(Int32 fd, String s);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of characters available for reading, or -1 for any error condition,
|
||||
/// in which case errno will be set appropriately.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialDataAvail", SetLastError = true)]
|
||||
public static extern Int32 SerialDataAvail(Int32 fd);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the next character available on the serial device.
|
||||
/// This call will block for up to 10 seconds if no data is available (when it will return -1)
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialGetchar", SetLastError = true)]
|
||||
public static extern Int32 SerialGetchar(Int32 fd);
|
||||
|
||||
/// <summary>
|
||||
/// This discards all data received, or waiting to be send down the given device.
|
||||
/// </summary>
|
||||
/// <param name="fd">The fd.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "serialFlush", SetLastError = true)]
|
||||
public static extern void SerialFlush(Int32 fd);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,35 @@
|
||||
namespace Unosquare.RaspberryIO.Native
|
||||
{
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public partial class WiringPi
|
||||
{
|
||||
#region WiringPi - Shift Library
|
||||
|
||||
/// <summary>
|
||||
/// This shifts an 8-bit data value in with the data appearing on the dPin and the clock being sent out on the cPin.
|
||||
/// Order is either LSBFIRST or MSBFIRST. The data is sampled after the cPin goes high.
|
||||
/// (So cPin high, sample data, cPin low, repeat for 8 bits) The 8-bit value is returned by the function.
|
||||
/// </summary>
|
||||
/// <param name="dPin">The d pin.</param>
|
||||
/// <param name="cPin">The c pin.</param>
|
||||
/// <param name="order">The order.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "shiftIn", SetLastError = true)]
|
||||
public static extern byte ShiftIn(byte dPin, byte cPin, byte order);
|
||||
|
||||
/// <summary>
|
||||
/// The shifts an 8-bit data value val out with the data being sent out on dPin and the clock being sent out on the cPin.
|
||||
/// order is as above. Data is clocked out on the rising or falling edge – ie. dPin is set, then cPin is taken high then low
|
||||
/// – repeated for the 8 bits.
|
||||
/// </summary>
|
||||
/// <param name="dPin">The d pin.</param>
|
||||
/// <param name="cPin">The c pin.</param>
|
||||
/// <param name="order">The order.</param>
|
||||
/// <param name="val">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "shiftOut", SetLastError = true)]
|
||||
public static extern void ShiftOut(byte dPin, byte cPin, byte order, byte val);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
public partial class WiringPi {
|
||||
#region WiringPi - Shift Library
|
||||
|
||||
/// <summary>
|
||||
/// This shifts an 8-bit data value in with the data appearing on the dPin and the clock being sent out on the cPin.
|
||||
/// Order is either LSBFIRST or MSBFIRST. The data is sampled after the cPin goes high.
|
||||
/// (So cPin high, sample data, cPin low, repeat for 8 bits) The 8-bit value is returned by the function.
|
||||
/// </summary>
|
||||
/// <param name="dPin">The d pin.</param>
|
||||
/// <param name="cPin">The c pin.</param>
|
||||
/// <param name="order">The order.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "shiftIn", SetLastError = true)]
|
||||
public static extern Byte ShiftIn(Byte dPin, Byte cPin, Byte order);
|
||||
|
||||
/// <summary>
|
||||
/// The shifts an 8-bit data value val out with the data being sent out on dPin and the clock being sent out on the cPin.
|
||||
/// order is as above. Data is clocked out on the rising or falling edge – ie. dPin is set, then cPin is taken high then low
|
||||
/// – repeated for the 8 bits.
|
||||
/// </summary>
|
||||
/// <param name="dPin">The d pin.</param>
|
||||
/// <param name="cPin">The c pin.</param>
|
||||
/// <param name="order">The order.</param>
|
||||
/// <param name="val">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "shiftOut", SetLastError = true)]
|
||||
public static extern void ShiftOut(Byte dPin, Byte cPin, Byte order, Byte val);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +1,63 @@
|
||||
namespace Unosquare.RaspberryIO.Native
|
||||
{
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public partial class WiringPi
|
||||
{
|
||||
#region WiringPi - Soft PWM (https://github.com/WiringPi/WiringPi/blob/master/wiringPi/softPwm.h)
|
||||
|
||||
/// <summary>
|
||||
/// This creates a software controlled PWM pin. You can use any GPIO pin and the pin numbering will be that of the wiringPiSetup()
|
||||
/// function you used. Use 100 for the pwmRange, then the value can be anything from 0 (off) to 100 (fully on) for the given pin.
|
||||
/// The return value is 0 for success. Anything else and you should check the global errno variable to see what went wrong.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="initialValue">The initial value.</param>
|
||||
/// <param name="pwmRange">The PWM range.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "softPwmCreate", SetLastError = true)]
|
||||
public static extern int SoftPwmCreate(int pin, int initialValue, int pwmRange);
|
||||
|
||||
/// <summary>
|
||||
/// This updates the PWM value on the given pin. The value is checked to be in-range and pins that haven’t previously
|
||||
/// been initialized via softPwmCreate will be silently ignored.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "softPwmWrite", SetLastError = true)]
|
||||
public static extern void SoftPwmWrite(int pin, int value);
|
||||
|
||||
/// <summary>
|
||||
/// This function is undocumented
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "softPwmStop", SetLastError = true)]
|
||||
public static extern void SoftPwmStop(int pin);
|
||||
|
||||
/// <summary>
|
||||
/// This creates a software controlled tone pin. You can use any GPIO pin and the pin numbering will be that of the wiringPiSetup() function you used.
|
||||
/// The return value is 0 for success. Anything else and you should check the global errno variable to see what went wrong.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "softToneCreate", SetLastError = true)]
|
||||
public static extern int SoftToneCreate(int pin);
|
||||
|
||||
/// <summary>
|
||||
/// This function is undocumented
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "softToneStop", SetLastError = true)]
|
||||
public static extern void SoftToneStop(int pin);
|
||||
|
||||
/// <summary>
|
||||
/// This updates the tone frequency value on the given pin. The tone will be played until you set the frequency to 0.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="freq">The freq.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "softToneWrite", SetLastError = true)]
|
||||
public static extern void SoftToneWrite(int pin, int freq);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
public partial class WiringPi {
|
||||
#region WiringPi - Soft PWM (https://github.com/WiringPi/WiringPi/blob/master/wiringPi/softPwm.h)
|
||||
|
||||
/// <summary>
|
||||
/// This creates a software controlled PWM pin. You can use any GPIO pin and the pin numbering will be that of the wiringPiSetup()
|
||||
/// function you used. Use 100 for the pwmRange, then the value can be anything from 0 (off) to 100 (fully on) for the given pin.
|
||||
/// The return value is 0 for success. Anything else and you should check the global errno variable to see what went wrong.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="initialValue">The initial value.</param>
|
||||
/// <param name="pwmRange">The PWM range.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "softPwmCreate", SetLastError = true)]
|
||||
public static extern Int32 SoftPwmCreate(Int32 pin, Int32 initialValue, Int32 pwmRange);
|
||||
|
||||
/// <summary>
|
||||
/// This updates the PWM value on the given pin. The value is checked to be in-range and pins that haven’t previously
|
||||
/// been initialized via softPwmCreate will be silently ignored.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "softPwmWrite", SetLastError = true)]
|
||||
public static extern void SoftPwmWrite(Int32 pin, Int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// This function is undocumented
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "softPwmStop", SetLastError = true)]
|
||||
public static extern void SoftPwmStop(Int32 pin);
|
||||
|
||||
/// <summary>
|
||||
/// This creates a software controlled tone pin. You can use any GPIO pin and the pin numbering will be that of the wiringPiSetup() function you used.
|
||||
/// The return value is 0 for success. Anything else and you should check the global errno variable to see what went wrong.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "softToneCreate", SetLastError = true)]
|
||||
public static extern Int32 SoftToneCreate(Int32 pin);
|
||||
|
||||
/// <summary>
|
||||
/// This function is undocumented
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "softToneStop", SetLastError = true)]
|
||||
public static extern void SoftToneStop(Int32 pin);
|
||||
|
||||
/// <summary>
|
||||
/// This updates the tone frequency value on the given pin. The tone will be played until you set the frequency to 0.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="freq">The freq.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "softToneWrite", SetLastError = true)]
|
||||
public static extern void SoftToneWrite(Int32 pin, Int32 freq);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,52 @@
|
||||
namespace Unosquare.RaspberryIO.Native
|
||||
{
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public partial class WiringPi
|
||||
{
|
||||
#region WiringPi - SPI Library Calls
|
||||
|
||||
/// <summary>
|
||||
/// This function is undocumented
|
||||
/// </summary>
|
||||
/// <param name="channel">The channel.</param>
|
||||
/// <returns>Unknown</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSPIGetFd", SetLastError = true)]
|
||||
public static extern int WiringPiSPIGetFd(int channel);
|
||||
|
||||
/// <summary>
|
||||
/// This performs a simultaneous write/read transaction over the selected SPI bus. Data that was in your buffer is overwritten by data returned from the SPI bus.
|
||||
/// That’s all there is in the helper library. It is possible to do simple read and writes over the SPI bus using the standard read() and write() system calls though –
|
||||
/// write() may be better to use for sending data to chains of shift registers, or those LED strings where you send RGB triplets of data.
|
||||
/// Devices such as A/D and D/A converters usually need to perform a concurrent write/read transaction to work.
|
||||
/// </summary>
|
||||
/// <param name="channel">The channel.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
/// <param name="len">The length.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSPIDataRW", SetLastError = true)]
|
||||
public static extern int WiringPiSPIDataRW(int channel, byte[] data, int len);
|
||||
|
||||
/// <summary>
|
||||
/// This function is undocumented
|
||||
/// </summary>
|
||||
/// <param name="channel">The channel.</param>
|
||||
/// <param name="speed">The speed.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
/// <returns>Unkown</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSPISetupMode", SetLastError = true)]
|
||||
public static extern int WiringPiSPISetupMode(int channel, int speed, int mode);
|
||||
|
||||
/// <summary>
|
||||
/// This is the way to initialize a channel (The Pi has 2 channels; 0 and 1). The speed parameter is an integer
|
||||
/// in the range 500,000 through 32,000,000 and represents the SPI clock speed in Hz.
|
||||
/// The returned value is the Linux file-descriptor for the device, or -1 on error. If an error has happened, you may use the standard errno global variable to see why.
|
||||
/// </summary>
|
||||
/// <param name="channel">The channel.</param>
|
||||
/// <param name="speed">The speed.</param>
|
||||
/// <returns>The Linux file descriptor for the device or -1 for error</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSPISetup", SetLastError = true)]
|
||||
public static extern int WiringPiSPISetup(int channel, int speed);
|
||||
|
||||
#endregion
|
||||
}
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
public partial class WiringPi {
|
||||
#region WiringPi - SPI Library Calls
|
||||
|
||||
/// <summary>
|
||||
/// This function is undocumented
|
||||
/// </summary>
|
||||
/// <param name="channel">The channel.</param>
|
||||
/// <returns>Unknown</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSPIGetFd", SetLastError = true)]
|
||||
public static extern Int32 WiringPiSPIGetFd(Int32 channel);
|
||||
|
||||
/// <summary>
|
||||
/// This performs a simultaneous write/read transaction over the selected SPI bus. Data that was in your buffer is overwritten by data returned from the SPI bus.
|
||||
/// That’s all there is in the helper library. It is possible to do simple read and writes over the SPI bus using the standard read() and write() system calls though –
|
||||
/// write() may be better to use for sending data to chains of shift registers, or those LED strings where you send RGB triplets of data.
|
||||
/// Devices such as A/D and D/A converters usually need to perform a concurrent write/read transaction to work.
|
||||
/// </summary>
|
||||
/// <param name="channel">The channel.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
/// <param name="len">The length.</param>
|
||||
/// <returns>The result</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSPIDataRW", SetLastError = true)]
|
||||
public static extern Int32 WiringPiSPIDataRW(Int32 channel, Byte[] data, Int32 len);
|
||||
|
||||
/// <summary>
|
||||
/// This function is undocumented
|
||||
/// </summary>
|
||||
/// <param name="channel">The channel.</param>
|
||||
/// <param name="speed">The speed.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
/// <returns>Unkown</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSPISetupMode", SetLastError = true)]
|
||||
public static extern Int32 WiringPiSPISetupMode(Int32 channel, Int32 speed, Int32 mode);
|
||||
|
||||
/// <summary>
|
||||
/// This is the way to initialize a channel (The Pi has 2 channels; 0 and 1). The speed parameter is an integer
|
||||
/// in the range 500,000 through 32,000,000 and represents the SPI clock speed in Hz.
|
||||
/// The returned value is the Linux file-descriptor for the device, or -1 on error. If an error has happened, you may use the standard errno global variable to see why.
|
||||
/// </summary>
|
||||
/// <param name="channel">The channel.</param>
|
||||
/// <param name="speed">The speed.</param>
|
||||
/// <returns>The Linux file descriptor for the device or -1 for error</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSPISetup", SetLastError = true)]
|
||||
public static extern Int32 WiringPiSPISetup(Int32 channel, Int32 speed);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,394 +1,392 @@
|
||||
namespace Unosquare.RaspberryIO.Native
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
/// <summary>
|
||||
/// Provides native C WiringPi Library function call wrappers
|
||||
/// All credit for the native library goes to the author of http://wiringpi.com/
|
||||
/// The wrappers were written based on https://github.com/WiringPi/WiringPi/blob/master/wiringPi/wiringPi.h
|
||||
/// </summary>
|
||||
public partial class WiringPi {
|
||||
internal const String WiringPiLibrary = "libwiringPi.so.2.46";
|
||||
|
||||
#region WiringPi - Core Functions (https://github.com/WiringPi/WiringPi/blob/master/wiringPi/wiringPi.h)
|
||||
|
||||
/// <summary>
|
||||
/// Provides native C WiringPi Library function call wrappers
|
||||
/// All credit for the native library goes to the author of http://wiringpi.com/
|
||||
/// The wrappers were written based on https://github.com/WiringPi/WiringPi/blob/master/wiringPi/wiringPi.h
|
||||
/// This initialises wiringPi and assumes that the calling program is going to be using the wiringPi pin numbering scheme.
|
||||
/// This is a simplified numbering scheme which provides a mapping from virtual pin numbers 0 through 16 to the real underlying Broadcom GPIO pin numbers.
|
||||
/// See the pins page for a table which maps the wiringPi pin number to the Broadcom GPIO pin number to the physical location on the edge connector.
|
||||
/// This function needs to be called with root privileges.
|
||||
/// </summary>
|
||||
public partial class WiringPi
|
||||
{
|
||||
internal const string WiringPiLibrary = "libwiringPi.so.2.46";
|
||||
|
||||
#region WiringPi - Core Functions (https://github.com/WiringPi/WiringPi/blob/master/wiringPi/wiringPi.h)
|
||||
|
||||
/// <summary>
|
||||
/// This initialises wiringPi and assumes that the calling program is going to be using the wiringPi pin numbering scheme.
|
||||
/// This is a simplified numbering scheme which provides a mapping from virtual pin numbers 0 through 16 to the real underlying Broadcom GPIO pin numbers.
|
||||
/// See the pins page for a table which maps the wiringPi pin number to the Broadcom GPIO pin number to the physical location on the edge connector.
|
||||
/// This function needs to be called with root privileges.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSetup", SetLastError = true)]
|
||||
public static extern int WiringPiSetup();
|
||||
|
||||
/// <summary>
|
||||
/// This initialises wiringPi but uses the /sys/class/gpio interface rather than accessing the hardware directly.
|
||||
/// This can be called as a non-root user provided the GPIO pins have been exported before-hand using the gpio program.
|
||||
/// Pin numbering in this mode is the native Broadcom GPIO numbers – the same as wiringPiSetupGpio() above,
|
||||
/// so be aware of the differences between Rev 1 and Rev 2 boards.
|
||||
///
|
||||
/// Note: In this mode you can only use the pins which have been exported via the /sys/class/gpio interface before you run your program.
|
||||
/// You can do this in a separate shell-script, or by using the system() function from inside your program to call the gpio program.
|
||||
/// Also note that some functions have no effect when using this mode as they’re not currently possible to action unless called with root privileges.
|
||||
/// (although you can use system() to call gpio to set/change modes if needed)
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSetupSys", SetLastError = true)]
|
||||
public static extern int WiringPiSetupSys();
|
||||
|
||||
/// <summary>
|
||||
/// This is identical to wiringPiSetup, however it allows the calling programs to use the Broadcom GPIO
|
||||
/// pin numbers directly with no re-mapping.
|
||||
/// As above, this function needs to be called with root privileges, and note that some pins are different
|
||||
/// from revision 1 to revision 2 boards.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSetupGpio", SetLastError = true)]
|
||||
public static extern int WiringPiSetupGpio();
|
||||
|
||||
/// <summary>
|
||||
/// Identical to wiringPiSetup, however it allows the calling programs to use the physical pin numbers on the P1 connector only.
|
||||
/// This function needs to be called with root privileges.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSetupPhys", SetLastError = true)]
|
||||
public static extern int WiringPiSetupPhys();
|
||||
|
||||
/// <summary>
|
||||
/// This function is undocumented
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pinModeAlt", SetLastError = true)]
|
||||
public static extern void PinModeAlt(int pin, int mode);
|
||||
|
||||
/// <summary>
|
||||
/// This sets the mode of a pin to either INPUT, OUTPUT, PWM_OUTPUT or GPIO_CLOCK.
|
||||
/// Note that only wiringPi pin 1 (BCM_GPIO 18) supports PWM output and only wiringPi pin 7 (BCM_GPIO 4)
|
||||
/// supports CLOCK output modes.
|
||||
///
|
||||
/// This function has no effect when in Sys mode. If you need to change the pin mode, then you can
|
||||
/// do it with the gpio program in a script before you start your program.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pinMode", SetLastError = true)]
|
||||
public static extern void PinMode(int pin, int mode);
|
||||
|
||||
/// <summary>
|
||||
/// This sets the pull-up or pull-down resistor mode on the given pin, which should be set as an input.
|
||||
/// Unlike the Arduino, the BCM2835 has both pull-up an down internal resistors. The parameter pud should be; PUD_OFF,
|
||||
/// (no pull up/down), PUD_DOWN (pull to ground) or PUD_UP (pull to 3.3v) The internal pull up/down resistors
|
||||
/// have a value of approximately 50KΩ on the Raspberry Pi.
|
||||
///
|
||||
/// This function has no effect on the Raspberry Pi’s GPIO pins when in Sys mode.
|
||||
/// If you need to activate a pull-up/pull-down, then you can do it with the gpio program in a script before you start your program.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="pud">The pud.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pullUpDnControl", SetLastError = true)]
|
||||
public static extern void PullUpDnControl(int pin, int pud);
|
||||
|
||||
/// <summary>
|
||||
/// This function returns the value read at the given pin. It will be HIGH or LOW (1 or 0) depending on the logic level at the pin.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "digitalRead", SetLastError = true)]
|
||||
public static extern int DigitalRead(int pin);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the value HIGH or LOW (1 or 0) to the given pin which must have been previously set as an output.
|
||||
/// WiringPi treats any non-zero number as HIGH, however 0 is the only representation of LOW.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "digitalWrite", SetLastError = true)]
|
||||
public static extern void DigitalWrite(int pin, int value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the value to the PWM register for the given pin. The Raspberry Pi has one
|
||||
/// on-board PWM pin, pin 1 (BMC_GPIO 18, Phys 12) and the range is 0-1024.
|
||||
/// Other PWM devices may have other PWM ranges.
|
||||
/// This function is not able to control the Pi’s on-board PWM when in Sys mode.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pwmWrite", SetLastError = true)]
|
||||
public static extern void PwmWrite(int pin, int value);
|
||||
|
||||
/// <summary>
|
||||
/// This returns the value read on the supplied analog input pin. You will need to
|
||||
/// register additional analog modules to enable this function for devices such as the Gertboard, quick2Wire analog board, etc.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "analogRead", SetLastError = true)]
|
||||
public static extern int AnalogRead(int pin);
|
||||
|
||||
/// <summary>
|
||||
/// This writes the given value to the supplied analog pin. You will need to register additional
|
||||
/// analog modules to enable this function for devices such as the Gertboard.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "analogWrite", SetLastError = true)]
|
||||
public static extern void AnalogWrite(int pin, int value);
|
||||
|
||||
/// <summary>
|
||||
/// This returns the board revision of the Raspberry Pi. It will be either 1 or 2. Some of the BCM_GPIO pins changed number and
|
||||
/// function when moving from board revision 1 to 2, so if you are using BCM_GPIO pin numbers, then you need to be aware of the differences.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "piBoardRev", SetLastError = true)]
|
||||
public static extern int PiBoardRev();
|
||||
|
||||
/// <summary>
|
||||
/// This function is undocumented
|
||||
/// </summary>
|
||||
/// <param name="model">The model.</param>
|
||||
/// <param name="mem">The memory.</param>
|
||||
/// <param name="maker">The maker.</param>
|
||||
/// <param name="overVolted">The over volted.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "piBoardId", SetLastError = true)]
|
||||
public static extern int PiBoardId(ref int model, ref int mem, ref int maker, ref int overVolted);
|
||||
|
||||
/// <summary>
|
||||
/// This returns the BCM_GPIO pin number of the supplied wiringPi pin. It takes the board revision into account.
|
||||
/// </summary>
|
||||
/// <param name="wPiPin">The w pi pin.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wpiPinToGpio", SetLastError = true)]
|
||||
public static extern int WpiPinToGpio(int wPiPin);
|
||||
|
||||
/// <summary>
|
||||
/// This returns the BCM_GPIO pin number of the supplied physical pin on the P1 connector.
|
||||
/// </summary>
|
||||
/// <param name="physPin">The physical pin.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "physPinToGpio", SetLastError = true)]
|
||||
public static extern int PhysPinToGpio(int physPin);
|
||||
|
||||
/// <summary>
|
||||
/// This sets the “strength” of the pad drivers for a particular group of pins.
|
||||
/// There are 3 groups of pins and the drive strength is from 0 to 7. Do not use this unless you know what you are doing.
|
||||
/// </summary>
|
||||
/// <param name="group">The group.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "setPadDrive", SetLastError = true)]
|
||||
public static extern int SetPadDrive(int group, int value);
|
||||
|
||||
/// <summary>
|
||||
/// Undocumented function
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "getAlt", SetLastError = true)]
|
||||
public static extern int GetAlt(int pin);
|
||||
|
||||
/// <summary>
|
||||
/// Undocumented function
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="freq">The freq.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pwmToneWrite", SetLastError = true)]
|
||||
public static extern int PwmToneWrite(int pin, int freq);
|
||||
|
||||
/// <summary>
|
||||
/// This writes the 8-bit byte supplied to the first 8 GPIO pins.
|
||||
/// It’s the fastest way to set all 8 bits at once to a particular value, although it still takes two write operations to the Pi’s GPIO hardware.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "digitalWriteByte", SetLastError = true)]
|
||||
public static extern void DigitalWriteByte(int value);
|
||||
|
||||
/// <summary>
|
||||
/// This writes the 8-bit byte supplied to the first 8 GPIO pins.
|
||||
/// It’s the fastest way to set all 8 bits at once to a particular value, although it still takes two write operations to the Pi’s GPIO hardware.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "digitalWriteByte2", SetLastError = true)]
|
||||
public static extern void DigitalWriteByte2(int value);
|
||||
|
||||
/// <summary>
|
||||
/// Undocumented function
|
||||
/// This reads the 8-bit byte supplied to the first 8 GPIO pins.
|
||||
/// It’s the fastest way to get all 8 bits at once to a particular value.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "digitalReadByte", SetLastError = true)]
|
||||
public static extern uint DigitalReadByte();
|
||||
|
||||
/// <summary>
|
||||
/// Undocumented function
|
||||
/// This reads the 8-bit byte supplied to the first 8 GPIO pins.
|
||||
/// It’s the fastest way to get all 8 bits at once to a particular value.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "digitalReadByte2", SetLastError = true)]
|
||||
public static extern uint DigitalReadByte2();
|
||||
|
||||
/// <summary>
|
||||
/// The PWM generator can run in 2 modes – “balanced” and “mark:space”. The mark:space mode is traditional,
|
||||
/// however the default mode in the Pi is “balanced”. You can switch modes by supplying the parameter: PWM_MODE_BAL or PWM_MODE_MS.
|
||||
/// </summary>
|
||||
/// <param name="mode">The mode.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pwmSetMode", SetLastError = true)]
|
||||
public static extern void PwmSetMode(int mode);
|
||||
|
||||
/// <summary>
|
||||
/// This sets the range register in the PWM generator. The default is 1024.
|
||||
/// </summary>
|
||||
/// <param name="range">The range.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pwmSetRange", SetLastError = true)]
|
||||
public static extern void PwmSetRange(uint range);
|
||||
|
||||
/// <summary>
|
||||
/// This sets the divisor for the PWM clock.
|
||||
/// Note: The PWM control functions can not be used when in Sys mode.
|
||||
/// To understand more about the PWM system, you’ll need to read the Broadcom ARM peripherals manual.
|
||||
/// </summary>
|
||||
/// <param name="divisor">The divisor.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pwmSetClock", SetLastError = true)]
|
||||
public static extern void PwmSetClock(int divisor);
|
||||
|
||||
/// <summary>
|
||||
/// Undocumented function
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="freq">The freq.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "gpioClockSet", SetLastError = true)]
|
||||
public static extern void GpioClockSet(int pin, int freq);
|
||||
|
||||
/// <summary>
|
||||
/// Note: Jan 2013: The waitForInterrupt() function is deprecated – you should use the newer and easier to use wiringPiISR() function below.
|
||||
/// When called, it will wait for an interrupt event to happen on that pin and your program will be stalled. The timeOut parameter is given in milliseconds,
|
||||
/// or can be -1 which means to wait forever.
|
||||
/// The return value is -1 if an error occurred (and errno will be set appropriately), 0 if it timed out, or 1 on a successful interrupt event.
|
||||
/// Before you call waitForInterrupt, you must first initialise the GPIO pin and at present the only way to do this is to use the gpio program, either
|
||||
/// in a script, or using the system() call from inside your program.
|
||||
/// e.g. We want to wait for a falling-edge interrupt on GPIO pin 0, so to setup the hardware, we need to run: gpio edge 0 falling
|
||||
/// before running the program.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="timeout">The timeout.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[Obsolete]
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "waitForInterrupt", SetLastError = true)]
|
||||
public static extern int WaitForInterrupt(int pin, int timeout);
|
||||
|
||||
/// <summary>
|
||||
/// This function registers a function to received interrupts on the specified pin.
|
||||
/// The edgeType parameter is either INT_EDGE_FALLING, INT_EDGE_RISING, INT_EDGE_BOTH or INT_EDGE_SETUP.
|
||||
/// If it is INT_EDGE_SETUP then no initialisation of the pin will happen – it’s assumed that you have already setup the pin elsewhere
|
||||
/// (e.g. with the gpio program), but if you specify one of the other types, then the pin will be exported and initialised as specified.
|
||||
/// This is accomplished via a suitable call to the gpio utility program, so it need to be available.
|
||||
/// The pin number is supplied in the current mode – native wiringPi, BCM_GPIO, physical or Sys modes.
|
||||
/// This function will work in any mode, and does not need root privileges to work.
|
||||
/// The function will be called when the interrupt triggers. When it is triggered, it’s cleared in the dispatcher before calling your function,
|
||||
/// so if a subsequent interrupt fires before you finish your handler, then it won’t be missed. (However it can only track one more interrupt,
|
||||
/// if more than one interrupt fires while one is being handled then they will be ignored)
|
||||
/// This function is run at a high priority (if the program is run using sudo, or as root) and executes concurrently with the main program.
|
||||
/// It has full access to all the global variables, open file handles and so on.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
/// <param name="method">The method.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiISR", SetLastError = true)]
|
||||
public static extern int WiringPiISR(int pin, int mode, InterruptServiceRoutineCallback method);
|
||||
|
||||
/// <summary>
|
||||
/// This function creates a thread which is another function in your program previously declared using the PI_THREAD declaration.
|
||||
/// This function is then run concurrently with your main program. An example may be to have this function wait for an interrupt while
|
||||
/// your program carries on doing other tasks. The thread can indicate an event, or action by using global variables to
|
||||
/// communicate back to the main program, or other threads.
|
||||
/// </summary>
|
||||
/// <param name="method">The method.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "piThreadCreate", SetLastError = true)]
|
||||
public static extern int PiThreadCreate(ThreadWorker method);
|
||||
|
||||
/// <summary>
|
||||
/// These allow you to synchronise variable updates from your main program to any threads running in your program. keyNum is a number from 0 to 3 and represents a key.
|
||||
/// When another process tries to lock the same key, it will be stalled until the first process has unlocked the same key.
|
||||
/// You may need to use these functions to ensure that you get valid data when exchanging data between your main program and a thread
|
||||
/// – otherwise it’s possible that the thread could wake-up halfway during your data copy and change the data –
|
||||
/// so the data you end up copying is incomplete, or invalid. See the wfi.c program in the examples directory for an example.
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "piLock", SetLastError = true)]
|
||||
public static extern void PiLock(int key);
|
||||
|
||||
/// <summary>
|
||||
/// These allow you to synchronise variable updates from your main program to any threads running in your program. keyNum is a number from 0 to 3 and represents a key.
|
||||
/// When another process tries to lock the same key, it will be stalled until the first process has unlocked the same key.
|
||||
/// You may need to use these functions to ensure that you get valid data when exchanging data between your main program and a thread
|
||||
/// – otherwise it’s possible that the thread could wake-up halfway during your data copy and change the data –
|
||||
/// so the data you end up copying is incomplete, or invalid. See the wfi.c program in the examples directory for an example.
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "piUnlock", SetLastError = true)]
|
||||
public static extern void PiUnlock(int key);
|
||||
|
||||
/// <summary>
|
||||
/// This attempts to shift your program (or thread in a multi-threaded program) to a higher priority
|
||||
/// and enables a real-time scheduling. The priority parameter should be from 0 (the default) to 99 (the maximum).
|
||||
/// This won’t make your program go any faster, but it will give it a bigger slice of time when other programs are running.
|
||||
/// The priority parameter works relative to others – so you can make one program priority 1 and another priority 2
|
||||
/// and it will have the same effect as setting one to 10 and the other to 90 (as long as no other
|
||||
/// programs are running with elevated priorities)
|
||||
/// The return value is 0 for success and -1 for error. If an error is returned, the program should then consult the errno global variable, as per the usual conventions.
|
||||
/// Note: Only programs running as root can change their priority. If called from a non-root program then nothing happens.
|
||||
/// </summary>
|
||||
/// <param name="priority">The priority.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "piHiPri", SetLastError = true)]
|
||||
public static extern int PiHiPri(int priority);
|
||||
|
||||
/// <summary>
|
||||
/// This causes program execution to pause for at least howLong milliseconds.
|
||||
/// Due to the multi-tasking nature of Linux it could be longer.
|
||||
/// Note that the maximum delay is an unsigned 32-bit integer or approximately 49 days.
|
||||
/// </summary>
|
||||
/// <param name="howLong">The how long.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "delay", SetLastError = true)]
|
||||
public static extern void Delay(uint howLong);
|
||||
|
||||
/// <summary>
|
||||
/// This causes program execution to pause for at least howLong microseconds.
|
||||
/// Due to the multi-tasking nature of Linux it could be longer.
|
||||
/// Note that the maximum delay is an unsigned 32-bit integer microseconds or approximately 71 minutes.
|
||||
/// Delays under 100 microseconds are timed using a hard-coded loop continually polling the system time,
|
||||
/// Delays over 100 microseconds are done using the system nanosleep() function – You may need to consider the implications
|
||||
/// of very short delays on the overall performance of the system, especially if using threads.
|
||||
/// </summary>
|
||||
/// <param name="howLong">The how long.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "delayMicroseconds", SetLastError = true)]
|
||||
public static extern void DelayMicroseconds(uint howLong);
|
||||
|
||||
/// <summary>
|
||||
/// This returns a number representing the number of milliseconds since your program called one of the wiringPiSetup functions.
|
||||
/// It returns an unsigned 32-bit number which wraps after 49 days.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "millis", SetLastError = true)]
|
||||
public static extern uint Millis();
|
||||
|
||||
/// <summary>
|
||||
/// This returns a number representing the number of microseconds since your program called one of
|
||||
/// the wiringPiSetup functions. It returns an unsigned 32-bit number which wraps after approximately 71 minutes.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "micros", SetLastError = true)]
|
||||
public static extern uint Micros();
|
||||
|
||||
#endregion
|
||||
}
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSetup", SetLastError = true)]
|
||||
public static extern Int32 WiringPiSetup();
|
||||
|
||||
/// <summary>
|
||||
/// This initialises wiringPi but uses the /sys/class/gpio interface rather than accessing the hardware directly.
|
||||
/// This can be called as a non-root user provided the GPIO pins have been exported before-hand using the gpio program.
|
||||
/// Pin numbering in this mode is the native Broadcom GPIO numbers – the same as wiringPiSetupGpio() above,
|
||||
/// so be aware of the differences between Rev 1 and Rev 2 boards.
|
||||
///
|
||||
/// Note: In this mode you can only use the pins which have been exported via the /sys/class/gpio interface before you run your program.
|
||||
/// You can do this in a separate shell-script, or by using the system() function from inside your program to call the gpio program.
|
||||
/// Also note that some functions have no effect when using this mode as they’re not currently possible to action unless called with root privileges.
|
||||
/// (although you can use system() to call gpio to set/change modes if needed)
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSetupSys", SetLastError = true)]
|
||||
public static extern Int32 WiringPiSetupSys();
|
||||
|
||||
/// <summary>
|
||||
/// This is identical to wiringPiSetup, however it allows the calling programs to use the Broadcom GPIO
|
||||
/// pin numbers directly with no re-mapping.
|
||||
/// As above, this function needs to be called with root privileges, and note that some pins are different
|
||||
/// from revision 1 to revision 2 boards.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSetupGpio", SetLastError = true)]
|
||||
public static extern Int32 WiringPiSetupGpio();
|
||||
|
||||
/// <summary>
|
||||
/// Identical to wiringPiSetup, however it allows the calling programs to use the physical pin numbers on the P1 connector only.
|
||||
/// This function needs to be called with root privileges.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiSetupPhys", SetLastError = true)]
|
||||
public static extern Int32 WiringPiSetupPhys();
|
||||
|
||||
/// <summary>
|
||||
/// This function is undocumented
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pinModeAlt", SetLastError = true)]
|
||||
public static extern void PinModeAlt(Int32 pin, Int32 mode);
|
||||
|
||||
/// <summary>
|
||||
/// This sets the mode of a pin to either INPUT, OUTPUT, PWM_OUTPUT or GPIO_CLOCK.
|
||||
/// Note that only wiringPi pin 1 (BCM_GPIO 18) supports PWM output and only wiringPi pin 7 (BCM_GPIO 4)
|
||||
/// supports CLOCK output modes.
|
||||
///
|
||||
/// This function has no effect when in Sys mode. If you need to change the pin mode, then you can
|
||||
/// do it with the gpio program in a script before you start your program.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pinMode", SetLastError = true)]
|
||||
public static extern void PinMode(Int32 pin, Int32 mode);
|
||||
|
||||
/// <summary>
|
||||
/// This sets the pull-up or pull-down resistor mode on the given pin, which should be set as an input.
|
||||
/// Unlike the Arduino, the BCM2835 has both pull-up an down internal resistors. The parameter pud should be; PUD_OFF,
|
||||
/// (no pull up/down), PUD_DOWN (pull to ground) or PUD_UP (pull to 3.3v) The internal pull up/down resistors
|
||||
/// have a value of approximately 50KΩ on the Raspberry Pi.
|
||||
///
|
||||
/// This function has no effect on the Raspberry Pi’s GPIO pins when in Sys mode.
|
||||
/// If you need to activate a pull-up/pull-down, then you can do it with the gpio program in a script before you start your program.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="pud">The pud.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pullUpDnControl", SetLastError = true)]
|
||||
public static extern void PullUpDnControl(Int32 pin, Int32 pud);
|
||||
|
||||
/// <summary>
|
||||
/// This function returns the value read at the given pin. It will be HIGH or LOW (1 or 0) depending on the logic level at the pin.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "digitalRead", SetLastError = true)]
|
||||
public static extern Int32 DigitalRead(Int32 pin);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the value HIGH or LOW (1 or 0) to the given pin which must have been previously set as an output.
|
||||
/// WiringPi treats any non-zero number as HIGH, however 0 is the only representation of LOW.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "digitalWrite", SetLastError = true)]
|
||||
public static extern void DigitalWrite(Int32 pin, Int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the value to the PWM register for the given pin. The Raspberry Pi has one
|
||||
/// on-board PWM pin, pin 1 (BMC_GPIO 18, Phys 12) and the range is 0-1024.
|
||||
/// Other PWM devices may have other PWM ranges.
|
||||
/// This function is not able to control the Pi’s on-board PWM when in Sys mode.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pwmWrite", SetLastError = true)]
|
||||
public static extern void PwmWrite(Int32 pin, Int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// This returns the value read on the supplied analog input pin. You will need to
|
||||
/// register additional analog modules to enable this function for devices such as the Gertboard, quick2Wire analog board, etc.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "analogRead", SetLastError = true)]
|
||||
public static extern Int32 AnalogRead(Int32 pin);
|
||||
|
||||
/// <summary>
|
||||
/// This writes the given value to the supplied analog pin. You will need to register additional
|
||||
/// analog modules to enable this function for devices such as the Gertboard.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "analogWrite", SetLastError = true)]
|
||||
public static extern void AnalogWrite(Int32 pin, Int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// This returns the board revision of the Raspberry Pi. It will be either 1 or 2. Some of the BCM_GPIO pins changed number and
|
||||
/// function when moving from board revision 1 to 2, so if you are using BCM_GPIO pin numbers, then you need to be aware of the differences.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "piBoardRev", SetLastError = true)]
|
||||
public static extern Int32 PiBoardRev();
|
||||
|
||||
/// <summary>
|
||||
/// This function is undocumented
|
||||
/// </summary>
|
||||
/// <param name="model">The model.</param>
|
||||
/// <param name="mem">The memory.</param>
|
||||
/// <param name="maker">The maker.</param>
|
||||
/// <param name="overVolted">The over volted.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "piBoardId", SetLastError = true)]
|
||||
public static extern Int32 PiBoardId(ref Int32 model, ref Int32 mem, ref Int32 maker, ref Int32 overVolted);
|
||||
|
||||
/// <summary>
|
||||
/// This returns the BCM_GPIO pin number of the supplied wiringPi pin. It takes the board revision into account.
|
||||
/// </summary>
|
||||
/// <param name="wPiPin">The w pi pin.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wpiPinToGpio", SetLastError = true)]
|
||||
public static extern Int32 WpiPinToGpio(Int32 wPiPin);
|
||||
|
||||
/// <summary>
|
||||
/// This returns the BCM_GPIO pin number of the supplied physical pin on the P1 connector.
|
||||
/// </summary>
|
||||
/// <param name="physPin">The physical pin.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "physPinToGpio", SetLastError = true)]
|
||||
public static extern Int32 PhysPinToGpio(Int32 physPin);
|
||||
|
||||
/// <summary>
|
||||
/// This sets the “strength” of the pad drivers for a particular group of pins.
|
||||
/// There are 3 groups of pins and the drive strength is from 0 to 7. Do not use this unless you know what you are doing.
|
||||
/// </summary>
|
||||
/// <param name="group">The group.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "setPadDrive", SetLastError = true)]
|
||||
public static extern Int32 SetPadDrive(Int32 group, Int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// Undocumented function
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "getAlt", SetLastError = true)]
|
||||
public static extern Int32 GetAlt(Int32 pin);
|
||||
|
||||
/// <summary>
|
||||
/// Undocumented function
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="freq">The freq.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pwmToneWrite", SetLastError = true)]
|
||||
public static extern Int32 PwmToneWrite(Int32 pin, Int32 freq);
|
||||
|
||||
/// <summary>
|
||||
/// This writes the 8-bit byte supplied to the first 8 GPIO pins.
|
||||
/// It’s the fastest way to set all 8 bits at once to a particular value, although it still takes two write operations to the Pi’s GPIO hardware.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "digitalWriteByte", SetLastError = true)]
|
||||
public static extern void DigitalWriteByte(Int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// This writes the 8-bit byte supplied to the first 8 GPIO pins.
|
||||
/// It’s the fastest way to set all 8 bits at once to a particular value, although it still takes two write operations to the Pi’s GPIO hardware.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "digitalWriteByte2", SetLastError = true)]
|
||||
public static extern void DigitalWriteByte2(Int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// Undocumented function
|
||||
/// This reads the 8-bit byte supplied to the first 8 GPIO pins.
|
||||
/// It’s the fastest way to get all 8 bits at once to a particular value.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "digitalReadByte", SetLastError = true)]
|
||||
public static extern UInt32 DigitalReadByte();
|
||||
|
||||
/// <summary>
|
||||
/// Undocumented function
|
||||
/// This reads the 8-bit byte supplied to the first 8 GPIO pins.
|
||||
/// It’s the fastest way to get all 8 bits at once to a particular value.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "digitalReadByte2", SetLastError = true)]
|
||||
public static extern UInt32 DigitalReadByte2();
|
||||
|
||||
/// <summary>
|
||||
/// The PWM generator can run in 2 modes – “balanced” and “mark:space”. The mark:space mode is traditional,
|
||||
/// however the default mode in the Pi is “balanced”. You can switch modes by supplying the parameter: PWM_MODE_BAL or PWM_MODE_MS.
|
||||
/// </summary>
|
||||
/// <param name="mode">The mode.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pwmSetMode", SetLastError = true)]
|
||||
public static extern void PwmSetMode(Int32 mode);
|
||||
|
||||
/// <summary>
|
||||
/// This sets the range register in the PWM generator. The default is 1024.
|
||||
/// </summary>
|
||||
/// <param name="range">The range.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pwmSetRange", SetLastError = true)]
|
||||
public static extern void PwmSetRange(UInt32 range);
|
||||
|
||||
/// <summary>
|
||||
/// This sets the divisor for the PWM clock.
|
||||
/// Note: The PWM control functions can not be used when in Sys mode.
|
||||
/// To understand more about the PWM system, you’ll need to read the Broadcom ARM peripherals manual.
|
||||
/// </summary>
|
||||
/// <param name="divisor">The divisor.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "pwmSetClock", SetLastError = true)]
|
||||
public static extern void PwmSetClock(Int32 divisor);
|
||||
|
||||
/// <summary>
|
||||
/// Undocumented function
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="freq">The freq.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "gpioClockSet", SetLastError = true)]
|
||||
public static extern void GpioClockSet(Int32 pin, Int32 freq);
|
||||
|
||||
/// <summary>
|
||||
/// Note: Jan 2013: The waitForInterrupt() function is deprecated – you should use the newer and easier to use wiringPiISR() function below.
|
||||
/// When called, it will wait for an interrupt event to happen on that pin and your program will be stalled. The timeOut parameter is given in milliseconds,
|
||||
/// or can be -1 which means to wait forever.
|
||||
/// The return value is -1 if an error occurred (and errno will be set appropriately), 0 if it timed out, or 1 on a successful interrupt event.
|
||||
/// Before you call waitForInterrupt, you must first initialise the GPIO pin and at present the only way to do this is to use the gpio program, either
|
||||
/// in a script, or using the system() call from inside your program.
|
||||
/// e.g. We want to wait for a falling-edge interrupt on GPIO pin 0, so to setup the hardware, we need to run: gpio edge 0 falling
|
||||
/// before running the program.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="timeout">The timeout.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[Obsolete]
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "waitForInterrupt", SetLastError = true)]
|
||||
public static extern Int32 WaitForInterrupt(Int32 pin, Int32 timeout);
|
||||
|
||||
/// <summary>
|
||||
/// This function registers a function to received interrupts on the specified pin.
|
||||
/// The edgeType parameter is either INT_EDGE_FALLING, INT_EDGE_RISING, INT_EDGE_BOTH or INT_EDGE_SETUP.
|
||||
/// If it is INT_EDGE_SETUP then no initialisation of the pin will happen – it’s assumed that you have already setup the pin elsewhere
|
||||
/// (e.g. with the gpio program), but if you specify one of the other types, then the pin will be exported and initialised as specified.
|
||||
/// This is accomplished via a suitable call to the gpio utility program, so it need to be available.
|
||||
/// The pin number is supplied in the current mode – native wiringPi, BCM_GPIO, physical or Sys modes.
|
||||
/// This function will work in any mode, and does not need root privileges to work.
|
||||
/// The function will be called when the interrupt triggers. When it is triggered, it’s cleared in the dispatcher before calling your function,
|
||||
/// so if a subsequent interrupt fires before you finish your handler, then it won’t be missed. (However it can only track one more interrupt,
|
||||
/// if more than one interrupt fires while one is being handled then they will be ignored)
|
||||
/// This function is run at a high priority (if the program is run using sudo, or as root) and executes concurrently with the main program.
|
||||
/// It has full access to all the global variables, open file handles and so on.
|
||||
/// </summary>
|
||||
/// <param name="pin">The pin.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
/// <param name="method">The method.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiISR", SetLastError = true)]
|
||||
public static extern Int32 WiringPiISR(Int32 pin, Int32 mode, InterruptServiceRoutineCallback method);
|
||||
|
||||
/// <summary>
|
||||
/// This function creates a thread which is another function in your program previously declared using the PI_THREAD declaration.
|
||||
/// This function is then run concurrently with your main program. An example may be to have this function wait for an interrupt while
|
||||
/// your program carries on doing other tasks. The thread can indicate an event, or action by using global variables to
|
||||
/// communicate back to the main program, or other threads.
|
||||
/// </summary>
|
||||
/// <param name="method">The method.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "piThreadCreate", SetLastError = true)]
|
||||
public static extern Int32 PiThreadCreate(ThreadWorker method);
|
||||
|
||||
/// <summary>
|
||||
/// These allow you to synchronise variable updates from your main program to any threads running in your program. keyNum is a number from 0 to 3 and represents a key.
|
||||
/// When another process tries to lock the same key, it will be stalled until the first process has unlocked the same key.
|
||||
/// You may need to use these functions to ensure that you get valid data when exchanging data between your main program and a thread
|
||||
/// – otherwise it’s possible that the thread could wake-up halfway during your data copy and change the data –
|
||||
/// so the data you end up copying is incomplete, or invalid. See the wfi.c program in the examples directory for an example.
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "piLock", SetLastError = true)]
|
||||
public static extern void PiLock(Int32 key);
|
||||
|
||||
/// <summary>
|
||||
/// These allow you to synchronise variable updates from your main program to any threads running in your program. keyNum is a number from 0 to 3 and represents a key.
|
||||
/// When another process tries to lock the same key, it will be stalled until the first process has unlocked the same key.
|
||||
/// You may need to use these functions to ensure that you get valid data when exchanging data between your main program and a thread
|
||||
/// – otherwise it’s possible that the thread could wake-up halfway during your data copy and change the data –
|
||||
/// so the data you end up copying is incomplete, or invalid. See the wfi.c program in the examples directory for an example.
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "piUnlock", SetLastError = true)]
|
||||
public static extern void PiUnlock(Int32 key);
|
||||
|
||||
/// <summary>
|
||||
/// This attempts to shift your program (or thread in a multi-threaded program) to a higher priority
|
||||
/// and enables a real-time scheduling. The priority parameter should be from 0 (the default) to 99 (the maximum).
|
||||
/// This won’t make your program go any faster, but it will give it a bigger slice of time when other programs are running.
|
||||
/// The priority parameter works relative to others – so you can make one program priority 1 and another priority 2
|
||||
/// and it will have the same effect as setting one to 10 and the other to 90 (as long as no other
|
||||
/// programs are running with elevated priorities)
|
||||
/// The return value is 0 for success and -1 for error. If an error is returned, the program should then consult the errno global variable, as per the usual conventions.
|
||||
/// Note: Only programs running as root can change their priority. If called from a non-root program then nothing happens.
|
||||
/// </summary>
|
||||
/// <param name="priority">The priority.</param>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "piHiPri", SetLastError = true)]
|
||||
public static extern Int32 PiHiPri(Int32 priority);
|
||||
|
||||
/// <summary>
|
||||
/// This causes program execution to pause for at least howLong milliseconds.
|
||||
/// Due to the multi-tasking nature of Linux it could be longer.
|
||||
/// Note that the maximum delay is an unsigned 32-bit integer or approximately 49 days.
|
||||
/// </summary>
|
||||
/// <param name="howLong">The how long.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "delay", SetLastError = true)]
|
||||
public static extern void Delay(UInt32 howLong);
|
||||
|
||||
/// <summary>
|
||||
/// This causes program execution to pause for at least howLong microseconds.
|
||||
/// Due to the multi-tasking nature of Linux it could be longer.
|
||||
/// Note that the maximum delay is an unsigned 32-bit integer microseconds or approximately 71 minutes.
|
||||
/// Delays under 100 microseconds are timed using a hard-coded loop continually polling the system time,
|
||||
/// Delays over 100 microseconds are done using the system nanosleep() function – You may need to consider the implications
|
||||
/// of very short delays on the overall performance of the system, especially if using threads.
|
||||
/// </summary>
|
||||
/// <param name="howLong">The how long.</param>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "delayMicroseconds", SetLastError = true)]
|
||||
public static extern void DelayMicroseconds(UInt32 howLong);
|
||||
|
||||
/// <summary>
|
||||
/// This returns a number representing the number of milliseconds since your program called one of the wiringPiSetup functions.
|
||||
/// It returns an unsigned 32-bit number which wraps after 49 days.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "millis", SetLastError = true)]
|
||||
public static extern UInt32 Millis();
|
||||
|
||||
/// <summary>
|
||||
/// This returns a number representing the number of microseconds since your program called one of
|
||||
/// the wiringPiSetup functions. It returns an unsigned 32-bit number which wraps after approximately 71 minutes.
|
||||
/// </summary>
|
||||
/// <returns>The result code</returns>
|
||||
[DllImport(WiringPiLibrary, EntryPoint = "micros", SetLastError = true)]
|
||||
public static extern UInt32 Micros();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user