Add new `configured` state to farmbot firmware

feature/sequence-on-boot
Connor Rigby 2019-11-07 09:01:58 -08:00
parent d34ab2abb2
commit a76f67347a
No known key found for this signature in database
GPG Key ID: 29A88B24B70456E0
6 changed files with 41 additions and 3 deletions

View File

@ -72,6 +72,10 @@ defmodule FarmbotCore.BotState do
def set_firmware_version(bot_state_server \\ __MODULE__, version) do
GenServer.call(bot_state_server, {:set_firmware_version, version})
end
def set_firmware_configured(bot_state_server \\ __MODULE__, configured \\ true) do
GenServer.call(bot_state_server, {:set_firmware_configured, configured})
end
@doc "Sets configuration.arduino_hardware"
def set_firmware_hardware(bot_state_server \\ __MODULE__, hardware) do
@ -306,6 +310,17 @@ defmodule FarmbotCore.BotState do
{:reply, reply, state}
end
def handle_call({:set_firmware_configured, configured}, _from, state) do
change = %{informational_settings: %{firmware_configured: configured}}
{reply, state} =
BotStateNG.changeset(state.tree, change)
|> dispatch_and_apply(state)
{:reply, reply, state}
end
def handle_call({:set_firmware_hardware, hardware}, _from, state) do
change = %{configuration: %{firmware_hardware: hardware}}

View File

@ -16,6 +16,7 @@ defmodule FarmbotCore.BotStateNG.InformationalSettings do
field(:controller_uuid, :string)
field(:controller_commit, :string, default: Project.commit())
field(:firmware_version, :string)
field(:firmware_configured, :boolean, default: false)
field(:node_name, :string)
field(:private_ip, :string)
field(:soc_temp, :integer)
@ -52,6 +53,7 @@ defmodule FarmbotCore.BotStateNG.InformationalSettings do
commit: informational_settings.controller_commit,
firmware_commit: informational_settings.firmware_commit,
firmware_version: informational_settings.firmware_version,
firmware_configured: informational_settings.firmware_configured,
node_name: informational_settings.node_name,
private_ip: informational_settings.private_ip,
soc_temp: informational_settings.soc_temp,
@ -84,6 +86,7 @@ defmodule FarmbotCore.BotStateNG.InformationalSettings do
:controller_commit,
:firmware_commit,
:firmware_version,
:firmware_configured,
:node_name,
:private_ip,
:soc_temp,

View File

@ -3,7 +3,7 @@ defmodule FarmbotCore.FirmwareSideEffects do
@behaviour FarmbotFirmware.SideEffects
require Logger
require FarmbotCore.Logger
alias FarmbotCore.{Asset, BotState, FirmwareEstopTimer, Leds}
alias FarmbotCore.{Asset, BotState, DepTracker, FirmwareEstopTimer, Leds}
@impl FarmbotFirmware.SideEffects
def handle_position(x: x, y: y, z: z) do
@ -111,6 +111,7 @@ defmodule FarmbotCore.FirmwareSideEffects do
@impl FarmbotFirmware.SideEffects
def handle_busy(busy) do
:ok = BotState.set_firmware_busy(busy)
DepTracker.register_service(:firmware, :busy)
end
@impl FarmbotFirmware.SideEffects
@ -118,6 +119,7 @@ defmodule FarmbotCore.FirmwareSideEffects do
_ = FirmwareEstopTimer.cancel_timer()
:ok = BotState.set_firmware_unlocked()
:ok = BotState.set_firmware_idle(idle)
DepTracker.register_service(:firmware, :idle)
end
@impl FarmbotFirmware.SideEffects
@ -125,6 +127,7 @@ defmodule FarmbotCore.FirmwareSideEffects do
_ = FirmwareEstopTimer.start_timer()
_ = Leds.yellow(:slow_blink)
:ok = BotState.set_firmware_locked()
DepTracker.register_service(:firmware, :locked)
end
@impl FarmbotFirmware.SideEffects
@ -163,6 +166,12 @@ defmodule FarmbotCore.FirmwareSideEffects do
should_log? && FarmbotCore.Logger.debug(3, "Firmware debug message: " <> message)
end
@impl FarmbotFirmware.SideEffects
def handle_configuration_complete() do
:ok = BotState.set_firmware_configured()
DepTracker.register_service(:firmware, :configured)
end
@impl FarmbotFirmware.SideEffects
def load_params do
conf = Asset.firmware_config()

View File

@ -118,6 +118,7 @@ defmodule FarmbotFirmware do
| :emergency_lock
defstruct [
:configured,
:transport,
:transport_pid,
:transport_ref,
@ -148,7 +149,8 @@ defmodule FarmbotFirmware do
current: nil | GCODE.t(),
vcr_fd: nil | File.io_device(),
reset: module(),
reset_pid: nil | pid()
reset_pid: nil | pid(),
configured: boolean()
}
@doc """
@ -259,6 +261,7 @@ defmodule FarmbotFirmware do
transport_args = Keyword.put(args, :handle_gcode, fun)
state = %State{
configured: false,
transport_pid: nil,
transport_ref: nil,
transport: transport,
@ -694,7 +697,10 @@ defmodule FarmbotFirmware do
# report_parameters_complete => goto(:configuration, :idle)
def handle_report({:report_parameters_complete, []}, %{status: status} = state)
when status in [:begin, :configuration] do
{:noreply, goto(state, :idle)}
Logger.debug("Firmware configuration complete")
new_state = %{state | configured: true}
_ = side_effects(new_state, :handle_configuration_complete, [])
{:noreply, goto(new_state, :idle)}
end
def handle_report(_, %{status: :no_config} = state) do

View File

@ -39,4 +39,6 @@ defmodule FarmbotFirmware.SideEffects do
@callback handle_input_gcode(GCODE.t()) :: any()
@callback handle_output_gcode(GCODE.t()) :: any()
@callback handle_debug_message([String.t()]) :: any()
@callback handle_configuration_complete() :: any()
end

View File

@ -164,4 +164,7 @@ defmodule FarmbotFirmware.StubSideEffects do
@impl SideEffects
def handle_debug_message(_), do: :noop
@impl SideEffects
def handle_configuration_complete(), do: :noop
end