diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..20d749c --- /dev/null +++ b/Makefile @@ -0,0 +1,72 @@ +.PHONY: dev prod cleandev cleanprod compile release publish docs test run + +MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) +APP_NAME := $(notdir $(patsubst %/,%,$(dir $(MKFILE_PATH)))) +VERSION_FILE := $(dir $(MKFILE_PATH))/VERSION +VERSION := $(shell sed 's/^ *//;s/ *$$//' $(VERSION_FILE)) +LOG_PREFIX = '${APP_NAME} | ${MIX_ENV}:' + +dev: export MIX_ENV = dev +dev: compile + @echo MAKE DONE: $@ + +prod: export MIX_ENV = prod +prod: git-status-test cleanprod compile + @echo MAKE DONE: $@ + +compile: + @echo ${LOG_PREFIX} getting deps + @mix deps.get 1>/dev/null + @echo ${LOG_PREFIX} compiling deps + @mix deps.compile 1>/dev/null + @echo ${LOG_PREFIX} compiling application + @mix compile + @echo MAKE DONE: $@ + +cleandev: export MIX_ENV = dev +cleandev: + @echo ${LOG_PREFIX} cleaning + @rm -rf _build/dev deps + @echo MAKE DONE: $@ + +cleanprod: export MIX_ENV = prod +cleanprod: + @echo ${LOG_PREFIX} cleaning + @rm -rf _build/prod deps + @echo MAKE DONE: $@ + +release: export MIX_ENV = prod +release: prod + @echo ${LOG_PREFIX} creating release + @mix release --env=prod + @echo MAKE DONE: $@ + +publish: test docs prod + @echo ${LOG_PREFIX} tagging with current version: $(VERSION) + @git tag -a "v$(VERSION)" -m "version $(VERSION)" + @echo ${LOG_PREFIX} pushing repository to origin + @git push + @echo ${LOG_PREFIX} pushing tag to origin + @git push origin "v$(VERSION)" + @echo ${LOG_PREFIX} publishing version $(VERSION) to hex + @mix hex.publish + @echo MAKE DONE: $@ + +docs: git-status-test + @echo ${LOG_PREFIX} updating documentation + @mix docs 1>/dev/null + @echo MAKE DONE: $@ + +run: + iex -S mix + +test: + @echo ${LOG_PREFIX} running tests + @mix test + @echo MAKE DONE: $@ + +git-status-test: + @test -z "$(shell git status -s 2>&1)" \ + && echo "Git repo is clean" \ + || (echo "Failed: uncommitted changes in git repo" && exit 1) + diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..0ea3a94 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.2.0 diff --git a/lib/exred_node_picar.ex b/lib/exred_node_picar.ex index 2b78ff4..56746ee 100644 --- a/lib/exred_node_picar.ex +++ b/lib/exred_node_picar.ex @@ -31,63 +31,50 @@ defmodule Exred.Node.Picar do } @ui_attributes %{left_icon: "directions_car"} - - alias Exred.Scheduler.DaemonNodeSupervisor alias Exred.Node.Picar.FrontWheels alias Exred.Node.Picar.RearWheels - - use Exred.Library.NodePrototype - require Logger - + use Exred.NodePrototype @impl true - def node_init(state) do - children = [ + def daemon_child_specs(config) do + [ %{ id: I2C, start: {ElixirALE.I2C, :start_link, [@i2c_device, @i2c_address, [name: :i2c]]} - #start: {ElixirALE.I2C, :start_link, [state.config.i2c_device.value, state.config.i2c_address.value, [name: :i2c]]} }, Exred.Node.Picar.PWM, Exred.Node.Picar.RearWheels, Exred.Node.Picar.FrontWheels ] - - # start children - Enum.each children, fn(child) -> - case DaemonNodeSupervisor.start_child(child) do - {:ok, _pid} -> :ok - {:error, {:already_started, _pid}} -> :ok - {:error, other} -> - event = "notification" - debug_data = %{msg: "Could not initialize " <> @name} - event_msg = %{node_id: state.node_id, node_name: @name, debug_data: debug_data} - EventChannelClient.broadcast event, event_msg - end - end - - state end @impl true def handle_msg(msg, state) do case msg.payload do "stop" -> - RearWheels.stop + RearWheels.stop() + {"speed", speed} -> RearWheels.speed(speed) + {"left", angle} -> - FrontWheels.left angle + FrontWheels.left(angle) + {"right", angle} -> - FrontWheels.right angle - "straight" -> - FrontWheels.straight + FrontWheels.right(angle) + + "straight" -> + FrontWheels.straight() + _ -> - Logger.warn "UNHANDLED MSG node: #{state.node_id} #{get_in(state.config, [:name, :value])} msg: #{inspect msg}" + Logger.warn( + "UNHANDLED MSG node: #{state.node_id} #{get_in(state.config, [:name, :value])} msg: #{ + inspect(msg) + }" + ) end + {nil, state} end - end - diff --git a/mix.exs b/mix.exs index 07faf04..acef9e2 100644 --- a/mix.exs +++ b/mix.exs @@ -2,11 +2,12 @@ defmodule Exred.Node.Picar.MixProject do use Mix.Project @description "Exred node to control a SunFounder PiCar" + @version File.read!("VERSION") |> String.trim() def project do [ app: :exred_node_picar, - version: "0.1.0", + version: @version, elixir: "~> 1.6", start_permanent: Mix.env() == :prod, deps: deps(), @@ -25,9 +26,9 @@ defmodule Exred.Node.Picar.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:ex_doc, "~> 0.18.0", only: :dev, runtime: false}, - {:exred_library, "~> 0.1.11"}, {:elixir_ale, "~> 1.0"}, + {:exred_nodeprototype, "~> 0.2"}, + {:ex_doc, "~> 0.19.0", only: :dev, runtime: false} ] end @@ -36,11 +37,10 @@ defmodule Exred.Node.Picar.MixProject do licenses: ["MIT"], maintainers: ["Zsolt Keszthelyi"], links: %{ - "GitHub" => "https://github.com/exredorg/exred_node_picar", + "GitHub" => "https://github.com/exredorg/exred_node_picar.git", "Exred" => "http://exred.org" }, - files: ["lib", "mix.exs", "README.md", "LICENSE"] + files: ["lib", "mix.exs", "README.md", "LICENSE", "VERSION"] } end - end diff --git a/mix.lock b/mix.lock index 08e8ca2..9d4a10b 100644 --- a/mix.lock +++ b/mix.lock @@ -3,13 +3,17 @@ "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"}, "db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, "decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"}, - "earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"}, + "earmark": {:hex, :earmark, "1.3.0", "17f0c38eaafb4800f746b457313af4b2442a8c2405b49c645768680f900be603", [:mix], [], "hexpm"}, "elixir_ale": {:hex, :elixir_ale, "1.1.0", "06e77697fa0bd7aff5f9040d8be8ba7947e5833de2a12d1a25f54332556b4e90", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"}, "elixir_make": {:hex, :elixir_make, "0.4.2", "332c649d08c18bc1ecc73b1befc68c647136de4f340b548844efc796405743bf", [:mix], [], "hexpm"}, - "ex_doc": {:hex, :ex_doc, "0.18.4", "4406b8891cecf1352f49975c6d554e62e4341ceb41b9338949077b0d4a97b949", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.19.1", "519bb9c19526ca51d326c060cb1778d4a9056b190086a8c6c115828eaccea6cf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.7", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, "exred_library": {:hex, :exred_library, "0.1.11", "15ee81546450b55ed45908113b0fb0cf844b2ddeeeee3bc85428b69a5ecffed8", [:mix], [{:conform, "~> 2.2", [hex: :conform, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.4", [hex: :postgrex, repo: "hexpm", optional: false]}, {:uuid, "~> 1.1", [hex: :uuid, repo: "hexpm", optional: false]}], "hexpm"}, + "exred_nodeprototype": {:hex, :exred_nodeprototype, "0.2.0", "560e5ccddabadc27e76ce0429cd8909fb2c8689df6bd891753e7659ebc3317d0", [:mix], [], "hexpm"}, "jason": {:hex, :jason, "1.1.1", "d3ccb840dfb06f2f90a6d335b536dd074db748b3e7f5b11ab61d239506585eb2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, + "makeup": {:hex, :makeup, "0.5.6", "da47b331b1fe0a5f0380cc3a6967200eac5e1daaa9c6bff4b0310b3fcc12b98f", [:mix], [{:nimble_parsec, "~> 0.4.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.10.0", "0f09c2ddf352887a956d84f8f7e702111122ca32fbbc84c2f0569b8b65cbf7fa", [:mix], [{:makeup, "~> 0.5.5", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, "neotoma": {:hex, :neotoma, "1.7.3", "d8bd5404b73273989946e4f4f6d529e5c2088f5fa1ca790b4dbe81f4be408e61", [:rebar], [], "hexpm"}, + "nimble_parsec": {:hex, :nimble_parsec, "0.4.0", "ee261bb53214943679422be70f1658fff573c5d0b0a1ecd0f18738944f818efe", [:mix], [], "hexpm"}, "postgrex": {:hex, :postgrex, "0.13.5", "3d931aba29363e1443da167a4b12f06dcd171103c424de15e5f3fc2ba3e6d9c5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"}, "uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm"}, } diff --git a/test/exred_node_picar_test.exs b/test/exred_node_picar_test.exs index 78e8311..c568375 100644 --- a/test/exred_node_picar_test.exs +++ b/test/exred_node_picar_test.exs @@ -1,8 +1,4 @@ defmodule Exred.Node.PicarTest do use ExUnit.Case doctest Exred.Node.Picar - - test "greets the world" do - assert Exred.Node.Picar.hello() == :world - end end