Skip to content

Commit

Permalink
Merge pull request #619 from FarmBot/staging
Browse files Browse the repository at this point in the history
Flash firmware now clears eeprom
  • Loading branch information
ConnorRigby authored Aug 10, 2018
2 parents 8a0be62 + 837f069 commit 9e69e96
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# 6.4.9
* Add feature to save logs to sdcard for debugging.
* Fix bug causing long running Farmwares to fail.
* Make sure to clear eeprom before flashing Arduino firmware.
* Update Linux system layer.

# 6.4.8
Expand Down
10 changes: 2 additions & 8 deletions lib/farmbot/bot_state/transport/amqp/amqp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,13 @@ defmodule Farmbot.BotState.Transport.AMQP do
{:noreply, [], state}
else
case Poison.decode(payload) do
{:ok, %{"body" => nil}} ->
# If the settings were reset remotely, just set migrated to true,
# which will cause FBOS to download the defaults and apply them.
pl = %{"api_migrated" => true} |> Poison.encode!()
Farmbot.HTTP.put!("/api/fbos_config", pl)
Farmbot.Bootstrap.SettingsSync.run()
{:noreply, [], state}
{:ok, %{"body" => config}} ->
{:ok, %{"body" => %{"api_migrated" => true} = config}} ->
# Logger.info 1, "Got fbos config from amqp: #{inspect config}"
old = state.state_cache.configuration
updated = Farmbot.Bootstrap.SettingsSync.apply_fbos_map(old, config)
push_bot_state(state.chan, state.bot, %{state.state_cache | configuration: updated})
{:noreply, [], state}
_ -> {:noreply, [], state}
end
end
end
Expand Down
13 changes: 10 additions & 3 deletions lib/farmbot/firmware/uart_handler/update.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,21 @@ defmodule Farmbot.Firmware.UartHandler.Update do

# Farmduino
defp do_flash("F", uart, tty) do
avrdude("#{:code.priv_dir(:farmbot)}/eeprom_clear.ino.hex", uart, tty)
Process.sleep(1000)
avrdude("#{:code.priv_dir(:farmbot)}/farmduino.hex", uart, tty)
end

defp do_flash("G", uart, tty) do
avrdude("#{:code.priv_dir(:farmbot)}/eeprom_clear.ino.hex", uart, tty)
Process.sleep(1000)
avrdude("#{:code.priv_dir(:farmbot)}/farmduino_k14.hex", uart, tty)
end

# Anything else. (should always be "R")
defp do_flash(_, uart, tty) do
avrdude("#{:code.priv_dir(:farmbot)}/eeprom_clear.ino.hex", uart, tty)
Process.sleep(1000)
avrdude("#{:code.priv_dir(:farmbot)}/arduino_firmware.hex", uart, tty)
end

Expand All @@ -141,17 +147,18 @@ defmodule Farmbot.Firmware.UartHandler.Update do

def avrdude(fw_file, uart, tty) do
close(uart)
Logger.busy 3, "Starting avrdude."
Logger.busy 3, "Starting avrdude: #{fw_file}"
args = ~w"-q -q -patmega2560 -cwiring -P#{tty} -b#{@uart_speed} -D -V -Uflash:w:#{fw_file}:i"
opts = [stderr_to_stdout: true, into: IO.stream(:stdio, :line)]
res = System.cmd("avrdude", args, opts)
Process.sleep(1500) # wait to allow file descriptors to be closed.
case res do
{_, 0} ->
Logger.success 1, "Firmware flashed!"
Logger.success 1, "Firmware flashed! #{fw_file}"
:ok
{_, err_code} ->
Logger.error 1, "Failed to flash Firmware! #{err_code}"
Logger.error 1, "Failed to flash Firmware! #{fw_file} #{err_code}"
Farmbot.Firmware.Utils.replace_firmware_handler(Farmbot.Firmware.StubHandler)
:error
end
end
Expand Down
2 changes: 1 addition & 1 deletion scripts/flash_fw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ if [ -z $2 ]; then
exit 1
fi

avrdude -v -patmega2560 -cwiring -P$2 -b115200 -D -V -Uflash:w:./priv/$1.hex:i
avrdude -v -p atmega2560 -c wiring -P$2 -b 115200 -D -V -Uflash:w:./priv/$1.hex:i
7 changes: 1 addition & 6 deletions scripts/reset_fw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ fi
FW_TYPE=$1
TTY=$2
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if $DIR/flash_fw.sh clear_eeprom $TTY; then
if $DIR/flash_fw.sh blink $TTY; then
if $DIR/flash_fw.sh eeprom_clear.ino $TTY; then
$DIR/flash_fw.sh $FW_TYPE $TTY
else
echo "Failed to flash blink!"
exit 1
fi
else
echo "Failed to clear eeprom!"
exit 1
Expand Down

0 comments on commit 9e69e96

Please sign in to comment.