Skip to content

Commit e9f4bc1

Browse files
committed
Add docs
1 parent ead741b commit e9f4bc1

File tree

9 files changed

+103
-5
lines changed

9 files changed

+103
-5
lines changed

docs/.DS_Store

6 KB
Binary file not shown.

docs/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
site/

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

docs/make.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Documenter
2+
using SenseHat
3+
4+
makedocs(
5+
sitename = "SenseHat",
6+
format = Documenter.HTML(),
7+
modules = [SenseHat],
8+
pages = [
9+
"index.md",
10+
"API Docs" => "api.md"
11+
]
12+
)
13+
14+
# Documenter can also automatically deploy documentation to gh-pages.
15+
# See "Hosting Documentation" and deploydocs() in the Documenter manual
16+
# for more information.
17+
#=deploydocs(
18+
repo = "<repository url>"
19+
)=#

docs/src/api.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SenseHat API
2+
3+
```@index
4+
```
5+
6+
```@autodocs
7+
Modules = [SenseHat, SenseHat.Stick, SenseHat.LED, SenseHat.Sensors, SenseHat.Text]
8+
```

docs/src/index.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# SenseHat.jl
2+
3+
SenseHat.jl is a Julia library for interacting with the Raspberry Pi [Sense HAT](https://www.raspberrypi.org/products/sense-hat/).
4+
5+
SenseHat.jl requires the Raspbian `sense-hat` package:
6+
7+
```bash
8+
sudo apt-get update
9+
sudo apt-get install sense-hat
10+
sudo reboot
11+
```
12+
13+
## LED matrix
14+
15+
The main interface is the `led_matrix()` function, which creates an 8&times;8 array of RGB
16+
values (from [ColorTypes.jl](https://github.com/JuliaGraphics/ColorTypes.jl)) which is
17+
memory-mapped to the frame buffer of the LED matrix. `led_clear()` is a convenience
18+
function for resetting the LED matrix to black.
19+
20+
```julia
21+
using SenseHat
22+
using ColorTypes
23+
24+
const LED = led_matrix()
25+
26+
LED[:] = SenseHat.JULIA_LOGO
27+
sleep(3)
28+
led_clear()
29+
```
30+
31+
## Joystick
32+
33+
In the `Stick` module there is `readstick()` which will block until the joystick is
34+
manipulated, returning a `StickEvent`:
35+
36+
```julia
37+
using SenseHat
38+
39+
e = readstick()
40+
```
41+
42+
For querying within a loop, use a `Channel` to create a buffer of `StickEvent`.
43+
44+
```julia
45+
using SenseHat
46+
47+
c = Channel{StickEvent}(32)
48+
49+
@async while true
50+
put!(c, readstick())
51+
end
52+
```
53+
54+
## Sensors
55+
56+
`humidity()`, `temperature()` and `pressure()` will read values from the corresponding sensors.
57+
58+
The inertial measurement unit (IMU) is not yet supported, but is coming soon. In the meantime, you can use the [python library](https://pythonhosted.org/sense-hat/) via [PyCall.jl](https://github.com/JuliaPy/PyCall.jl).

src/led.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@ function _led_fb_device()
1717
end
1818
end
1919
catch e
20+
@warn("LED: Sense Hat not found.")
21+
return nothing
2022
end
21-
error("Sense Hat device not found.")
2223
end
2324

2425
const LED_FB_DEVICE_PATH = _led_fb_device()
2526
const LED_FB_DEVICE = Ref{IOStream}()
2627

2728
function __init__()
28-
LED_FB_DEVICE[] = open(LED_FB_DEVICE_PATH,"w+")
29+
if LED_FB_DEVICE_PATH != nothing
30+
LED_FB_DEVICE[] = open(LED_FB_DEVICE_PATH,"w+")
31+
end
2932
end
3033

3134
const U5 = Normed{UInt8,5}

src/sensors.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ const I2C_DEVICE = Ref{IOStream}()
77
const I2C_ADDR = Ref{UInt8}(0xff)
88

99
function __init__()
10-
I2C_DEVICE[] = open("/dev/i2c-1","r+")
11-
HTS221_calibrate()
10+
try
11+
I2C_DEVICE[] = open("/dev/i2c-1","r+")
12+
HTS221_calibrate()
13+
catch
14+
@warn("I2C: Sense Hat not found")
15+
end
1216
end
1317

1418
import ..ioctl

src/stick.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ function _stick_input_device()
1515
end
1616
end
1717
catch e
18+
@warn("STICK: Sense Hat not found.")
19+
return nothing
1820
end
19-
error("Sense Hat not found.")
21+
2022
end
2123

2224
const STICK_INPUT_DEVICE = _stick_input_device()

0 commit comments

Comments
 (0)