Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LabConnections.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
labdev
LabConnections.jl
Commits
1a358bbf
Commit
1a358bbf
authored
7 years ago
by
Marcus Thelander Andrén
Browse files
Options
Downloads
Patches
Plain Diff
Added read method, tests and String-arguments to GPIO
parent
22ff84d6
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/BeagleBone/GPIO.jl
+35
-20
35 additions, 20 deletions
src/BeagleBone/GPIO.jl
src/BeagleBone/precompile.jl
+1
-1
1 addition, 1 deletion
src/BeagleBone/precompile.jl
test/BeagleBone/GPIO_test.jl
+15
-12
15 additions, 12 deletions
test/BeagleBone/GPIO_test.jl
with
51 additions
and
33 deletions
src/BeagleBone/GPIO.jl
+
35
−
20
View file @
1a358bbf
"""
Lowest form of communication w
o
th the GPIO pins. The available pins are
Lowest form of communication w
i
th the GPIO pins. The available pins are
listed in the "
channel
" parameter, and appear as directories in /sys/class.
Any of these GPIOs can be run in various ways, with any operation specified
by a sequence of three entries
(channel, operation, entry) = (int32,
int32
, String)
(channel,
(
operation, entry)
)
= (int32,
(String
, String)
)
For instance, if the GPIO "
gpio30
" is to be configured as a output pin and set
to high, the following two writes aould be done.
to high, the following two writes would be done.
write!(GPIO, 14, ("
direction
", "
out
"))
write!(GPIO, 14, ("
value
", "
1
"))
The operation of reading the current cofiguration of the GPIO is specified by
(channel, operation) = (int32, String)
write!(GPIO, 14, 2, "
out
")
write!(GPIO, 14, 1, "
1
")
For instance, to read the current value of the GPIO "
gpio30
" the following read
would be done
read(GPIO, 14, "
value
")
"""
struct
GPIO
end
writeOperations
=
[
Dict
(
"dir"
=>
"value"
,
"entries"
=>
[
"1"
,
"0"
])
Dict
(
"dir"
=>
"direction"
,
"entries"
=>
[
"in"
,
"out"
])
]
writeOperations
=
Dict
(
"value"
=>
[
"1"
,
"0"
],
"direction"
=>
[
"in"
,
"out"
])
readOperations
=
[
"value"
...
...
@@ -63,14 +70,14 @@ channels =[
"gpio7"
]
function
write!
(
::
GPIO
,
index
::
Int32
,
args
::
Tuple
{
Int32
,
String
},
debug
::
Bool
=
false
)
function
write!
(
::
GPIO
,
index
::
Int32
,
args
::
Tuple
{
String
,
String
},
debug
::
Bool
=
false
)
debug
&&
return
operation
,
entry
=
args
[
1
],
args
[
2
]
(
index
<=
0
||
index
>
length
(
channels
))
&&
error
(
"Invalid GPIO index:
$
index"
)
(
operation
<=
0
||
operation
>
length
(
writeO
peration
s
)
)
&&
error
(
"Invalid GPIO operation:
$
operation"
)
filename
=
"/sys/class/gpio/
$
(channels[index])/
$
(writeOperations[operation]["
dir
"])
"
!
haskey
(
writeOperations
,
o
peration
)
&&
error
(
"Invalid GPIO operation:
$
operation"
)
filename
=
"/sys/class/gpio/
$
(channels[index])/
$
operation
"
if
entry
in
writeOperations
[
operation
]
[
"entries"
]
if
entry
in
writeOperations
[
operation
]
file
=
open
(
filename
,
"r+"
)
write
(
file
,
"
$(entry)
"
)
close
(
file
)
...
...
@@ -80,10 +87,18 @@ function write!(::GPIO, index::Int32, args::Tuple{Int32,String}, debug::Bool=fal
return
end
#function Base.read(::SysLED, ind::Int32, debug::Bool=false)
# debug && return
# (ind < 0 || ind > length(channels)) && error("Invalid SysLEND ind: $ind")
# println("not yet supported")
# l = 0
# return l == "1"
#end
function
read
(
::
GPIO
,
index
::
Int32
,
operation
::
String
,
debug
::
Bool
=
false
)
debug
&&
return
(
index
<=
0
||
index
>
length
(
channels
))
&&
error
(
"Invalid GPIO index:
$
index"
)
if
operation
in
readOperations
filename
=
"/sys/class/gpio/
$
(channels[index])/
$
operation"
file
=
open
(
filename
,
"r"
)
l
=
readline
(
file
)
close
(
file
)
l
∉
readOperations
[
operation
]
&&
error
(
"Invalid entry read :
$
l"
)
return
l
else
error
(
"Cannot read from:
$
operation"
)
end
end
This diff is collapsed.
Click to expand it.
src/BeagleBone/precompile.jl
+
1
−
1
View file @
1a358bbf
...
...
@@ -25,7 +25,7 @@ function precompile_bb()
# Precompile GPIO
gpio
=
GPIO
()
write!
(
gpio
,
Int32
(
1
),
(
Int32
(
2
)
,
"1"
),
debug
)
write!
(
gpio
,
Int32
(
1
),
(
"value"
,
"1"
),
debug
)
#read(gpio, ind, args, debug)
try
getdev
(
"nonexistent"
)
catch
end
...
...
This diff is collapsed.
Click to expand it.
test/BeagleBone/GPIO_test.jl
+
15
−
12
View file @
1a358bbf
...
...
@@ -7,7 +7,7 @@ using Base.Test
#Fixture
device
=
getdev
(
"gpio"
)
gpio_state
=
true
write!
(
device
,
3
1
,
(
2
,
"out"
))
write!
(
device
,
1
,
(
"direction"
,
"out"
))
device
=
getdev
(
"gpio"
)
...
...
@@ -16,26 +16,29 @@ device = getdev("gpio")
# Attempt to initialize faulty device
@test_throws
ErrorException
getdev
(
"wrong_device_name"
)
# Test that an exception is thrown when a faulty channel is given
@test_throws
ErrorException
write!
(
device
,
100
,
(
1
,
"0"
))
# Test that an exception is thrown when a too high pin-index is given
@test_throws
ErrorException
write!
(
device
,
Int32
(
100
),
(
"value"
,
"0"
))
@test_throws
ErrorException
read
(
device
,
Int32
(
100
),
"value"
)
# Test that an exception is thrown when a faulty channel is given
@test_throws
ErrorException
write!
(
device
,
0
,
(
1
,
"1"
))
# Test that an exception is thrown when a too low pin-index is given
@test_throws
ErrorException
write!
(
device
,
Int32
(
0
),
(
"value"
,
"1"
))
@test_throws
ErrorException
read
(
device
,
Int32
(
0
),
"value"
)
# Test that an exepition is thrown when requiring bad entry
@test_throws
ErrorException
write!
(
device
,
0
,
(
123
,
"0"
))
# Test that an exception is thrown when requesting a bad operation
@test_throws
ErrorException
write!
(
device
,
Int32
(
1
),
(
"bad_operation"
,
"0"
))
@test_throws
ErrorException
read
(
device
,
Int32
(
1
),
"bad_operation"
)
# Test that an exep
i
tion is thrown when
requir
ing bad entry
@test_throws
ErrorException
write!
(
device
,
0
,
(
1
,
"bad_entry"
))
# Test that an ex
c
eption is thrown when
writ
ing
a
bad entry
@test_throws
ErrorException
write!
(
device
,
Int32
(
1
),
(
"value"
,
"bad_entry"
))
end
@testset
"IO Communication"
begin
# Instanciate all possible leds and perform 10 read/write commands
# with the set high/low operation (
1
)
operation
=
1
# with the set high/low operation (
"value"
)
operation
=
"value"
for
i
=
1
:
10
state
=
"
$
(i%2)"
for
index
=
1
:
length
(
channels
)
write!
(
device
,
index
,
(
operation
,
state
))
write!
(
device
,
Int32
(
index
)
,
(
operation
,
state
))
end
sleep
(
0.1
)
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment