From 34d2a4b5729283163fe7143014f124fae423db6b Mon Sep 17 00:00:00 2001 From: mgreiff <marcusgreiff.93@hotmail.com> Date: Thu, 24 Aug 2017 13:51:35 +0200 Subject: [PATCH] Added text based setting of GPIO allowing in/out configuration and refactor code --- src/BeagleBone/GPIO.jl | 84 ------------------------------------ test/BeagleBone/GPIO_test.jl | 36 ---------------- 2 files changed, 120 deletions(-) delete mode 100644 src/BeagleBone/GPIO.jl delete mode 100644 test/BeagleBone/GPIO_test.jl diff --git a/src/BeagleBone/GPIO.jl b/src/BeagleBone/GPIO.jl deleted file mode 100644 index e1d748a..0000000 --- a/src/BeagleBone/GPIO.jl +++ /dev/null @@ -1,84 +0,0 @@ -""" -Lowest form of communication woth 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) - -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. - - write!(GPIO, 14, 2, "out") - write!(GPIO, 14, 1, "1") - -""" -struct GPIO -end - -writeOperations = [ - Dict("dir" => "value", "entries"=>["1", "0"]) - Dict("dir" => "direction", "entries"=>["in", "out"]) -] - -readOperations = [ - "value" - "direction" - "edge" -] - -channels =[ - "gpio112" - "gpio114" - "gpio115" - "gpio116" - "gpio14" - "gpio15" - "gpio2" - "gpio20" - "gpio22" - "gpio23" - "gpio26" - "gpio27" - "gpio3" - "gpio30" - "gpio31" - "gpio4" - "gpio44" - "gpio45" - "gpio46" - "gpio47" - "gpio48" - "gpio49" - "gpio5" - "gpio50" - "gpio51" - "gpio60" - "gpio61" - "gpio65" - "gpio66" - "gpio67" - "gpio68" - "gpio69" - "gpio7" -] - -function write!(::GPIO, index::Int32, operation::Int32, entry::Bool) - (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) - return -end - -#function Base.read(::SysLED, ind::Int32) -# (ind < 0 || ind > length(channels)) && error("Invalid SysLEND ind: $ind") -# println("not yet supported") -# l = 0 -# return l == "1" -#end diff --git a/test/BeagleBone/GPIO_test.jl b/test/BeagleBone/GPIO_test.jl deleted file mode 100644 index 02128f3..0000000 --- a/test/BeagleBone/GPIO_test.jl +++ /dev/null @@ -1,36 +0,0 @@ -include("../../src/BeagleBone/BeagleBone.jl") - -using Base.Test - -#Fixture -device = getdev("gpio") -gpio_state = true - -@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 ID is given - @test_throws ErrorException write!(device, 0, 1, gpio_state) - 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 - for index = 1:length(channels) - write!(device, index, operation, gpio_state) - end - sleep(0.01) - #for j = 1:4 - #val = read(device, j) - #@test val == gpio_state - #end - gpio_state = !gpio_state - end - end -end -- GitLab