Skip to content

Commit

Permalink
Update testsw
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor Rigby committed Dec 20, 2019
1 parent 2e32ee0 commit 566c853
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 59 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ erl_crash.dump

*.hex
upload.sh
.env
.env
*.img
6 changes: 3 additions & 3 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ config :post, POST.PlatformSupervisor, children: []
if Mix.target() != :host do
import_config "target.exs"
else
# import_config "profiles/FARMDUINO_K15.ex"
import_config "profiles/EXPRESS_K10.ex"
config :post, POST.Comms, device: "ttyUSB0"
import_config "profiles/FARMDUINO_K15.ex"
# import_config "profiles/EXPRESS_K10.ex"
# config :post, POST.Comms, device: "ttyUSB0"
config :post, POST.Comms.FlashFirmware, reset: POST.Comms.FlashFirmware.NullReset
config :post, POST.ButtonSupervisor, button: POST.NullButton
config :post, POST.LEDSupervisor, led: POST.NullLED
Expand Down
5 changes: 3 additions & 2 deletions firmware_src/include/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#if defined(MIX_TARGET)
#if defined(MIX_TARGET_host)
#include "pins_farmduino_k15.h"
#include "pins_farmduino_k15.h"
#endif

#if defined(MIX_TARGET_rpi)
Expand All @@ -15,7 +16,7 @@

#endif
#else // if MIX_TARGET is not defined
#include "pins_express_k10.h"
// #include "pins_farmduino_k15.h"
// #include "pins_express_k10.h"
#include "pins_farmduino_k15.h"
#endif
#endif
63 changes: 63 additions & 0 deletions lib/post/comms.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,41 @@ defmodule POST.Comms do
recv_close(uart, 10000)
end

def move_all(motors, steps) do
{:ok, uart} = UART.start_link()
:ok = UART.open(uart, serial_port(), active: true, speed: 9600, framing: Framing)
do_sleep_hack()

r =
motors
|> Enum.map(fn
axis ->
move1 =
<<109::integer-size(8), 0x5::integer-size(8), axis::integer-size(8),
steps::unsigned-integer-big-size(32)>>

move2 =
<<109::integer-size(8), 0x5::integer-size(8), axis::integer-size(8),
steps * -1::unsigned-integer-big-size(32)>>

:ok = UART.write(uart, move1)
recv(uart, 10000)
:ok = UART.write(uart, move2)
recv(uart, 10000)
end)
|> Enum.all?(fn
{:ok, steps} when steps >= 1 ->
true

_ ->
false
end)

UART.close(uart)

r
end

@doc "writes a pin number"
def pin(number) do
{:ok, uart} = UART.start_link()
Expand All @@ -96,6 +131,34 @@ defmodule POST.Comms do
recv_close(uart)
end

def all_pins(pins) do
{:ok, uart} = UART.start_link()
:ok = UART.open(uart, serial_port(), active: true, speed: 9600, framing: Framing)
do_sleep_hack()

r =
pins
|> Enum.map(fn
number ->
data = <<112::integer-size(8), 0x1::integer-size(8), number::integer-size(8)>>
:ok = UART.write(uart, data)
recv(5000)
end)
|> Enum.all?(fn
{:ok, load} when load <= 3 ->
false

{:ok, _} ->
true

_ ->
false
end)

UART.close(uart)
r
end

def reset_test do
{:ok, uart} = UART.start_link()
:ok = UART.open(uart, serial_port(), active: true, speed: 9600, framing: Framing)
Expand Down
96 changes: 43 additions & 53 deletions lib/post/test_suite.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,78 +106,68 @@ defmodule POST.TestSuite do
{:noreply, %{state | leds: [], state: :peripherals}}
end

def handle_info({:button, _, _, 0}, %{state: :leds, leds: [24, 25, 12, 13] = leds} = state) do
for led <- leds do
led_on(led)
end

{:noreply, %{state | leds: [], state: :peripherals}}
end

def handle_info({:button, _, _, 0}, %{state: :leds, leds: [led | rest]} = state) do
Logger.info("testing led: #{led}")
led_on(led)
{:noreply, %{state | leds: rest}}
end

def handle_info({:button, _, _, 0}, %{state: :peripherals, peripherals: [peripheral]} = state) do
Logger.info("testing peripheral: #{peripheral} (this is the last one)")
_ = POST.Comms.pin(peripheral)
{:noreply, %{state | peripherals: [], state: :motors}}
end
# def handle_info({:button, _, _, 0}, %{state: :peripherals, peripherals: [peripheral]} = state) do
# Logger.info("testing peripheral: #{peripheral} (this is the last one)")
# _ = POST.Comms.pin(peripheral)
# {:noreply, %{state | peripherals: [], state: :motors}}
# end

def handle_info(
{:button, _, _, 0},
%{state: :peripherals, peripherals: [peripheral | rest]} = state
%{state: :peripherals, peripherals: peripherals} = state
) do
case POST.Comms.pin(peripheral) do
{:ok, load} when load <= 3 ->
Logger.error("failed testing peripheral: #{peripheral} load: #{load}")
send(self(), :peripheral_error)

{:ok, load} when load >= 256 ->
Logger.error("failed testing peripheral: #{peripheral} load: #{load}")
send(self(), :peripheral_error)

{:ok, load} ->
Logger.info("testing peripheral: #{peripheral} load: #{load}")

error ->
Logger.error("failed testing peripheral: #{peripheral} error: #{inspect(error)}")
send(self(), :peripheral_error)
if POST.Comms.all_pins(peripherals) do
{:noreply, %{state | peripherals: [], state: :motors}}
else
Logger.error("failed testing peripherals")
send(self(), :peripheral_error)
{:noreply, state}
end

{:noreply, %{state | peripherals: rest}}
end

def handle_info({:button, _, _, 0}, %{state: :motors, motors: [motor]} = state) do
Logger.info("testing motor: #{motor} (this is the last one)")

case POST.Comms.move2(motor, 500) do
{:ok, steps} when steps >= 1 ->
send(self(), :init)
:ok
# def handle_info({:button, _, _, 0}, %{state: :motors, motors: [motor]} = state) do
# Logger.info("testing motor: #{motor} (this is the last one)")

{:ok, steps} ->
send(self(), :encoder_error)
Logger.error("movement test failed! #{steps}")
# case POST.Comms.move2(motor, 500) do
# {:ok, steps} when steps >= 1 ->
# send(self(), :init)
# :ok

:error ->
send(self(), :encoder_error)
Logger.error("movement test failed (no response)")
end

{:noreply, %{state | motors: [], state: :complete}}
end
# {:ok, steps} ->
# send(self(), :encoder_error)
# Logger.error("movement test failed! #{steps}")

def handle_info({:button, _, _, 0}, %{state: :motors, motors: [motor | rest]} = state) do
Logger.info("testing motor: #{motor}")
# :error ->
# send(self(), :encoder_error)
# Logger.error("movement test failed (no response)")
# end

case POST.Comms.move2(motor, 500) do
{:ok, steps} when steps >= 1 ->
:ok
# {:noreply, %{state | motors: [], state: :complete}}
# end

{:ok, steps} ->
send(self(), :encoder_error)
Logger.error("movement test failed! #{steps}")
def handle_info({:button, _, _, 0}, %{state: :motors, motors: motors} = state) do
Logger.info("testing motors:")

:error ->
send(self(), :encoder_error)
Logger.error("movement test failed (no response)")
if POST.Comms.move_all(motors, 500) do
{:noreply, %{state | motors: [], state: :complete}}
else
send(self(), :encoder_error)
Logger.error("movement test failed")
{:noreply, state}
end

{:noreply, %{state | motors: rest}}
end
end

0 comments on commit 566c853

Please sign in to comment.