Add led debuggers, clean up stub fw impl, add default network configurator
parent
2e5fa911fb
commit
238d4a56f5
|
@ -51,7 +51,7 @@ case target do
|
|||
_ ->
|
||||
import_config("target/#{env}.exs")
|
||||
if File.exists?("config/target/#{target}.exs") do
|
||||
import_config("config/target/#{target}.exs")
|
||||
import_config("target/#{target}.exs")
|
||||
end
|
||||
|
||||
rootfs_overlay_dir = "config/target/rootfs_overlay_#{Mix.Project.config()[:target]}"
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
use Mix.Config
|
||||
|
||||
config :nerves_leds, names: [ status: "led0" ]
|
||||
config :farmbot, :gpio, status_led_on: false
|
||||
config :farmbot, :gpio, status_led_off: true
|
|
@ -4,6 +4,10 @@ use Mix.Config
|
|||
# TODO Remove this some day.
|
||||
config :nerves, :firmware, fwup_conf: "fwup_interim.conf"
|
||||
|
||||
config :nerves_leds, names: [ status: "led0" ]
|
||||
config :farmbot, :gpio, status_led_on: false
|
||||
config :farmbot, :gpio, status_led_off: true
|
||||
|
||||
config :bootloader,
|
||||
init: [:nerves_runtime, :nerves_firmware_ssh],
|
||||
app: :farmbot
|
|
@ -21,11 +21,13 @@ defmodule Farmbot.Bootstrap.AuthTask do
|
|||
auth_task = Application.get_env(:farmbot, :behaviour)[:authorization]
|
||||
{email, pass, server} = {fetch_email(), fetch_pass(), fetch_server()}
|
||||
Logger.busy(3, "refreshing token: #{auth_task} - #{email} - #{server}")
|
||||
Farmbot.System.GPIO.Leds.led_status_err()
|
||||
case auth_task.authorize(email, pass, server) do
|
||||
{:ok, token} ->
|
||||
Logger.success(3, "Successful authorization: #{auth_task} - #{email} - #{server}")
|
||||
ConfigStorage.update_config_value(:bool, "settings", "first_boot", false)
|
||||
ConfigStorage.update_config_value(:string, "authorization", "token", token)
|
||||
Farmbot.System.GPIO.Leds.led_status_ok()
|
||||
restart_transports()
|
||||
refresh_timer(self())
|
||||
{:error, reason} ->
|
||||
|
|
|
@ -33,6 +33,8 @@ defmodule Farmbot.Bootstrap.Authorization do
|
|||
{:ok, body} <- Poison.decode(resp),
|
||||
{:ok, map} <- Map.fetch(body, "token") do
|
||||
Farmbot.System.ConfigStorage.update_config_value(:bool, "settings", "first_boot", false)
|
||||
Farmbot.System.GPIO.Leds.led_status_ok()
|
||||
|
||||
Map.fetch(map, "encoded")
|
||||
else
|
||||
:error -> {:error, "unknown error."}
|
||||
|
@ -50,6 +52,7 @@ defmodule Farmbot.Bootstrap.Authorization do
|
|||
{:ok, resp} <- request_token(server, payload),
|
||||
{:ok, body} <- Poison.decode(resp),
|
||||
{:ok, map} <- Map.fetch(body, "token") do
|
||||
Farmbot.System.GPIO.Leds.led_status_ok()
|
||||
Map.fetch(map, "encoded")
|
||||
else
|
||||
:error -> {:error, "unknown error."}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
defmodule Farmbot.CeleryScript.AST.Node.Calibrate do
|
||||
@moduledoc false
|
||||
use Farmbot.CeleryScript.AST.Node
|
||||
allow_args [:axis]
|
||||
allow_args [:axis, :speed]
|
||||
|
||||
@default_speed 100
|
||||
|
||||
def execute(%{axis: :all}, _, env) do
|
||||
env = mutate_env(env)
|
||||
do_reduce([:y, :z, :x], @default_speed, env)
|
||||
do_reduce([:z, :y, :x], @default_speed, env)
|
||||
end
|
||||
|
||||
def execute(%{speed: speed, axis: axis}, _, env) do
|
||||
|
|
|
@ -5,7 +5,7 @@ defmodule Farmbot.CeleryScript.AST.Node.FindHome do
|
|||
|
||||
def execute(%{speed: speed, axis: :all}, _, env) do
|
||||
env = mutate_env(env)
|
||||
do_reduce([:y, :z, :x], speed, env)
|
||||
do_reduce([:z, :y, :x], speed, env)
|
||||
end
|
||||
|
||||
def execute(%{speed: speed, axis: axis}, _, env) do
|
||||
|
|
|
@ -5,7 +5,7 @@ defmodule Farmbot.CeleryScript.AST.Node.Home do
|
|||
|
||||
def execute(%{speed: speed, axis: :all}, _, env) do
|
||||
env = mutate_env(env)
|
||||
do_reduce([:y, :z, :x], speed, env)
|
||||
do_reduce([:z, :y, :x], speed, env)
|
||||
end
|
||||
|
||||
def execute(%{speed: speed, axis: axis}, _, env) do
|
||||
|
|
|
@ -2,9 +2,9 @@ defmodule Farmbot.CeleryScript.AST.Node.Sequence do
|
|||
@moduledoc false
|
||||
use Farmbot.CeleryScript.AST.Node
|
||||
use Farmbot.Logger
|
||||
allow_args [:version, :label, :locals]
|
||||
allow_args [:version, :label, :locals, :is_outdated]
|
||||
|
||||
def execute(%{version: _, label: name, locals: _}, body, env) do
|
||||
def execute(%{label: name}, body, env) do
|
||||
if Farmbot.System.ConfigStorage.get_config_value(:bool, "settings", "sequence_init_log") do
|
||||
Logger.busy 2, "[#{name}] - Sequence init."
|
||||
end
|
||||
|
|
|
@ -179,6 +179,7 @@ defmodule Farmbot.Firmware do
|
|||
|
||||
case apply(state.handler_mod, fun, [state.handler | args]) do
|
||||
:ok ->
|
||||
if fun == :emergency_unlock, do: Farmbot.System.GPIO.Leds.led_status_ok()
|
||||
timer = Process.send_after(self(), :timeout, 6500)
|
||||
{:noreply, dispatch, %{state | current: current, timer: timer}}
|
||||
{:error, _} = res ->
|
||||
|
@ -353,6 +354,7 @@ defmodule Farmbot.Firmware do
|
|||
end
|
||||
|
||||
defp handle_gcode(:report_emergency_lock, state) do
|
||||
Farmbot.System.GPIO.Leds.led_status_err
|
||||
if state.current do
|
||||
GenStage.reply(state.current.from, {:error, :emergency_lock})
|
||||
{:informational_settings, %{sync_status: :locked}, %{state | current: nil}}
|
||||
|
|
|
@ -119,11 +119,14 @@ defmodule Farmbot.Firmware.StubHandler do
|
|||
|
||||
def handle_call({:home, axis, _speed}, _from, state) do
|
||||
state = %{state | pos: %{state.pos | axis => 0}}
|
||||
case axis do
|
||||
:x -> {:reply, :ok, [:report_axis_home_complete_x, {:report_current_position, 0, state.pos.y, state.pos.z}, :done], state}
|
||||
:y -> {:reply, :ok, [:report_axis_home_complete_y, {:report_current_position, state.pos.x, 0, state.pos.z}, :done], state}
|
||||
:z -> {:reply, :ok, [:report_axis_home_complete_z, {:report_current_position, state.pos.x, state.pos.y, 0}, :done], state}
|
||||
end
|
||||
response = [
|
||||
:"report_axis_home_complete_#{axis}",
|
||||
{:report_current_position, state.pos.x, state.pos.y, state.pos.z},
|
||||
{:report_encoder_position_scaled, state.pos.x, state.pos.y, state.pos.z},
|
||||
{:report_encoder_position_raw, state.pos.x, state.pos.y, state.pos.z},
|
||||
:done
|
||||
]
|
||||
{:reply, :ok, response, state}
|
||||
end
|
||||
|
||||
def handle_call({:read_pin, pin, mode}, _from, state) do
|
||||
|
@ -140,11 +143,13 @@ defmodule Farmbot.Firmware.StubHandler do
|
|||
|
||||
def handle_call({:zero, axis}, _from, state) do
|
||||
state = %{state | pos: %{state.pos | axis => 0}}
|
||||
case axis do
|
||||
:x -> {:reply, :ok, [{:report_current_position, 0, state.pos.y, state.pos.z}, :done], state}
|
||||
:y -> {:reply, :ok, [{:report_current_position, state.pos.x, 0, state.pos.z}, :done], state}
|
||||
:z -> {:reply, :ok, [{:report_current_position, state.pos.x, state.pos.y, 0}, :done], state}
|
||||
end
|
||||
response = [
|
||||
{:report_current_position, state.pos.x, state.pos.y, state.pos.z},
|
||||
{:report_encoder_position_scaled, state.pos.x, state.pos.y, state.pos.z},
|
||||
{:report_encoder_position_raw, state.pos.x, state.pos.y, state.pos.z},
|
||||
:done
|
||||
]
|
||||
{:reply, :ok, response, state}
|
||||
end
|
||||
|
||||
def handle_call({:update_param, param, val}, _from, state) do
|
||||
|
@ -161,11 +166,11 @@ defmodule Farmbot.Firmware.StubHandler do
|
|||
end
|
||||
|
||||
def handle_call(:emergency_lock, _from, state) do
|
||||
{:reply, :ok, [:done], state}
|
||||
{:reply, :ok, [:report_emergency_lock, :done], state}
|
||||
end
|
||||
|
||||
def handle_call(:emergency_unlock, _from, state) do
|
||||
{:reply, :ok, [:done], state}
|
||||
{:reply, :ok, [:done, :idle], state}
|
||||
end
|
||||
|
||||
def handle_call(:request_software_version, _, state) do
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
defmodule Farmbot.System.GPIO.Leds do
|
||||
@moduledoc false
|
||||
|
||||
use GenServer
|
||||
|
||||
@led_status_on Application.get_env(:farmbot, :gpio, :status_led_off) || true
|
||||
|
||||
def led_status_ok do
|
||||
GenServer.call(__MODULE__, :led_status_ok)
|
||||
end
|
||||
|
||||
def led_status_err do
|
||||
GenServer.call(__MODULE__, :led_status_err)
|
||||
end
|
||||
|
||||
@doc false
|
||||
def start_link do
|
||||
GenServer.start_link(__MODULE__, [], [name: __MODULE__])
|
||||
end
|
||||
|
||||
def init([]) do
|
||||
names = Application.get_env(:nerves_leds, :names) || []
|
||||
status_led_name = Keyword.get(names, :status)
|
||||
{:ok, %{status: status_led_name}}
|
||||
end
|
||||
|
||||
def handle_call(_, _from, %{status: nil} = state) do
|
||||
{:reply, :ok, state}
|
||||
end
|
||||
|
||||
def handle_call(:led_status_ok, _from, %{status: _} = state) do
|
||||
Nerves.Leds.set status: @led_status_on
|
||||
{:reply, :ok, state}
|
||||
end
|
||||
|
||||
def handle_call(:led_status_err, _from, %{status: _} = state) do
|
||||
Nerves.Leds.set status: :slowblink
|
||||
{:reply, :ok, state}
|
||||
end
|
||||
end
|
|
@ -16,6 +16,7 @@ defmodule Farmbot.System.Supervisor do
|
|||
supervisor(Farmbot.System.Init.Ecto, [[], []]),
|
||||
supervisor(Farmbot.System.ConfigStorage, []),
|
||||
worker(Farmbot.System.ConfigStorage.Dispatcher, []),
|
||||
worker(Farmbot.System.GPIO.Leds, [])
|
||||
]
|
||||
|
||||
init_mods =
|
||||
|
|
5
mix.exs
5
mix.exs
|
@ -102,7 +102,8 @@ defmodule Farmbot.Mixfile do
|
|||
|
||||
{:ex_syslogger, "~> 1.4", only: :prod},
|
||||
{:credo, "~> 0.8", only: [:dev, :test], runtime: false},
|
||||
{:recon, "~> 2.3"}
|
||||
{:recon, "~> 2.3"},
|
||||
{:nerves_leds, "~> 0.8.0"}
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -140,7 +141,7 @@ defmodule Farmbot.Mixfile do
|
|||
{:nerves_init_gadget, github: "nerves-project/nerves_init_gadget", branch: "dhcp", only: :dev},
|
||||
{:nerves_network, "~> 0.3", github: "nerves-project/nerves_network", override: true},
|
||||
{:dhcp_server, github: "nerves-project/dhcp_server", branch: "elixirize-go!", override: true},
|
||||
{:elixir_ale, "~> 1.0"}
|
||||
{:elixir_ale, "~> 1.0"},
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [], [], "hexpm"},
|
||||
"mock": {:hex, :mock, "0.2.1", "bfdba786903e77f9c18772dee472d020ceb8ef000783e737725a4c8f54ad28ec", [], [{:meck, "~> 0.8.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"nerves": {:hex, :nerves, "0.8.3", "cd3db3adadf5d4191249770ff2f247884408722f1fef2fa1e24f3145972bcf6f", [:mix], [{:distillery, "~> 1.4", [hex: :distillery, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"nerves_leds": {:hex, :nerves_leds, "0.8.0", "193692767dca1a201b09113d242648493b9be0087bab83ebee99c3b0a254f5e1", [], [], "hexpm"},
|
||||
"nerves_network": {:git, "https://github.com/nerves-project/nerves_network.git", "a4c4e11c8f8663bed36e1bc0f45ac57a1b9eee9a", []},
|
||||
"nerves_network_interface": {:hex, :nerves_network_interface, "0.4.2", "7a3663a07803f2f9f1e37146714d24ccec1e9349268586e4ed8c41f38641d837", [], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"nerves_ssdp_client": {:hex, :nerves_ssdp_client, "0.1.3", "b09dc7433b2536399885a5f0fcd1fb58283115b075f9485f86fa713547d404dc", [], [], "hexpm"},
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
"nerves_firmware": {:hex, :nerves_firmware, "0.4.0", "ac2fed915a7ca4bb69f567d9b742d77cffc3a6a56420ce65e870c8c34119b935", [], [], "hexpm"},
|
||||
"nerves_firmware_ssh": {:hex, :nerves_firmware_ssh, "0.3.1", "e8b1967fa0aff255230be539c68ec868d33884193a385caff957ebad7d6aa8af", [:mix], [{:nerves_runtime, "~> 0.4", [hex: :nerves_runtime, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"nerves_init_gadget": {:git, "https://github.com/nerves-project/nerves_init_gadget.git", "7eee0c73286e927b90f6d90b6a35b63aeefa5e84", [branch: "dhcp"]},
|
||||
"nerves_leds": {:hex, :nerves_leds, "0.8.0", "193692767dca1a201b09113d242648493b9be0087bab83ebee99c3b0a254f5e1", [], [], "hexpm"},
|
||||
"nerves_network": {:git, "https://github.com/nerves-project/nerves_network.git", "40c7fbb60e08f4f40e446941b189cb9adbbcf3cf", []},
|
||||
"nerves_network_interface": {:hex, :nerves_network_interface, "0.4.2", "7a3663a07803f2f9f1e37146714d24ccec1e9349268586e4ed8c41f38641d837", [], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"nerves_runtime": {:hex, :nerves_runtime, "0.5.0", "5f4135fe3c94ca5c9e25d677350fbb136f279d14aac4871236961b6f5ccbcfa5", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:system_registry, "~> 0.5", [hex: :system_registry, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
|
|
|
@ -47,7 +47,7 @@ defmodule Farmbot.Target.Bootstrap.Configurator do
|
|||
Logger.info(3, "Building new configuration.")
|
||||
import Supervisor.Spec
|
||||
:ets.new(:session, [:named_table, :public, read_concurrency: true])
|
||||
|
||||
Farmbot.System.GPIO.Leds.led_status_err()
|
||||
children = [
|
||||
Plug.Adapters.Cowboy.child_spec(
|
||||
:http,
|
||||
|
|
Loading…
Reference in New Issue