Skip to content

Commit

Permalink
Merge pull request #2 from infinity-aps/check_link_on_init
Browse files Browse the repository at this point in the history
Test connection on init
  • Loading branch information
tmecklem committed Oct 28, 2017
2 parents eaa403b + 5ddec20 commit c72f934
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/subg_rfspy/spi.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ defmodule SubgRfspy.SPI do
GenServer.start_link(__MODULE__, [device, reset_pin], name: __MODULE__)
end

@status_tx1 <<@initial_byte::8, 0x010100::24>>
@status_tx2 <<@initial_byte::8, 0x00000000::32>>
def init([device, reset_pin]) do
with {:ok, serial_pid} <- SPI.start_link(device, [speed_hz: 62500]),
{:ok, reset_pid} <- GPIO.start_link(reset_pin, :output),
:ok <- _reset(reset_pid) do
:ok <- _reset(reset_pid),
transfer(serial_pid, @status_tx1),
<<_::16>> <> "OK" <> <<_::8>> <- transfer(serial_pid, @status_tx2) do
{:ok, %{serial_pid: serial_pid, reset_pid: reset_pid, read_queue: []}}
else
error ->
Expand Down
4 changes: 3 additions & 1 deletion lib/subg_rfspy/uart.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ defmodule SubgRfspy.UART do
with {:ok, serial_pid} <- UART.start_link,
:ok <- UART.open(serial_pid, device, speed: 19_200, active: false),
:ok <- UART.configure(serial_pid, framing: {UARTFraming, separator: <<0x00>>}),
:ok <- UART.flush(serial_pid) do
:ok <- UART.flush(serial_pid),
:ok <- write_fully(<<0x01>>, 100, serial_pid),
{:ok, "OK"} <- UART.read(serial_pid, 1_000) do

{:ok, serial_pid}
else
Expand Down

0 comments on commit c72f934

Please sign in to comment.