diff --git a/apps/zeus/lib/zeus/color_parsing.ex b/apps/lightning/lib/lightning/color_parsing.ex similarity index 68% rename from apps/zeus/lib/zeus/color_parsing.ex rename to apps/lightning/lib/lightning/color_parsing.ex index 7745ab1..a4a2820 100644 --- a/apps/zeus/lib/zeus/color_parsing.ex +++ b/apps/lightning/lib/lightning/color_parsing.ex @@ -1,4 +1,7 @@ -defmodule Zeus.ColorParsing do +defmodule Lightning.ColorParsing do + def get_color("Color: #" <> <> <> _), do: raw_hex + + def get_color(_), do: "FFFFFF" def parse_rgb_hex(rgb_value) do [r1, r2, g1, g2, b1, b2] = rgb_value |> String.codepoints |> Enum.take(-6) diff --git a/apps/lightning/lib/lightning/control.ex b/apps/lightning/lib/lightning/control.ex index 6bc8591..dd1de37 100644 --- a/apps/lightning/lib/lightning/control.ex +++ b/apps/lightning/lib/lightning/control.ex @@ -9,12 +9,14 @@ defmodule Lightning.Control do change_color(0, color, brightness) end - def change_color(ch, color, brightness) do - IO.puts renderer - renderer.render(ch, {brightness, [color]}) + def change_color(channel, color, brightness) do + IO.puts renderer() + IO.puts("Rendering #{inspect([color])} at brightness #{inspect(brightness)} to channel #{inspect(channel)}") + renderer().render(channel, {brightness, [color]}) end def renderer do - @renderer || Lightning.NeopixelStandin + # @renderer || Lightning.NeopixelStandin + Nerves.Neopixel end end diff --git a/apps/lightning/lib/lightning/neopixel_standin.ex b/apps/lightning/lib/lightning/neopixel_standin.ex index d45d1f0..8ce0a50 100644 --- a/apps/lightning/lib/lightning/neopixel_standin.ex +++ b/apps/lightning/lib/lightning/neopixel_standin.ex @@ -1,5 +1,6 @@ defmodule Lightning.NeopixelStandin do def render(channel, {brightness, color_array}) do IO.puts("Rendering #{inspect(color_array)} at brightness #{inspect(brightness)} to channel #{inspect(channel)}") + {:ok, ""} end end diff --git a/apps/lightning/mix.exs b/apps/lightning/mix.exs index d290722..74c8852 100644 --- a/apps/lightning/mix.exs +++ b/apps/lightning/mix.exs @@ -11,7 +11,7 @@ defmodule Lightning.Mixfile do elixir: "~> 1.3", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, - deps: deps] + deps: deps()] end # Configuration for the OTP application diff --git a/apps/zeus/test/color_parsing_test.exs b/apps/lightning/test/color_parsing_test.exs similarity index 62% rename from apps/zeus/test/color_parsing_test.exs rename to apps/lightning/test/color_parsing_test.exs index e272511..59abdbf 100644 --- a/apps/zeus/test/color_parsing_test.exs +++ b/apps/lightning/test/color_parsing_test.exs @@ -1,44 +1,45 @@ defmodule ColorParsingTest do use ExUnit.Case - doctest Zeus.ColorParsing + doctest Lightning.ColorParsing describe "parse_rgb_hex" do test "parses out three values" do assert "#000000" - |> Zeus.ColorParsing.parse_rgb_hex + |> Lightning.ColorParsing.parse_rgb_hex + |> Tuple.to_list |> Enum.count == 3 end test "converts hex numbers to integers" do assert "#000000" - |> Zeus.ColorParsing.parse_rgb_hex - == [0, 0, 0] + |> Lightning.ColorParsing.parse_rgb_hex + == {0, 0, 0} end test "converts other hex numbers" do assert "#ffaa11" - |> Zeus.ColorParsing.parse_rgb_hex - == [255, 170, 17] + |> Lightning.ColorParsing.parse_rgb_hex + == {255, 170, 17} end end describe "hex_to_number" do test "Converts a small hex number" do assert "00" - |> Zeus.ColorParsing.hex_to_number + |> Lightning.ColorParsing.hex_to_number == 0 end test "Converts a large hex number" do assert "FF" - |> Zeus.ColorParsing.hex_to_number + |> Lightning.ColorParsing.hex_to_number == 255 end test "is able to work with lower case numbers" do assert "aa" - |> Zeus.ColorParsing.hex_to_number + |> Lightning.ColorParsing.hex_to_number == 170 end end diff --git a/apps/the_eye/lib/the_eye.ex b/apps/the_eye/lib/the_eye.ex index 2dabee0..2dd6461 100644 --- a/apps/the_eye/lib/the_eye.ex +++ b/apps/the_eye/lib/the_eye.ex @@ -1,5 +1,6 @@ defmodule TheEye do use Application + alias Lightning.ColorParsing @kernel_module "brcmfmac" @interface :wlan0 @@ -13,7 +14,9 @@ defmodule TheEye do children = [ worker(Task, [fn -> init_kernel_modules() end], restart: :transient, id: Nerves.Init.KernelModules), worker(Task, [fn -> init_network() end], restart: :transient, id: Nerves.Init.Network), + worker(Task, [fn -> init_ntpd() end], restart: :transient, id: Nerves.Init.Ntpd), worker(Nerves.Neopixel, [neopixel_cfg, nil]), + worker(Task, [fn -> IO.puts("Starting Twitter Connection"); get_tweets('#cmm_storm') end], restart: :transient), ] # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html @@ -29,4 +32,25 @@ defmodule TheEye do def init_network() do Nerves.InterimWiFi.setup(@interface, @wifi_cfg) end + + def get_tweets(query) do + Process.sleep(10000) + IO.puts "get_tweets: #{query}" + ExTwitter.stream_filter(track: query) + |> Stream.map(fn(tweet) -> tweet.text end) + |> Stream.map(&(update_color(&1))) + |> Enum.to_list + end + + defp update_color(text) do + IO.puts "update_color: #{text}" + ColorParsing.get_color(text) + |> ColorParsing.parse_rgb_hex + |> Lightning.Control.change_color(150) + end + + def init_ntpd do + Process.sleep(8000) + System.cmd("ntpd", ["-q", "-p", "pool.ntp.org"]) + end end diff --git a/apps/the_eye/mix.exs b/apps/the_eye/mix.exs index 11fb9ba..abf8b5d 100644 --- a/apps/the_eye/mix.exs +++ b/apps/the_eye/mix.exs @@ -25,16 +25,18 @@ defmodule TheEye.Mixfile do # Type `mix help compile.app` for more information. def application do [mod: {TheEye, []}, - applications: [:logger, :nerves_interim_wifi, :nerves_neopixel, :lightning, :zeus]] + applications: [:logger, :nerves_interim_wifi, :nerves_ntp, :nerves_neopixel, :oauther, :extwitter, :lightning, :zeus]] end def deps do [ {:nerves, "~> 0.4.0"}, {:nerves_interim_wifi, "~> 0.1.0"}, + {:nerves_ntp, "~> 0.1.1"}, {:nerves_neopixel, "~> 0.3.0"}, + {:extwitter, "~> 0.8"}, {:lightning, in_umbrella: true}, - {:zeus, in_umbrella: true}, + {:zeus, in_umbrella: true} ] end @@ -45,7 +47,7 @@ defmodule TheEye.Mixfile do def aliases do ["deps.precompile": ["nerves.precompile", "deps.precompile"], "deps.loadpaths": ["deps.loadpaths", "nerves.loadpaths"], - "burn": ["compile", "firmware", "firmware.burn"]] + "burn": ["clean", "compile", "firmware", "firmware.burn"]] end end diff --git a/apps/zapdos/.gitignore b/apps/zapdos/.gitignore new file mode 100644 index 0000000..b6012c7 --- /dev/null +++ b/apps/zapdos/.gitignore @@ -0,0 +1,20 @@ +# The directory Mix will write compiled artifacts to. +/_build + +# If you run "mix test --cover", coverage assets end up here. +/cover + +# The directory Mix downloads your dependencies sources to. +/deps + +# Where 3rd-party dependencies like ExDoc output generated docs. +/doc + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez diff --git a/apps/zapdos/README.md b/apps/zapdos/README.md new file mode 100644 index 0000000..0a77962 --- /dev/null +++ b/apps/zapdos/README.md @@ -0,0 +1,19 @@ +# Zapdos + +**TODO: Add description** + +## Installation + +If [available in Hex](https://hex.pm/docs/publish), the package can be installed +by adding `zapdos` to your list of dependencies in `mix.exs`: + +```elixir +def deps do + [{:zapdos, "~> 0.1.0"}] +end +``` + +Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) +and published on [HexDocs](https://hexdocs.pm). Once published, the docs can +be found at [https://hexdocs.pm/zapdos](https://hexdocs.pm/zapdos). + diff --git a/apps/zapdos/config/config.exs b/apps/zapdos/config/config.exs new file mode 100644 index 0000000..152aa8e --- /dev/null +++ b/apps/zapdos/config/config.exs @@ -0,0 +1,32 @@ +# This file is responsible for configuring your application +# and its dependencies with the aid of the Mix.Config module. +use Mix.Config + +# This configuration is loaded before any dependency and is restricted +# to this project. If another project depends on this project, this +# file won't be loaded nor affect the parent project. For this reason, +# if you want to provide default values for your application for +# 3rd-party users, it should be done in your "mix.exs" file. + +# You can configure for your application as: +# +# config :zapdos, key: :value +# +# And access this configuration in your application as: +# +# Application.get_env(:zapdos, :key) +# +# Or configure a 3rd-party app: +# +# config :logger, level: :info +# + +# It is also possible to import configuration files, relative to this +# directory. For example, you can emulate configuration per environment +# by uncommenting the line below and defining dev.exs, test.exs and such. +# Configuration from the imported file will override the ones defined +# here (which is why it is important to import them last). +# +# import_config "#{Mix.env}.exs" + +config :lightning, renderer: Lightning.NeopixelStandin diff --git a/apps/zapdos/lib/zapdos.ex b/apps/zapdos/lib/zapdos.ex new file mode 100644 index 0000000..4c22099 --- /dev/null +++ b/apps/zapdos/lib/zapdos.ex @@ -0,0 +1,24 @@ +defmodule Zapdos do + alias Lightning.ColorParsing + + @moduledoc """ + Documentation for Zapdos. + """ + + def get_tweets(query) do + Process.sleep(10000) + IO.puts "get_tweets: #{query}" + ExTwitter.stream_filter(track: query) + |> Stream.map(fn(tweet) -> tweet.text end) + |> Stream.map(&(update_color(&1))) + |> Enum.to_list + end + + defp update_color(text) do + IO.puts "update_color: #{text}" + ColorParsing.get_color(text) + |> ColorParsing.parse_rgb_hex + |> Lightning.Control.change_color(150) + end + +end diff --git a/apps/zapdos/lib/zapdos/application.ex b/apps/zapdos/lib/zapdos/application.ex new file mode 100644 index 0000000..5c83fc0 --- /dev/null +++ b/apps/zapdos/lib/zapdos/application.ex @@ -0,0 +1,20 @@ +defmodule Zapdos.Application do + # See http://elixir-lang.org/docs/stable/elixir/Application.html + # for more information on OTP Applications + @moduledoc false + + use Application + + def start(_type, _args) do + import Supervisor.Spec, warn: false + + # Define workers and child supervisors to be supervised + children = [ + ] + + # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html + # for other strategies and supported options + opts = [strategy: :one_for_one, name: Zapdos.Supervisor] + Supervisor.start_link(children, opts) + end +end diff --git a/apps/zapdos/mix.exs b/apps/zapdos/mix.exs new file mode 100644 index 0000000..27b0e01 --- /dev/null +++ b/apps/zapdos/mix.exs @@ -0,0 +1,41 @@ +defmodule Zapdos.Mixfile do + use Mix.Project + + def project do + [app: :zapdos, + version: "0.1.0", + build_path: "../../_build", + config_path: "../../config/config.exs", + deps_path: "../../deps", + lockfile: "../../mix.lock", + elixir: "~> 1.3", + build_embedded: Mix.env == :prod, + start_permanent: Mix.env == :prod, + deps: deps()] + end + + # Configuration for the OTP application + # + # Type "mix help compile.app" for more information + def application do + # Specify extra applications you'll use from Erlang/Elixir + [applications: [:logger, :oauther, :extwitter], + mod: {Zapdos.Application, []}] + end + + # Dependencies can be Hex packages: + # + # {:my_dep, "~> 0.3.0"} + # + # Or git/path repositories: + # + # {:my_dep, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + # + # Type "mix help deps" for more examples and options + defp deps do + [ + {:extwitter, "~> 0.8"}, + {:lightning, in_umbrella: true} + ] + end +end diff --git a/apps/zapdos/test/test_helper.exs b/apps/zapdos/test/test_helper.exs new file mode 100644 index 0000000..869559e --- /dev/null +++ b/apps/zapdos/test/test_helper.exs @@ -0,0 +1 @@ +ExUnit.start() diff --git a/apps/zapdos/test/zapdos_test.exs b/apps/zapdos/test/zapdos_test.exs new file mode 100644 index 0000000..7d871ab --- /dev/null +++ b/apps/zapdos/test/zapdos_test.exs @@ -0,0 +1,8 @@ +defmodule ZapdosTest do + use ExUnit.Case + doctest Zapdos + + test "the truth" do + assert 1 + 1 == 2 + end +end diff --git a/apps/zeus/mix.exs b/apps/zeus/mix.exs index 600e276..2afdce4 100644 --- a/apps/zeus/mix.exs +++ b/apps/zeus/mix.exs @@ -13,7 +13,7 @@ defmodule Zeus.Mixfile do compilers: [:phoenix, :gettext] ++ Mix.compilers, build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, - aliases: aliases, + aliases: aliases(), deps: deps()] end diff --git a/apps/zeus/web/controllers/page_controller.ex b/apps/zeus/web/controllers/page_controller.ex index 01ecd53..669c337 100644 --- a/apps/zeus/web/controllers/page_controller.ex +++ b/apps/zeus/web/controllers/page_controller.ex @@ -1,6 +1,6 @@ defmodule Zeus.PageController do use Zeus.Web, :controller - alias Zeus.ColorParsing + alias Lightning.ColorParsing def index(conn, _params) do render conn, "index.html", color: nil, brightness: nil diff --git a/mix.lock b/mix.lock index df4a9d5..42351d6 100644 --- a/mix.lock +++ b/mix.lock @@ -2,6 +2,7 @@ "cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], []}, "distillery": {:hex, :distillery, "1.1.2", "4cf32ecc70ca7eecca9e52e111edf320bd78011050825863cd8bc7ffee686c5d", [:mix], []}, "elixir_make": {:hex, :elixir_make, "0.3.0", "285147fa943806eee82f6680b7b446b5569bcf3ee8328fa0a7c200ffc44fbaba", [:mix], []}, + "extwitter": {:hex, :extwitter, "0.8.2", "1b1b6842c6541ddfa468f1589b54c02a3b278b5ae74d6bed260655394d8cc7be", [:mix], [{:oauther, "~> 1.1", [hex: :oauther, optional: false]}, {:poison, "~> 2.0", [hex: :poison, optional: false]}]}, "fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], []}, "gettext": {:hex, :gettext, "0.13.1", "5e0daf4e7636d771c4c71ad5f3f53ba09a9ae5c250e1ab9c42ba9edccc476263", [:mix], []}, "mime": {:hex, :mime, "1.0.1", "05c393850524767d13a53627df71beeebb016205eb43bfbd92d14d24ec7a1b51", [:mix], []}, @@ -9,11 +10,13 @@ "nerves_interim_wifi": {:hex, :nerves_interim_wifi, "0.1.1", "88c65ced1440e96b954189ccfc8a55cb4575cb64a8725907c3e8a9900adb2a70", [:make, :mix], [{:elixir_make, "~> 0.3", [hex: :elixir_make, optional: false]}, {:nerves_network_interface, "~> 0.3.1", [hex: :nerves_network_interface, optional: false]}, {:nerves_wpa_supplicant, "~> 0.2.2", [hex: :nerves_wpa_supplicant, optional: false]}]}, "nerves_neopixel": {:hex, :nerves_neopixel, "0.3.0", "afd9c906896f0b39a2bea61cf01afe304d550bc74c789a5e872d64df5e1ae559", [:make, :mix], [{:elixir_make, "~> 0.3.0", [hex: :elixir_make, optional: false]}]}, "nerves_network_interface": {:hex, :nerves_network_interface, "0.3.3", "0a49e00f9f0bdb482e94d8e9885cf0a250ae04cc18d248d83bc184b8813ddda2", [:make, :mix], [{:elixir_make, "~> 0.3", [hex: :elixir_make, optional: false]}]}, + "nerves_ntp": {:hex, :nerves_ntp, "0.1.1", "fa1a1f5c325d00fc3d940d8f5deea98964c84e617c7370325989d64accfa698a", [:mix], []}, "nerves_system_br": {:hex, :nerves_system_br, "0.9.4", "5096a9dfec49d4663ccb94c4a4fe45885303fbf31108f7e9400369bdec94b5e7", [:mix], []}, "nerves_system_rpi3": {:hex, :nerves_system_rpi3, "0.10.0", "dc5c05e1caf13027aaa57b4142d128513d9c29acc3284cc984a6770592ed4b34", [:mix], [{:nerves, "~> 0.4.0", [hex: :nerves, optional: false]}, {:nerves_system_br, "~> 0.9.2", [hex: :nerves_system_br, optional: false]}, {:nerves_toolchain_arm_unknown_linux_gnueabihf, "~> 0.9.0", [hex: :nerves_toolchain_arm_unknown_linux_gnueabihf, optional: false]}]}, "nerves_toolchain_arm_unknown_linux_gnueabihf": {:hex, :nerves_toolchain_arm_unknown_linux_gnueabihf, "0.9.0", "5a1bca8c46776ad24c358ab58800ed470f91a3e294ac6eb8ffda0041954781e1", [:mix], [{:nerves, "~> 0.4.0", [hex: :nerves, optional: false]}, {:nerves_toolchain_ctng, "~> 0.8.0", [hex: :nerves_toolchain_ctng, optional: false]}]}, "nerves_toolchain_ctng": {:hex, :nerves_toolchain_ctng, "0.8.0", "6dff7ed51e1711c5f4da3d559bc528a8265e3dd950dda95f4d6832aed9dbe320", [:mix], []}, "nerves_wpa_supplicant": {:hex, :nerves_wpa_supplicant, "0.2.3", "2666b21bf0868f0d3b127930c3bacf59b178a0d015d308ae3985dcb7c1595870", [:make, :mix], [{:elixir_make, "~> 0.3", [hex: :elixir_make, optional: false]}]}, + "oauther": {:hex, :oauther, "1.1.0", "c9a56e200507ce64e069f5273143db0cddd7904cd5d1fe46920388a48f22441b", [:mix], []}, "phoenix": {:hex, :phoenix, "1.2.1", "6dc592249ab73c67575769765b66ad164ad25d83defa3492dc6ae269bd2a68ab", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, optional: false]}, {:plug, "~> 1.1", [hex: :plug, optional: false]}, {:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: false]}]}, "phoenix_html": {:hex, :phoenix_html, "2.9.3", "1b5a2122cbf743aa242f54dced8a4f1cc778b8bd304f4b4c0043a6250c58e258", [:mix], [{:plug, "~> 1.0", [hex: :plug, optional: false]}]}, "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.0.8", "4333f9c74190f485a74866beff2f9304f069d53f047f5fbb0fb8d1ee4c495f73", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2-rc", [hex: :phoenix, optional: false]}]},