Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GPIO pull setting #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/pigpiox/command.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Pigpiox.Command do
@commands %{
set_mode: 0,
get_mode: 1,
set_pull: 2,
gpio_read: 3,
gpio_write: 4,
set_servo_pulsewidth: 8,
Expand Down
26 changes: 26 additions & 0 deletions lib/pigpiox/gpio.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ defmodule Pigpiox.GPIO do
@gpio_modes Map.keys(@gpio_modes_map)
@inverted_gpio_modes_map for {key, val} <- @gpio_modes_map, into: %{}, do: {val, key}

@gpio_pull_map %{
off: 0,
down: 1,
up: 2
}
@gpio_pull Map.keys(@gpio_pull_map)

@moduledoc """
This module exposes pigpiod's basic GPIO functionality.
"""
Expand All @@ -21,6 +28,11 @@ defmodule Pigpiox.GPIO do
"""
@type mode :: :input | :output | :alt0 | :alt1 | :alt2 | :alt3 | :alt4 | :alt5

@typedoc """
GPIO pull settings, for `set_pull/2`
"""
@type pull :: :up | :down | :off

@typedoc """
The state of a GPIO pin - 0 for low, 1 for high.
"""
Expand Down Expand Up @@ -51,6 +63,20 @@ defmodule Pigpiox.GPIO do
end
end

@doc """
Sets a pull for a specific GPIO `pin`. `pin` must be a valid GPIO pin number for the device, with some exceptions.
See pigpio's [documentation](http://abyz.co.uk/rpi/pigpio/index.html) for more details.

`pull` can be any of `t:pull/0`.
"""
@spec set_pull(pin :: integer, pull) :: :ok | {:error, atom}
def set_pull(pin, pull) when pull in @gpio_pull do
case Pigpiox.Socket.command(:set_pull, pin, @gpio_pull_map[pull]) do
{:ok, _} -> :ok
error -> error
end
end

@doc """
Returns the current level for a specific GPIO `pin`
"""
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Pigpiox.Mixfile do
def project do
[
app: :pigpiox,
version: "0.1.2",
version: "0.1.3",
elixir: "~> 1.5",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
Expand Down