Skip to content

Commit 4aef35b

Browse files
committed
added docs
1 parent 722f6c9 commit 4aef35b

3 files changed

Lines changed: 59 additions & 17 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
_build
22
deps
33
priv
4+
doc
45
CMakeFiles
56
CMakeCache.txt
67
cmake_install.cmake

lib/serial.ex

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
defmodule Serial do
2+
@moduledoc """
3+
Serial communication through Elixir ports.
4+
"""
5+
26
use GenServer
37

48
@send 0
@@ -11,51 +15,82 @@ defmodule Serial do
1115
@parity_even 7
1216
@break 8
1317

14-
def start_link(pid) do
15-
GenServer.start_link(__MODULE__, pid)
18+
@doc """
19+
Starts a serial port. The process invoking this function will receive
20+
messages in the form of `{:elixir_serial, pid, data}`.
21+
"""
22+
def start_link(opts \\ []) do
23+
GenServer.start_link(__MODULE__, self(), opts)
1624
end
1725

26+
@doc """
27+
Opens a connection to the given tty.
28+
"""
1829
def open(pid, tty) do
1930
GenServer.call(pid, {:open, tty})
2031
end
2132

33+
@doc """
34+
Close the currently open connection.
35+
"""
2236
def close(pid) do
2337
GenServer.call(pid, {:cmd, @close})
2438
end
2539

40+
@doc """
41+
Reopens the connection to the current tty.
42+
"""
2643
def connect(pid) do
2744
GenServer.call(pid, {:cmd, @connect})
2845
end
2946

47+
@doc """
48+
Disconnects from the current tty.
49+
"""
3050
def disconnect(pid) do
3151
GenServer.call(pid, {:cmd, @disconnect})
3252
end
3353

54+
@doc """
55+
Sets the connection speed to the given value.
56+
"""
3457
def set_speed(pid, speed) do
3558
set_speed(pid, speed, speed)
3659
end
3760

61+
@doc """
62+
Sets the input and output connection speed to the given values.
63+
"""
3864
def set_speed(pid, in_speed, out_speed) do
3965
GenServer.call(pid, {:speed, in_speed, out_speed})
4066
end
4167

68+
@doc """
69+
Sets the parity to either `:odd` and `:even`.
70+
"""
4271
def set_parity(pid, :odd) do
4372
GenServer.call(pid, {:cmd, @parity_odd})
4473
end
4574
def set_parity(pid, :even) do
4675
GenServer.call(pid, {:cmd, @parity_even})
4776
end
4877

78+
@doc """
79+
Sends a break to the open connection.
80+
"""
4981
def break(pid) do
5082
GenServer.call(pid, {:cmd, @break})
5183
end
5284

85+
@doc """
86+
Sends data over the open connection.
87+
"""
5388
def send_data(pid, data) do
5489
GenServer.call(pid, {:send, data})
5590
end
5691

5792
def init(pid) do
58-
exec = :code.priv_dir(:elixir_serial) ++ '/serial'
93+
exec = :code.priv_dir(:serial) ++ '/serial'
5994
port = Port.open({:spawn_executable, exec}, [{:args, ['-erlang']}, :binary, {:packet, 2}])
6095
{:ok, {pid, port}}
6196
end

mix.exs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,32 @@ defmodule Serial.Mixfile do
1818
compilers: [:cmake] ++ Mix.compilers,
1919
build_embedded: Mix.env == :prod,
2020
start_permanent: Mix.env == :prod,
21-
deps: deps]
21+
deps: deps,
22+
package: package,
23+
description: description,
24+
docs: [readme: "README.md", main: "README"]]
2225
end
2326

24-
# Configuration for the OTP application
25-
#
26-
# Type `mix help compile.app` for more information
2727
def application do
2828
[applications: [:logger]]
2929
end
3030

31-
# Dependencies can be Hex packages:
32-
#
33-
# {:mydep, "~> 0.3.0"}
34-
#
35-
# Or git/path repositories:
36-
#
37-
# {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
38-
#
39-
# Type `mix help deps` for more examples and options
4031
defp deps do
41-
[]
32+
[
33+
{:earmark, "~> 0.1", only: :docs},
34+
{:ex_doc, "~> 0.8", only: :docs}
35+
]
36+
end
37+
38+
defp description do
39+
"Serial communication through Elixir ports"
40+
end
41+
42+
defp package do
43+
[
44+
contributors: ["Michele Balistreri"],
45+
licenses: ["ISC"],
46+
links: %{"GitHub" => "https://github.com/bitgamma/elixir_serial"}
47+
]
4248
end
4349
end

0 commit comments

Comments
 (0)