Skip to content

Commit

Permalink
Accept struct termios as args to speed funs
Browse files Browse the repository at this point in the history
  • Loading branch information
msantos committed Feb 4, 2012
1 parent 24eb8e5 commit 2f622a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,13 @@ converting binaries using serctl:termios/1) include their definition:

serctl has a higher level interface for manipulating the C data structures
that takes care of portability. The structures are represented as Erlang
records. These functions do not have side effects and only retrieve or
set values within the termios structure. To change the serial device,
the attributes must be written out using serctl:tcsetattr/3.
records. These functions only retrieve or modify values within the termios
structure and do not side effects when used with the record format (when
binaries are used as arguments, they are first converted to record format
based on a runtime platform check).

To change the serial device, the attributes must
be written out using serctl:tcsetattr/3.

serctl:flow(Termios) -> true | false
serctl:flow(Termios, Bool) -> #termios{}
Expand Down Expand Up @@ -188,9 +192,9 @@ the attributes must be written out using serctl:tcsetattr/3.
ok = serctl:tcsetattr(FD, tcsanow, Termios1).

serctl:ispeed(Termios) -> integer()
serctl:ispeed(Termios, Speed) -> #termios{}
serctl:ispeed(Termios, Speed) -> #termios{} | binary()
serctl:ospeed(Termios) -> integer()
serctl:ospeed(Termios, Speed) -> #termios{}
serctl:ospeed(Termios, Speed) -> #termios{} | binary()

Types Termios = #termios{}
Speed = integer()
Expand Down
10 changes: 10 additions & 0 deletions src/serctl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,25 @@ mode(raw) ->
bor constant(cread)
}.

ispeed(Speed) when is_binary(Speed) ->
ispeed(termios(Speed));
ispeed(#termios{ispeed = Speed}) ->
Speed.

ispeed(Termios, Speed) when is_binary(Termios) ->
ispeed(termios(Termios), Speed);
ispeed(Termios, Speed) when is_atom(Speed) ->
ispeed(Termios, constant(Speed));
ispeed(#termios{} = Termios, Speed) when is_integer(Speed) ->
Termios#termios{ispeed = Speed}.

ospeed(Speed) when is_binary(Speed) ->
ospeed(termios(Speed));
ospeed(#termios{ospeed = Speed}) ->
Speed.

ospeed(Termios, Speed) when is_binary(Termios) ->
ospeed(termios(Termios), Speed);
ospeed(Termios, Speed) when is_atom(Speed) ->
ospeed(Termios, constant(Speed));
ospeed(#termios{} = Termios, Speed) when is_integer(Speed) ->
Expand Down

0 comments on commit 2f622a0

Please sign in to comment.