Skip to content

Commit

Permalink
Specify supported level ranges for PWM
Browse files Browse the repository at this point in the history
  • Loading branch information
mnishiguchi committed Nov 23, 2020
1 parent 5085bfb commit 8d361f4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/pigpiox/pwm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ defmodule Pigpiox.Pwm do
@moduledoc """
Build and send waveforms with pigpiod.
"""

@doc """
Sets the current dutycycle and fequency for the hardware PWM on a specific GPIO `pin`
Sets the current dutycycle and fequency for the hardware PWM on a specific GPIO `pin`. Max value for `level` is `1_000_000`.
"""
@spec hardware_pwm(pin :: integer, freq :: integer, level :: integer) :: :ok | {:error, atom}
def hardware_pwm(pin, freq, level) do
def hardware_pwm(pin, freq, level) when level in 0..1_000_000 do
case Pigpiox.Socket.command(:hardware_pwm, pin, freq, [level]) do
{:ok, _} -> :ok
error -> error
end
end

@doc """
Sets up a specific pin as a software PWM and sets the current dutycycle
Sets up a specific pin as a software PWM and sets the current dutycycle. Max value for `level` is `255`.
"""
@spec gpio_pwm(pin :: integer, level :: integer) :: :ok | {:error, atom}
def gpio_pwm(pin, level) do
def gpio_pwm(pin, level) when level in 0..255 do
case Pigpiox.Socket.command(:gpio_PWM, pin, level) do
{:ok, _} -> :ok
error -> error
Expand Down Expand Up @@ -62,4 +62,3 @@ defmodule Pigpiox.Pwm do
end
end
end

0 comments on commit 8d361f4

Please sign in to comment.