Skip to content

Commit

Permalink
Merge pull request #605 from FarmBot/staging
Browse files Browse the repository at this point in the history
Fix settings sync syncing every fw param.
  • Loading branch information
ConnorRigby authored Jul 26, 2018
2 parents 2234a7c + 125253c commit bacdb21
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
# 6.4.5
* Fix Firmware syncing applying _every_ setting.

# 6.4.4
* Optimize AMQP connection.
* Sync PinBindings with the API.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.4.4
6.4.5
12 changes: 6 additions & 6 deletions lib/farmbot/bootstrap/settings_sync.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ defmodule Farmbot.Bootstrap.SettingsSync do
run(tries_left - 1)
else
try do
do_sync_fbos_configs()
do_sync_fw_configs()
do_sync_fbos_configs()
Logger.debug 1, "Synced Farmbot OS and Firmware settings with API"
:ok
rescue
Expand Down Expand Up @@ -182,8 +182,8 @@ defmodule Farmbot.Bootstrap.SettingsSync do
old_map = take_valid_fw(old_map)
new_map = take_valid_fw(new_map)
new_stuff = Map.new(new_map, fn({key, new_value}) ->
if old_map[key] !== new_value do
IO.puts "1 #{key} #{old_map[key]} !== #{new_value}"
if old_map[key] != new_value do
IO.puts "1 #{key} #{old_map[key]} != #{new_value}"
apply_to_config_storage key, new_value
{key, new_value}
else
Expand All @@ -193,8 +193,8 @@ defmodule Farmbot.Bootstrap.SettingsSync do

if Process.whereis(Farmbot.Firmware) do
Map.new(new_map, fn({param, new_value}) ->
if old_map[param] !== new_value do
IO.puts "2 #{param} #{old_map[param]} !== #{new_value}"
if old_map[param] != new_value do
IO.puts "2 #{param} #{old_map[param]} != #{new_value}"
Farmbot.Firmware.update_param(String.to_atom(param), new_value)
end
{param, get_config_value(:float, "hardware_params", param)}
Expand All @@ -219,7 +219,7 @@ defmodule Farmbot.Bootstrap.SettingsSync do
defp apply_to_config_storage(key, val)
when key in @firmware_keys do
if val do
Logger.success 2, "Updating FW param: #{key}: #{get_config_value(:float, "hardware_params", key)} => #{val / 1 || "null"}"
Logger.success 2, "Updating FW param: #{key}: #{get_config_value(:float, "hardware_params", key)} => #{val}"
update_config_value(:float, "hardware_params", key, val / 1)
else
Logger.warn 2, "Not allowing #{key} to be set to null"
Expand Down
11 changes: 7 additions & 4 deletions lib/farmbot/firmware/uart_handler/uart_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ defmodule Farmbot.Firmware.UartHandler do
defmodule State do
@moduledoc false
defstruct [
config_busy: false,
nerves: nil,
current_cmd: nil,
tty: nil,
Expand Down Expand Up @@ -125,6 +126,8 @@ defmodule Farmbot.Firmware.UartHandler do
end)

case state do
%State{config_busy: true} = state ->
{:noreply, [:busy], state}
%State{} = state ->
{:noreply, [], state}
_ -> state
Expand All @@ -137,7 +140,7 @@ defmodule Farmbot.Firmware.UartHandler do
# Restart the framing to pick up new changes.
UART.configure state.nerves, [framing: UART.Framing.None, active: false]
configure_uart(state.nerves, true)
state
%{state | config_busy: true}
end

defp handle_config({:config, "settings", "firmware_hardware", val}, state) do
Expand All @@ -147,8 +150,8 @@ defmodule Farmbot.Firmware.UartHandler do
UART.close(state.nerves)
UartHandler.Update.force_update_firmware(val)
open_tty(state.tty, state.nerves)
Farmbot.BotState.reset_sync_status
%{state | hw: val}
Farmbot.BotState.reset_sync_status()
%{state | hw: val, config_busy: true}
else
state
end
Expand Down Expand Up @@ -273,7 +276,7 @@ defmodule Farmbot.Firmware.UartHandler do
end

def handle_info({:nerves_uart, _, {_q, :done}}, state) do
{:noreply, [:done], %{state | current_cmd: nil}}
{:noreply, [:done], %{state | current_cmd: nil, config_busy: false}}
end

def handle_info({:nerves_uart, _, {_q, gcode}}, state) do
Expand Down

0 comments on commit bacdb21

Please sign in to comment.