diff --git a/src/BeagleBone/GPIO.jl b/src/BeagleBone/GPIO.jl index 1258e4cb93602ca41609d4d2afd7aa11321df333..4670fc1af79d9ad65d72da296f12212e11c02ac3 100644 --- a/src/BeagleBone/GPIO.jl +++ b/src/BeagleBone/GPIO.jl @@ -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] - file = open(filename, "r+") - - write(file, "$(value)") - close(file) + if entry in writeOperations[operation]["entries"] + file = open(filename, "r+") + write(file, "$(entry)") + close(file) + else + error("Cannot write $(entry) to operation: $operation") + end return end diff --git a/src/BeagleBone/precompile.jl b/src/BeagleBone/precompile.jl index 1c5a24d95d9e51a7ba7718876c63de7e55957ec3..9b7de32715d111a78cb764eaea29532d5a9b7244 100644 --- a/src/BeagleBone/precompile.jl +++ b/src/BeagleBone/precompile.jl @@ -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 diff --git a/src/LabConnection.jl b/src/LabConnection.jl index 2dc20efeac8683d5890ab9be2f142da20140b485..f2319055e922856ea0d4c8dba85dd93af68a9227 100644 --- a/src/LabConnection.jl +++ b/src/LabConnection.jl @@ -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 diff --git a/test/BeagleBone/GPIO_test.jl b/test/BeagleBone/GPIO_test.jl index 02128f3a0fc96c65932dc62e9d24c7478d94408c..bd3fabd812c66d2b972607ffe0a89294bf895e93 100644 --- a/test/BeagleBone/GPIO_test.jl +++ b/test/BeagleBone/GPIO_test.jl @@ -1,36 +1,43 @@ -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 diff --git a/test/BeagleBone/Sys_LED_test.jl b/test/BeagleBone/Sys_LED_test.jl index 6a8b901e932ea9de9979e622fea90541b2baef77..8c1e8265f5874f2f91b52c046b54679a14395b6b 100644 --- a/test/BeagleBone/Sys_LED_test.jl +++ b/test/BeagleBone/Sys_LED_test.jl @@ -1,4 +1,6 @@ -include("../../src/BeagleBone/BeagleBone.jl") +include("../../src/LabConnection.jl") +using LabConnection.BeagleBone +import LabConnection.BeagleBone: getdev, write! using Base.Test @@ -19,7 +21,7 @@ ledon = true end @testset "IO Communication" begin - # Instanciate all possible leds and perform 10 read/write commands + # Instanciate all possible leds and perform 10 read/write commands for i = 1:10 for j = 1:4 write!(device, j, ledon) diff --git a/util/startup.sh b/util/startup.sh index 78a8c75b74c62a7e02de9283fb4bd10d5ba94a0a..d556f1b05fa45910545a3d1f71545bd77b2d57d6 100755 --- a/util/startup.sh +++ b/util/startup.sh @@ -2,4 +2,3 @@ ls cd "LabConnection.jl/test/BeagleBone" sudo /home/debian/julia-903644385b/bin/julia -