diff --git a/src/BeagleBone/SysLED.jl b/src/BeagleBone/SysLED.jl index 4335db5281e4e486710f5479fae2b06182d271b5..3418deac50c916ee642667369a57cb5189d95f78 100644 --- a/src/BeagleBone/SysLED.jl +++ b/src/BeagleBone/SysLED.jl @@ -5,7 +5,7 @@ i ∈ [1,2,3,4]. """ type SysLED <: IO_Object i::Int32 - brightness_filestream::IOStream + filestream::IOStream function SysLED(i::Int32) i ∉ [1,2,3,4] && error("Invalid SysLED index: $i") #Note, in the future we should interface to config and retrieve IOStream from there @@ -18,10 +18,11 @@ end write!(led::SysLED, val::Bool, debug::Bool=false) Turns the LED 'SysLed' on/off for val = true/false respectively. """ -function write!(led::SysLED, val::Bool, debug::Bool=false) +function write!(led::SysLED, entry::String, debug::Bool=false) debug && return - write(led.brightness_filestream, val ? "1" : "0") - seekstart(led.brightness_filestream) + entry ∉ ["0", "1"] && error("Invalid SysLED entry $(entry), valid options are 0 and 1 (string)") + write(led.filestream, entry) + seekstart(led.filestream) end """ @@ -30,9 +31,9 @@ Reads the current brightness value from the LED 'SysLED'. """ function read(led::SysLED, debug::Bool=false) debug && return - l = read(led.brightness_filestream, Char) + l = read(filestream, Char) (l != '1' && l != '0') && error("Invalid value \"$l\" read from SysLed") - seekstart(led.brightness_filestream) + seekstart(led.filestream) return l end @@ -42,5 +43,5 @@ Closes all open filestreams for the SysLED 'led'. """ function teardown(led::SysLED, debug::Bool=false) debug && return - close(led.brightness_filestream) + close(led.filestream) end diff --git a/src/BeagleBone/precompile.jl b/src/BeagleBone/precompile.jl index 33edbfd27254a021d97d84213e4d9f0a0281fa6e..3f25ed51343a2fa18a5eafe6fdc35a2692df61d6 100644 --- a/src/BeagleBone/precompile.jl +++ b/src/BeagleBone/precompile.jl @@ -24,7 +24,7 @@ function precompile_bb() debug = true #Precompile SysLED led = initdev("sysled",Int32(1)) - write!(led, true, debug) + write!(led, "1", debug) read(led, debug) ind = 1 diff --git a/test/BeagleBone/Sys_LED_test.jl b/test/BeagleBone/Sys_LED_test.jl index 3a48f065a2f00ad8493501b347fb13dab5b33f07..c18b85fd7a770ed1d8fec3a66a9eab4160fbdb34 100644 --- a/test/BeagleBone/Sys_LED_test.jl +++ b/test/BeagleBone/Sys_LED_test.jl @@ -1,36 +1,39 @@ using LabConnections.BeagleBone -import LabConnections.BeagleBone: getdev, write! +import LabConnections.BeagleBone: getdev, write!, closedev, read, initdev using Base.Test -#Fixture -device = getdev("sysled") -ledon = true - @testset "SYS LED 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, 5, ledon) + device = initdev("sysled", 1) # Test that an exception is thrown when a faulty ID is given - @test_throws ErrorException write!(device, 0, ledon) + @test_throws ErrorException write!(device, "bad_entry") + + # Close device + closedev("sysled", 1) end @testset "IO Communication" begin # Instanciate all possible leds and perform 10 read/write commands + device1 = initdev("sysled", 1) + device2 = initdev("sysled", 2) + device3 = initdev("sysled", 3) + device4 = initdev("sysled", 4) + for i = 1:10 - for j = 1:4 - write!(device, j, ledon) - end - sleep(0.001) - for j = 1:4 - val = read(device, j) - @test val == ledon - end - ledon = !ledon + state = + write!(device1, "$(i%2)") + write!(device2, "$((i+1)%2)") + write!(device3, "$(i%2)") + write!(device4, "$((i+1)%2)") + sleep(0.1) end + + closedev("sysled", 1) + closedev("sysled", 2) + closedev("sysled", 3) + closedev("sysled", 4) end end