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()

0 commit comments

Comments
 (0)