Skip to content
Snippets Groups Projects
Commit 3b2febb3 authored by Mattias Fält's avatar Mattias Fält
Browse files

Merge and fixes

parents a27cb5bd 423213c1
No related branches found
No related tags found
No related merge requests found
...@@ -63,18 +63,20 @@ channels =[ ...@@ -63,18 +63,20 @@ channels =[
"gpio7" "gpio7"
] ]
function write!(::GPIO, index::Int32, args::Tuple{Int32,Bool}, debug::Bool=false) function write!(::GPIO, index::Int32, args::Tuple{Int32,String}, debug::Bool=false)
debug && return debug && return
operation, entry = args[1], args[2] operation, entry = args[1], args[2]
(index <= 0 || index > length(channels)) && error("Invalid GPIO index: $index") (index <= 0 || index > length(channels)) && error("Invalid GPIO index: $index")
(operation <= 0 || operation > length(writeOperations)) && error("Invalid GPIO operation: $operation") (operation <= 0 || operation > length(writeOperations)) && error("Invalid GPIO operation: $operation")
filename = "/sys/class/gpio/$(channels[index])/$(writeOperations[operation]["dir"])" filename = "/sys/class/gpio/$(channels[index])/$(writeOperations[operation]["dir"])"
value = writeOperations[operation]["entries"][entry ? 1 : 2] if entry in writeOperations[operation]["entries"]
file = open(filename, "r+") file = open(filename, "r+")
write(file, "$(entry)")
write(file, "$(value)")
close(file) close(file)
else
error("Cannot write $(entry) to operation: $operation")
end
return return
end end
......
...@@ -25,7 +25,7 @@ function precompile_bb() ...@@ -25,7 +25,7 @@ function precompile_bb()
# Precompile GPIO # Precompile GPIO
gpio = GPIO() gpio = GPIO()
write!(gpio, Int32(1), (Int32(2), true), debug) write!(gpio, Int32(1), (Int32(2), "1"), debug)
#read(gpio, ind, args, debug) #read(gpio, ind, args, debug)
try getdev("nonexistent") catch end try getdev("nonexistent") catch end
......
...@@ -12,7 +12,7 @@ module LabConnection ...@@ -12,7 +12,7 @@ module LabConnection
end end
module Computer module Computer
import Base: read, close, get, serialize, set! import Base: read, close, get, serialize
println("Initializing Computer") println("Initializing Computer")
include(joinpath("Computer","Computer.jl")) include(joinpath("Computer","Computer.jl"))
end end
......
include("../../src/BeagleBone/BeagleBone.jl") include("../../src/LabConnection.jl")
using LabConnection.BeagleBone
import LabConnection.BeagleBone: getdev, write!, channels
using Base.Test using Base.Test
#Fixture #Fixture
device = getdev("gpio") device = getdev("gpio")
gpio_state = true gpio_state = true
write!(device, 31, (2, "out"))
device = getdev("gpio")
@testset "GPIO Tests" begin @testset "GPIO Tests" begin
@testset "Error Handling" begin @testset "Error Handling" begin
# Attempt to initialize faulty device # Attempt to initialize faulty device
@test_throws ErrorException getdev("wrong_device_name") @test_throws ErrorException getdev("wrong_device_name")
# Test that an exception is thrown when a faulty ID is given # Test that an exception is thrown when a faulty channel is given
@test_throws ErrorException write!(device, 100, 1, gpio_state) @test_throws ErrorException write!(device, 100, (1, "0"))
# Test that an exception is thrown when a faulty channel is given
@test_throws ErrorException write!(device, 0, (1, "1"))
# 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 a faulty ID is given # Test that an exepition is thrown when requiring bad entry
@test_throws ErrorException write!(device, 0, 1, gpio_state) @test_throws ErrorException write!(device, 0, (1, "bad_entry"))
end end
@testset "IO Communication" begin @testset "IO Communication" begin
# Instanciate all possible leds and perform 10 read/write commands # Instanciate all possible leds and perform 10 read/write commands
# with the set high/low operation (1) # with the set high/low operation (1)
operation = 1 operation = 1
for i = 1:10 for i = 1:10
state = "$(i%2)"
for index = 1:length(channels) for index = 1:length(channels)
write!(device, index, operation, gpio_state) write!(device, index, (operation, state))
end end
sleep(0.01) sleep(0.1)
#for j = 1:4
#val = read(device, j)
#@test val == gpio_state
#end
gpio_state = !gpio_state
end end
end end
end end
include("../../src/BeagleBone/BeagleBone.jl") include("../../src/LabConnection.jl")
using LabConnection.BeagleBone
import LabConnection.BeagleBone: getdev, write!
using Base.Test using Base.Test
......
...@@ -2,4 +2,3 @@ ...@@ -2,4 +2,3 @@
ls ls
cd "LabConnection.jl/test/BeagleBone" cd "LabConnection.jl/test/BeagleBone"
sudo /home/debian/julia-903644385b/bin/julia sudo /home/debian/julia-903644385b/bin/julia
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment