Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 8b0a2ab

Browse files
committed
documentation updates
2 parents 83c9af2 + ed33e62 commit 8b0a2ab

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ Nerves.Leds
22
===========
33
[![Build Status](https://travis-ci.org/nerves-project/nerves_io_led.svg?branch=master)](https://travis-ci.org/nerves-project/nerves_leds)
44

5-
Simple API to drive leds exposed by linux's `/sys/class/leds`.
5+
Simple API to drive leds exposed by linux `/sys/class/leds`.
6+
Designed for use with [nerves](http://nerves-project.org/),
7+
but works on any distribution of Linux that supports `/sys/class/leds`.
68

79
## Configuration
810

@@ -59,10 +61,9 @@ config :nerves_leds, states: [
5961
blip: [ trigger: "timer", delay_off: 1000, delay_on: 100 ]]
6062
```
6163

62-
See the linux documentation on `sys/class/leds` to understand the meaning of
64+
See the Linux documentation on `sys/class/leds` to understand the meaning of
6365
trigger, delay, brightness, and other settings.
6466

6567
## Limitations, Areas for Improvement
6668

67-
- linux only, requires `/sys/class/leds`
6869
- most but not all ``/sys/class/leds` features are currently implemented

lib/nerves_leds.ex

+56-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,56 @@ defmodule Nerves.Leds do
44
Handles LED blinking/handling in a configurable way, providing an
55
easy-to use interface to setting LEDs defined in `/sys/class/leds`.
66
7+
While an application could write directly to /sys/class/leds, the main advantage
8+
of using this module is to provide a layer of abstraction that allows easily
9+
defining application-specific led names and states, like this:
10+
11+
```elixir
12+
alias Nerves.Leds
13+
14+
Leds.set power: true # turn on the led we called "power"
15+
Leds.set power: :slowblink # make it blink slowly
16+
Leds.set connected: false, alert: :fastblink # set multiple LED states at once
17+
```
18+
19+
## Configuration
20+
21+
Use config.exs to create a friendly name that maps to an entry in
22+
`/sys/class/leds` that make sense for your application. An example for the Alix 2D boards:
23+
24+
```elixir
25+
# in your app's config/config.exs:
26+
config :nerves_leds, names: [
27+
power: "alix:1",
28+
connected: "alix:2",
29+
alert: "alix:3"
30+
]
31+
```
32+
33+
## Included states
34+
35+
In addition to `true` (on) and `false` (off) the following atoms provide predefined
36+
behaviors:
37+
38+
- `:slowblink` - turns on and off slowly (about twice a second)
39+
- `:fastblink` - turns on and off rapidly (about 7.5 times a second)
40+
- `:slowwink` - mostly on, but "winks off" once every second or so
41+
- `:hearbeat` - a heartbeat pattern
42+
43+
## Customizing states
44+
45+
The standard LED states are defined as `@predefined_states` near the top of
46+
`lib/nerves_leds.ex`. You can change or add to them using config.exs as
47+
follows:
48+
49+
```elixir
50+
config :nerves_leds, states: [
51+
fastblink: [ trigger: "timer", delay_off: 40, delay_on: 30 ],
52+
blip: [ trigger: "timer", delay_off: 1000, delay_on: 100 ]]
53+
```
54+
55+
See the Linux documentation on `sys/class/leds` to understand the meaning of
56+
trigger, delay, brightness, and other settings.
757
"""
858

959
@app :nerves_leds
@@ -23,13 +73,15 @@ defmodule Nerves.Leds do
2373
@led_states Dict.merge(Application.get_env(@app, :states, []), @predefined_states)
2474

2575
@doc """
26-
Set status of one or more leds, like this:
76+
Set one or more leds to one of the built-in or user-defined states
2777
28-
```
29-
Nerves.Leds.set power: true, error: fastblink
30-
```
78+
~~~elixir
79+
Nerves.Leds.set power: true, error: fastblink
80+
~~~
3181
82+
See the module overview for information about states and configuration.
3283
"""
84+
3385
@spec set(Keyword.T) :: true
3486
def set(settings) do
3587
Enum.each settings, &(set_keyed_state(&1))

mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule Nerves.Leds.Mixfile do
1616
docs: [
1717
source_ref: "v#{@version}", main: "Nerves.Leds",
1818
source_url: "https://github.com/nerves-project/nerves_leds",
19-
# main: "extra-readme",
19+
# main: "extra-readme",
2020
extras: [ "README.md", "CHANGELOG.md"] ]]
2121
end
2222

0 commit comments

Comments
 (0)