Skip to content

Commit dc1a38d

Browse files
authored
Merge pull request #5 from Ellipse0934/master
Update for Julia 1.0
2 parents 6d79686 + 6865209 commit dc1a38d

File tree

10 files changed

+137
-30
lines changed

10 files changed

+137
-30
lines changed

Manifest.toml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
[[Base64]]
2+
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
3+
4+
[[ColorTypes]]
5+
deps = ["FixedPointNumbers", "Random", "Test"]
6+
git-tree-sha1 = "f73b0e10f2a5756de7019818a41654686da06b09"
7+
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
8+
version = "0.7.5"
9+
10+
[[Colors]]
11+
deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Pkg", "Printf", "Reexport", "Test"]
12+
git-tree-sha1 = "8c89e0a9a583954eae3efcf6a531e51c02b38cee"
13+
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
14+
version = "0.9.4"
15+
16+
[[Dates]]
17+
deps = ["Printf"]
18+
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
19+
20+
[[Distributed]]
21+
deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"]
22+
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
23+
24+
[[FixedPointNumbers]]
25+
deps = ["Pkg", "Test"]
26+
git-tree-sha1 = "b8045033701c3b10bf2324d7203404be7aef88ba"
27+
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
28+
version = "0.5.3"
29+
30+
[[InteractiveUtils]]
31+
deps = ["LinearAlgebra", "Markdown"]
32+
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
33+
34+
[[LibGit2]]
35+
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
36+
37+
[[Libdl]]
38+
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
39+
40+
[[LinearAlgebra]]
41+
deps = ["Libdl"]
42+
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
43+
44+
[[Logging]]
45+
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
46+
47+
[[Markdown]]
48+
deps = ["Base64"]
49+
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
50+
51+
[[Mmap]]
52+
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
53+
54+
[[Pkg]]
55+
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
56+
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
57+
58+
[[Printf]]
59+
deps = ["Unicode"]
60+
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
61+
62+
[[REPL]]
63+
deps = ["InteractiveUtils", "Markdown", "Sockets"]
64+
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
65+
66+
[[Random]]
67+
deps = ["Serialization"]
68+
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
69+
70+
[[Reexport]]
71+
deps = ["Pkg"]
72+
git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0"
73+
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
74+
version = "0.2.0"
75+
76+
[[SHA]]
77+
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
78+
79+
[[Serialization]]
80+
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
81+
82+
[[Sockets]]
83+
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
84+
85+
[[Test]]
86+
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
87+
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
88+
89+
[[UUIDs]]
90+
deps = ["Random"]
91+
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
92+
93+
[[Unicode]]
94+
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

Project.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name = "SenseHat"
2+
uuid = "0dbe55a1-025c-5c9b-ab45-55492d058cfb"
3+
version = "0.1.0"
4+
5+
[deps]
6+
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
7+
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
8+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
9+
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
10+
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"

src/LPS25H.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ function LPS25H_pressure()
2020
smbus_read(CTRL_REG2) == 0 && break # check if finished
2121
end
2222

23-
pressure = (Int32(smbus_read(0x2a)) << 16 | Int16(smbus_read(0x29)) << 8 | smbus_read(0x28)) / 4096
23+
pressure = (UInt64.(smbus_read(0x2a)) << 16 |
24+
UInt64.(smbus_read(0x29)) << 8 |
25+
UInt64.(smbus_read(0x28)))/4096.0
2426

2527
smbus_write(CTRL_REG1, 0x00) # power down
2628
return pressure
2729
end
2830

2931
"""
30-
HTS221_temperature()
32+
LPS25H_temperature()
3133
3234
The temperature (in °C) from the LPS25H sensor.
3335
"""

src/ioctl.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A wrapper around the unix `ioctl` function:
88
- `request` is a request code
99
1010
- `arg` is either an integer (which will be passed as a `Cint`), or a buffer (which will
11-
be passed as a `Ptr{Void}`).
11+
be passed as a `Ptr{nothing}`).
1212
1313
Will throw a `SystemError` if an error occurs. Otherwise returns a `Cint` (which is
1414
typically, though not always, 0).
@@ -25,7 +25,7 @@ function ioctl(fd::Cint, request::Integer, arg::Integer)
2525
return ret
2626
end
2727
function ioctl(fd::Cint, request::Integer, arg)
28-
ret = ccall(:ioctl, Cint, (Cint, Culong, Ptr{Void}...), fd, request, arg)
28+
ret = ccall(:ioctl, Cint, (Cint, Culong, Ptr{Cvoid}...), fd, request, arg)
2929
if ret < 0
3030
throw(SystemError("ioctl error"))
3131
end

src/led.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ module LED
22

33
import ..ioctl
44

5-
export led_matrix, RGB565, led_clear
5+
export led_matrix, RGB565, led_clear, @colorant_str
66

7-
using ColorTypes, FixedPointNumbers
7+
using Colors, ColorTypes, FixedPointNumbers, Dates, Mmap
88

99
function _led_fb_device()
1010
try
1111
for devname in readdir("/sys/class/graphics")
1212
sysfname = joinpath("/sys/class/graphics",devname,"name")
1313
if startswith(devname, "fb") && isfile(sysfname)
14-
if startswith(readstring(sysfname),"RPi-Sense FB")
14+
if startswith(readline(sysfname),"RPi-Sense FB")
1515
return joinpath("/dev",devname)
1616
end
1717
end
@@ -28,12 +28,10 @@ function __init__()
2828
LED_FB_DEVICE[] = open(LED_FB_DEVICE_PATH,"w+")
2929
end
3030

31-
32-
3331
const U5 = Normed{UInt8,5}
3432
const U6 = Normed{UInt8,6}
3533

36-
immutable RGB565 <: AbstractRGB{Normed{UInt8, 8}}
34+
struct RGB565 <: AbstractRGB{Normed{UInt8, 8}}
3735
data::UInt16
3836
end
3937

@@ -43,15 +41,15 @@ function RGB565(r::U5, g::U6, b::U5)
4341
(UInt16(reinterpret(b))) )
4442
end
4543

46-
RGB565(r::Real, g::Real, b::Real) =
44+
RGB565(r::Real, g::Real, b::Real) =
4745
RGB565(convert(U5,r), convert(U6,g), convert(U5,b))
4846
RGB565(c::Union{Color,Colorant}) = RGB565(red(c), green(c), blue(c))
4947

5048
ColorTypes.red(c::RGB565) = U5(c.data >> 11, Val{true})
5149
ColorTypes.green(c::RGB565) = U6((c.data >> 5) & 0x3f, Val{true})
5250
ColorTypes.blue(c::RGB565) = U5(c.data & 0x1f, Val{true})
5351

54-
ColorTypes.ccolor{Csrc<:Colorant}(::Type{RGB565}, ::Type{Csrc}) = RGB565
52+
ColorTypes.ccolor(::Type{RGB565}, ::Type{Csrc}) where {Csrc <: Colorant} = RGB565
5553
ColorTypes.base_color_type(::Type{RGB565}) = RGB565
5654

5755

@@ -138,7 +136,8 @@ end
138136
Sets the SenseHat LED matrix to all black.
139137
"""
140138
function led_clear()
141-
led_matrix()[:] = RGB565(0,0,0)
139+
led_matrix()[:] .= RGB565(0,0,0)
140+
return
142141
end
143142

144143
end # module

src/smbus.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const I2C_SMBUS_BYTE_DATA = 0x02
1010
const I2C_SLAVE = 0x0703
1111
const I2C_SMBUS = 0x0720
1212

13-
immutable SMBusData
13+
struct SMBusData
1414
read_write ::UInt8
1515
command ::UInt8
1616
size ::UInt32

src/stick.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ module Stick
22

33
export StickEvent, readstick, sticktask
44

5+
using Dates
6+
57
function _stick_input_device()
68
try
79
for devname in readdir("/sys/class/input")
810
sysfname = joinpath("/sys/class/input",devname,"device","name")
911
if startswith(devname, "event") && isfile(sysfname)
10-
if startswith(readstring(sysfname),"Raspberry Pi Sense HAT Joystick")
12+
if startswith(readline(sysfname),"Raspberry Pi Sense HAT Joystick")
1113
return joinpath("/dev/input",devname)
1214
end
1315
end
@@ -30,7 +32,7 @@ const EV_KEY = Cushort(0x01)
3032
3133
The raw data format from the input device. This is based on the struct specification from https://github.com/RPi-Distro/python-sense-hat/blob/ec8c96118d5eb58488c4ff6091cd373117e6ce08/sense_hat/stick.py#L41.
3234
"""
33-
immutable StickEventRaw
35+
struct StickEventRaw
3436
tv_sec::Clong
3537
tv_usec::Clong
3638
ev_type::Cushort
@@ -53,15 +55,15 @@ The data from a joystick event. The type contains the following fields:
5355
* `state` : the state of the event (`PRESS`, `RELEASE`, `HOLD`).
5456
5557
"""
56-
immutable StickEvent
58+
struct StickEvent
5759
timestamp::DateTime
5860
direc::Direc
5961
state::State
6062
end
6163

6264
Base.convert(::Type{StickEvent}, r::StickEventRaw) =
6365
StickEvent(Dates.unix2datetime(r.tv_sec + r.tv_usec/1_000_000),
64-
Direc(r.ev_direc), State(r.ev_state))
66+
Direc(r.ev_direc), State(r.ev_state))
6567

6668
"""
6769
readstick()
@@ -75,9 +77,9 @@ function readstick()
7577
fddev = RawFD(fd(dev))
7678
while true
7779
wait(fddev, readable=true)
78-
s = read(dev, StickEventRaw)
80+
s = read!(dev, Ref{StickEventRaw}())[]
7981
if s.ev_type == EV_KEY
80-
return StickEvent(s)
82+
return convert(StickEvent,s)
8183
end
8284
end
8385
end
@@ -101,9 +103,9 @@ function sticktask()
101103
fddev = RawFD(fd(dev))
102104
while true
103105
wait(fddev, readable=true)
104-
s = read(dev, StickEventRaw)
106+
s = read(dev, Ref{StickEventRaw}())[]
105107
if s.ev_type == EV_KEY
106-
produce(StickEvent(s))
108+
produce(convert(StickEvent, s))
107109
end
108110
end
109111
end

src/text.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
module Text
22

3-
using ColorTypes, Colors.@colorant_str
3+
using ColorTypes, Colors
44

55
import SenseHat.LED: RGB565, led_matrix, led_clear
6+
import Colors.@colorant_str
67

7-
export show_char, show_message, @colorant_str
8+
export show_char, show_message
89

910
"""
1011
show_char(c::Char, color::ColorTypes.AbstractRGB = colorant"white")
@@ -42,9 +43,8 @@ function show_message(s::String, speed::Real = 0.2, color::ColorTypes.AbstractRG
4243
error("Character font for $c not available \n")
4344
return
4445
end
45-
img = Array{Bool}(8, 16 + 5*length(s))
46-
img[1:8,1:8] = Bool.(zeros(8,8))
47-
img[1:8,(9 + 5*length(s)):(16 + 5*length(s))] = Bool.(zeros(8,8))
46+
img = Array{Bool, 2}(undef, 8, 16 + 5*length(s))
47+
img[:] .= 0
4848
for i in 1:length(s)
4949
img[1:8, (4 + 5*i):(8 + 5*i)] = font[s[i]]
5050
end

test/led.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using SenseHat
2-
using Base.Test
2+
using Test
33

44
using ColorTypes
55

test/sensors.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using Base.Test
1+
using Test
22
using SenseHat
33

44
@test -40 <= temperature() <= 60
55
@test 0 <= humidity() <= 100
6-
@test 950 <= pressure() <= 1100
6+
@test 900 <= pressure() <= 1200

0 commit comments

Comments
 (0)