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 =[
"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
operation, entry = args[1], args[2]
(index <= 0 || index > length(channels)) && error("Invalid GPIO index: $index")
(operation <= 0 || operation > length(writeOperations)) && error("Invalid GPIO operation: $operation")
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+")
write(file, "$(value)")
write(file, "$(entry)")
close(file)
else
error("Cannot write $(entry) to operation: $operation")
end
return
end
......
......@@ -25,7 +25,7 @@ function precompile_bb()
# Precompile GPIO
gpio = GPIO()
write!(gpio, Int32(1), (Int32(2), true), debug)
write!(gpio, Int32(1), (Int32(2), "1"), debug)
#read(gpio, ind, args, debug)
try getdev("nonexistent") catch end
......
......@@ -12,7 +12,7 @@ module LabConnection
end
module Computer
import Base: read, close, get, serialize, set!
import Base: read, close, get, serialize
println("Initializing Computer")
include(joinpath("Computer","Computer.jl"))
end
......
include("../../src/BeagleBone/BeagleBone.jl")
include("../../src/LabConnection.jl")
using LabConnection.BeagleBone
import LabConnection.BeagleBone: getdev, write!, channels
using Base.Test
#Fixture
device = getdev("gpio")
gpio_state = true
write!(device, 31, (2, "out"))
device = getdev("gpio")
@testset "GPIO Tests" begin
@testset "Error Handling" begin
# Attempt to initialize faulty device
@test_throws ErrorException getdev("wrong_device_name")
# Test that an exception is thrown when a faulty ID is given
@test_throws ErrorException write!(device, 100, 1, gpio_state)
# 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 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_throws ErrorException write!(device, 0, 1, gpio_state)
# Test that an exepition is thrown when requiring bad entry
@test_throws ErrorException write!(device, 0, (1, "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
for i = 1:10
state = "$(i%2)"
for index = 1:length(channels)
write!(device, index, operation, gpio_state)
write!(device, index, (operation, state))
end
sleep(0.01)
#for j = 1:4
#val = read(device, j)
#@test val == gpio_state
#end
gpio_state = !gpio_state
sleep(0.1)
end
end
end
include("../../src/BeagleBone/BeagleBone.jl")
include("../../src/LabConnection.jl")
using LabConnection.BeagleBone
import LabConnection.BeagleBone: getdev, write!
using Base.Test
......
......@@ -2,4 +2,3 @@
ls
cd "LabConnection.jl/test/BeagleBone"
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