Skip to content

Commit aa29ac9

Browse files
authored
Merge pull request #2 from ElixirCLE/add-neopixels
Add neopixels
2 parents 8eec517 + 809d95b commit aa29ac9

36 files changed

+2056
-1320
lines changed

apps/lightning/.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps
9+
10+
# Where 3rd-party dependencies like ExDoc output generated docs.
11+
/doc
12+
13+
# If the VM crashes, it generates a dump, let's ignore it too.
14+
erl_crash.dump
15+
16+
# Also ignore archive artifacts (built via "mix archive.build").
17+
*.ez

apps/lightning/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Lightning
2+
3+
**TODO: Add description**
4+
5+
## Installation
6+
7+
If [available in Hex](https://hex.pm/docs/publish), the package can be installed as:
8+
9+
1. Add `lightning` to your list of dependencies in `mix.exs`:
10+
11+
```elixir
12+
def deps do
13+
[{:lightning, "~> 0.1.0"}]
14+
end
15+
```
16+
17+
2. Ensure `lightning` is started before your application:
18+
19+
```elixir
20+
def application do
21+
[applications: [:lightning]]
22+
end
23+
```
24+

apps/lightning/config/config.exs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This file is responsible for configuring your application
2+
# and its dependencies with the aid of the Mix.Config module.
3+
use Mix.Config
4+
5+
config :lightning, :channel0,
6+
pin: 18,
7+
count: 1
8+
9+
config :lightning, renderer: Lightning.NeopixelStandin

apps/lightning/lib/lightning.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defmodule Lightning do
2+
use Application
3+
4+
def start(_type, _args) do
5+
import Supervisor.Spec, warn: false
6+
7+
children = [
8+
]
9+
10+
opts = [strategy: :one_for_one, name: Lightning.Supervisor]
11+
Supervisor.start_link(children, opts)
12+
end
13+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule Lightning.Colors do
2+
3+
def red do {255, 0, 0} end
4+
def green do {0, 255, 0} end
5+
def blue do {0, 0, 255} end
6+
def off do {0, 0, 0} end
7+
def white do {255, 255, 255} end
8+
9+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
defmodule Lightning.Control do
2+
@renderer Application.get_env(:lightning, :renderer)
3+
4+
def change_color(color) do
5+
change_color(color, 125)
6+
end
7+
8+
def change_color(color, brightness) do
9+
change_color(0, color, brightness)
10+
end
11+
12+
def change_color(ch, color, brightness) do
13+
IO.puts renderer
14+
renderer.render(ch, {brightness, [color]})
15+
end
16+
17+
def renderer do
18+
@renderer || Lightning.NeopixelStandin
19+
end
20+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
defmodule Lightning.NeopixelStandin do
2+
def render(channel, {brightness, color_array}) do
3+
IO.puts("Rendering #{inspect(color_array)} at brightness #{inspect(brightness)} to channel #{inspect(channel)}")
4+
end
5+
end

apps/lightning/mix.exs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
defmodule Lightning.Mixfile do
2+
use Mix.Project
3+
4+
def project do
5+
[app: :lightning,
6+
version: "0.1.0",
7+
build_path: "../../_build",
8+
config_path: "../../config/config.exs",
9+
deps_path: "../../deps",
10+
lockfile: "../../mix.lock",
11+
elixir: "~> 1.3",
12+
build_embedded: Mix.env == :prod,
13+
start_permanent: Mix.env == :prod,
14+
deps: deps]
15+
end
16+
17+
# Configuration for the OTP application
18+
#
19+
# Type "mix help compile.app" for more information
20+
def application do
21+
[applications: [:logger],
22+
mod: {Lightning, []}]
23+
end
24+
25+
# Dependencies can be Hex packages:
26+
#
27+
# {:mydep, "~> 0.3.0"}
28+
#
29+
# Or git/path repositories:
30+
#
31+
# {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
32+
#
33+
# To depend on another app inside the umbrella:
34+
#
35+
# {:myapp, in_umbrella: true}
36+
#
37+
# Type "mix help deps" for more examples and options
38+
defp deps do
39+
[]
40+
end
41+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defmodule LightningTest do
2+
use ExUnit.Case
3+
doctest Lightning
4+
5+
test "the truth" do
6+
assert 1 + 1 == 2
7+
end
8+
end

apps/lightning/test/test_helper.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ExUnit.start()

apps/the_eye/config/config.exs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@
66
use Mix.Config
77

88
config :the_eye, :wlan0,
9-
ssid: "CoverMyMeds-Guest",
109
key_mgmt: :"WPA-PSK",
10+
ssid: "CoverMyMeds-Guest",
1111
psk: "technology"
1212

13+
config :zeus, Zeus.Endpoint,
14+
http: [port: 80],
15+
url: [host: "localhost", port: 80],
16+
secret_key_base: "Q8bCLHDz9QAcJ8ZRA2fWwUWSbglcYv3YxiLhBB2ZlRoqJydRyIWrtkllBPXtdaPp",
17+
root: Path.dirname(__DIR__),
18+
server: true,
19+
render_errors: [accepts: ~w(html json)],
20+
pubsub: [name: Nerves.PubSub]
21+
1322
config :nerves_interim_wifi,
1423
regulatory_domain: "US"
1524

@@ -18,8 +27,8 @@ config :logger, level: :debug
1827
config :nerves, :firmware,
1928
rootfs_additions: "config/rootfs-additions"
2029

21-
# Import target specific config. This must remain at the bottom
22-
# of this file so it overrides the configuration defined above.
23-
# Uncomment to use target specific configurations
30+
config :lightning, :channel0,
31+
pin: 18,
32+
count: 1
2433

25-
# import_config "#{Mix.Project.config[:target]}.exs"
34+
config :lightning, renderer: Nerves.Neopixel

apps/the_eye/lib/the_eye.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ defmodule TheEye do
77

88
def start(_type, _args) do
99
import Supervisor.Spec, warn: false
10+
neopixel_cfg = Application.get_env(:lightning, :channel0)
1011

1112
# Define workers and child supervisors to be supervised
1213
children = [
1314
worker(Task, [fn -> init_kernel_modules() end], restart: :transient, id: Nerves.Init.KernelModules),
14-
worker(Task, [fn -> init_network() end], restart: :transient, id: Nerves.Init.Network)
15+
worker(Task, [fn -> init_network() end], restart: :transient, id: Nerves.Init.Network),
16+
worker(Nerves.Neopixel, [neopixel_cfg, nil]),
1517
]
1618

17-
1819
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
1920
# for other strategies and supported options
2021
opts = [strategy: :one_for_one, name: TheEye.Supervisor]

apps/the_eye/mix.exs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ defmodule TheEye.Mixfile do
2525
# Type `mix help compile.app` for more information.
2626
def application do
2727
[mod: {TheEye, []},
28-
applications: [:logger, :nerves_interim_wifi, :zeus]]
28+
applications: [:logger, :nerves_interim_wifi, :nerves_neopixel, :lightning, :zeus]]
2929
end
3030

3131
def deps do
32-
[{:nerves, "~> 0.4.0"},
33-
{:nerves_interim_wifi, "~> 0.1.0"},
34-
{:zeus, in_umbrella: true}
32+
[
33+
{:nerves, "~> 0.4.0"},
34+
{:nerves_interim_wifi, "~> 0.1.0"},
35+
{:nerves_neopixel, "~> 0.3.0"},
36+
{:lightning, in_umbrella: true},
37+
{:zeus, in_umbrella: true},
3538
]
3639
end
3740

@@ -42,7 +45,7 @@ defmodule TheEye.Mixfile do
4245
def aliases do
4346
["deps.precompile": ["nerves.precompile", "deps.precompile"],
4447
"deps.loadpaths": ["deps.loadpaths", "nerves.loadpaths"],
45-
"burn": ["compile", "firmware", "firmware.burn"]]
48+
"burn": ["compile", "firmware", "firmware.burn"]]
4649
end
4750

4851
end

apps/zeus/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
# Generated on crash by the VM
88
erl_crash.dump
99

10+
# Static artifacts
11+
/node_modules
12+
13+
# Since we are building assets from web/static,
14+
# we ignore priv/static. You may want to comment
15+
# this depending on your deployment strategy.
16+
/priv/static/
17+
1018
# The config/prod.secret.exs file by default contains sensitive
1119
# data and you should not commit it into version control.
1220
#

apps/zeus/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
To start your Phoenix app:
44

55
* Install dependencies with `mix deps.get`
6+
* Install Node.js dependencies with `npm install`
67
* Start Phoenix endpoint with `mix phoenix.server`
78

89
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.

apps/zeus/brunch-config.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
exports.config = {
2+
// See http://brunch.io/#documentation for docs.
3+
files: {
4+
javascripts: {
5+
joinTo: "js/app.js"
6+
7+
// To use a separate vendor.js bundle, specify two files path
8+
// http://brunch.io/docs/config#-files-
9+
// joinTo: {
10+
// "js/app.js": /^(web\/static\/js)/,
11+
// "js/vendor.js": /^(web\/static\/vendor)|(deps)/
12+
// }
13+
//
14+
// To change the order of concatenation of files, explicitly mention here
15+
// order: {
16+
// before: [
17+
// "web/static/vendor/js/jquery-2.1.1.js",
18+
// "web/static/vendor/js/bootstrap.min.js"
19+
// ]
20+
// }
21+
},
22+
stylesheets: {
23+
joinTo: "css/app.css",
24+
order: {
25+
after: ["web/static/css/app.css"] // concat app.css last
26+
}
27+
},
28+
templates: {
29+
joinTo: "js/app.js"
30+
}
31+
},
32+
33+
conventions: {
34+
// This option sets where we should place non-css and non-js assets in.
35+
// By default, we set this to "/web/static/assets". Files in this directory
36+
// will be copied to `paths.public`, which is "priv/static" by default.
37+
assets: /^(web\/static\/assets)/
38+
},
39+
40+
// Phoenix paths configuration
41+
paths: {
42+
// Dependencies and current project directories to watch
43+
watched: [
44+
"web/static",
45+
"test/static"
46+
],
47+
48+
// Where to compile files to
49+
public: "priv/static"
50+
},
51+
52+
// Configure your plugins
53+
plugins: {
54+
babel: {
55+
// Do not use ES6 compiler in vendor code
56+
ignore: [/web\/static\/vendor/]
57+
}
58+
},
59+
60+
modules: {
61+
autoRequire: {
62+
"js/app.js": ["web/static/js/app"]
63+
}
64+
},
65+
66+
npm: {
67+
enabled: true
68+
}
69+
};

apps/zeus/config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use Mix.Config
88
# Configures the endpoint
99
config :zeus, Zeus.Endpoint,
1010
url: [host: "localhost"],
11-
secret_key_base: "Gh3ofmtXIMgiUccNZVpQxZg5vYGzXKnNhH00/9xxB6O1JwIKkB8vifQWz+ODz4S/",
11+
secret_key_base: "Y+UM3Xb7PBo+7rGmSxILcUhFIf4eGRGTN2eCoFXzZ5h8Q+3fZWDL+adFoNkxHhbS",
1212
render_errors: [view: Zeus.ErrorView, accepts: ~w(html json)],
1313
pubsub: [name: Zeus.PubSub,
1414
adapter: Phoenix.PubSub.PG2]

apps/zeus/config/dev.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ use Mix.Config
99
config :zeus, Zeus.Endpoint,
1010
http: [port: 4000],
1111
debug_errors: true,
12-
code_reloader: false,
12+
code_reloader: true,
1313
check_origin: false,
14-
watchers: []
14+
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin",
15+
cd: Path.expand("../", __DIR__)]]
1516

1617

1718
# Watch static and templates for browser reloading.

apps/zeus/config/prod.exs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use Mix.Config
1212
# manifest is generated by the mix phoenix.digest task
1313
# which you typically run after static files are built.
1414
config :zeus, Zeus.Endpoint,
15-
http: [port: {:system, "PORT"}],
15+
http: [port: 80],
1616
url: [host: "example.com", port: 80],
1717
cache_static_manifest: "priv/static/manifest.json"
1818

@@ -55,10 +55,6 @@ config :logger, level: :info
5555
#
5656
# config :zeus, Zeus.Endpoint, server: true
5757
#
58-
# You will also need to set the application root to `.` in order
59-
# for the new static assets to be served after a hot upgrade:
60-
#
61-
# config :zeus, Zeus.Endpoint, root: "."
6258

6359
# Finally import the config/prod.secret.exs
6460
# which should be versioned separately.

apps/zeus/lib/zeus/color_parsing.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule Zeus.ColorParsing do
22

33
def parse_rgb_hex(rgb_value) do
44
[r1, r2, g1, g2, b1, b2] = rgb_value |> String.codepoints |> Enum.take(-6)
5-
[hex_to_number(r1 <> r2), hex_to_number(g1 <> g2), hex_to_number(b1 <> b2)]
5+
{hex_to_number(r1 <> r2), hex_to_number(g1 <> g2), hex_to_number(b1 <> b2)}
66
end
77

88
def hex_to_number(hex_value) do

apps/zeus/lib/zeus/endpoint.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ defmodule Zeus.Endpoint do
3636
plug Plug.Session,
3737
store: :cookie,
3838
key: "_zeus_key",
39-
signing_salt: "wxsbw8Vg"
39+
signing_salt: "X8voisJK"
4040

4141
plug Zeus.Router
4242
end

0 commit comments

Comments
 (0)