Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
Changing all Hardware PWM functions to allow changing values without …
Browse files Browse the repository at this point in the history
…the need to change the actual mode to PwmOutput. (#9)

Update to use libwiringPi.so.2.50 (It is not clear when will the sources for version 2.52 be available)
  • Loading branch information
k3z0 authored and geoperez committed Jul 29, 2019
1 parent e4b7e64 commit 814e9eb
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 19 deletions.
28 changes: 12 additions & 16 deletions src/Unosquare.WiringPi/GpioPin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,12 @@ public int PwmRegister
{
lock (_syncLock)
{
if (PinMode != GpioPinDriveMode.PwmOutput)
if (!HasCapability(PinCapability.PWM))
{
_pwmRegister = 0;

throw new InvalidOperationException(
$"Unable to write PWM register for pin {BcmPinNumber} because operating mode is {PinMode}."
+ $" Writing the PWM register is only allowed if {nameof(PinMode)} is set to {GpioPinDriveMode.PwmOutput}");
throw new NotSupportedException(
$"Pin {BcmPinNumber} '{Name}' does not support mode '{GpioPinDriveMode.PwmOutput}'. Pin capabilities are limited to: {Capabilities}");
}

var val = value.Clamp(0, 1024);
Expand All @@ -226,13 +225,12 @@ public PwmMode PwmMode
{
lock (_syncLock)
{
if (PinMode != GpioPinDriveMode.PwmOutput)
if (!HasCapability(PinCapability.PWM))
{
_pwmMode = PwmMode.Balanced;

throw new InvalidOperationException(
$"Unable to set PWM mode for pin {BcmPinNumber} because operating mode is {PinMode}."
+ $" Setting the PWM mode is only allowed if {nameof(PinMode)} is set to {GpioPinDriveMode.PwmOutput}");
throw new NotSupportedException(
$"Pin {BcmPinNumber} '{Name}' does not support mode '{GpioPinDriveMode.PwmOutput}'. Pin capabilities are limited to: {Capabilities}");
}

WiringPi.PwmSetMode((int)value);
Expand All @@ -256,13 +254,12 @@ public uint PwmRange
{
lock (_syncLock)
{
if (PinMode != GpioPinDriveMode.PwmOutput)
if (!HasCapability(PinCapability.PWM))
{
_pwmRange = 1024;

throw new InvalidOperationException(
$"Unable to set PWM range for pin {BcmPinNumber} because operating mode is {PinMode}."
+ $" Setting the PWM range is only allowed if {nameof(PinMode)} is set to {GpioPinDriveMode.PwmOutput}");
throw new NotSupportedException(
$"Pin {BcmPinNumber} '{Name}' does not support mode '{GpioPinDriveMode.PwmOutput}'. Pin capabilities are limited to: {Capabilities}");
}

WiringPi.PwmSetRange(value);
Expand All @@ -286,13 +283,12 @@ public int PwmClockDivisor
{
lock (_syncLock)
{
if (PinMode != GpioPinDriveMode.PwmOutput)
if (!HasCapability(PinCapability.PWM))
{
_pwmClockDivisor = 1;

throw new InvalidOperationException(
$"Unable to set PWM range for pin {BcmPinNumber} because operating mode is {PinMode}."
+ $" Setting the PWM range is only allowed if {nameof(PinMode)} is set to {GpioPinDriveMode.PwmOutput}");
throw new NotSupportedException(
$"Pin {BcmPinNumber} '{Name}' does not support mode '{GpioPinDriveMode.PwmOutput}'. Pin capabilities are limited to: {Capabilities}");
}

WiringPi.PwmSetClock(value);
Expand Down
2 changes: 1 addition & 1 deletion src/Unosquare.WiringPi/Native/WiringPi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// </summary>
public partial class WiringPi
{
internal const string WiringPiLibrary = "libwiringPi.so.2.46";
internal const string WiringPiLibrary = "libwiringPi.so.2.50";

#region WiringPi - Core Functions (https://github.com/WiringPi/WiringPi/blob/master/wiringPi/wiringPi.h)

Expand Down
Binary file added src/Unosquare.WiringPi/Resources/gpio
Binary file not shown.
Binary file removed src/Unosquare.WiringPi/Resources/gpio.2.44
Binary file not shown.
Binary file removed src/Unosquare.WiringPi/Resources/libwiringPi.so.2.46
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions src/Unosquare.WiringPi/Unosquare.WiringPi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\gpio.2.44" />
<EmbeddedResource Include="Resources\libwiringPi.so.2.46" />
<EmbeddedResource Include="Resources\gpio" />
<EmbeddedResource Include="Resources\libwiringPi.so.2.50" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 814e9eb

Please sign in to comment.