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

Fixed GPIO for julia1 and added GPIO on computer side

parent ae91cb63
No related branches found
No related tags found
No related merge requests found
Pipeline #700 failed
......@@ -177,10 +177,18 @@ function run_server(port=2001; debug=false)
@async while isopen(sock)
try
l = deserialize(sock);
println("deserialized:")
println(l)
try
bbparse(l, sock)
catch err
@warn "Failure in bbparse, server should keep running, error:"
println(err)
end
catch err
if !isopen(sock) && (isa(err, Base.EOFError) || isa(err, Base.UVError))
println("Connection to server closed")
# TODO teardown and remove all devices
else
println("error: $(typeof(err))")
println("err: $err")
......
......@@ -35,6 +35,11 @@ struct GPIO <: IO_Object
end
end
# Default to writing "value"
function write!(gpio::GPIO, val::String, debug::Bool=false)
write!(gpio, (Int32(1), val), debug=debug)
end
"""
write!(gpio::GPIO, args::Tuple{Int32,String}, debug::Bool=false)
Writes an entry to an operation on a GPIO, of the form args = (operation, entry).
......@@ -53,6 +58,10 @@ function write!(gpio::GPIO, args::Tuple{Int32,String}, debug::Bool=false)
end
end
# Default to reading "value"
function read(gpio::GPIO, debug::Bool=false)
read(gpio, Int32(1), debug=debug)
end
"""
l = read(gpio::GPIO, operation::Int32, debug::Bool=false)
Reads the current value from an operation on a GPIO.
......
......@@ -10,6 +10,8 @@ getstream(dev::AbstractDevice) = dev.stream
#Set the stream the AbstractDevice is connected to
setstream!(dev::AbstractDevice, stream::LabStream) = dev.stream = stream
# Write command that needs to be sent after setup (for example direction of GPIO)
getsetupwrite(::LabStream, ::AbstractDevice) = nothing
function safe_getwritecommand(dev::AbstractDevice, val)
stream = try getstream(dev) catch
......
......@@ -27,8 +27,16 @@ function init_devices!(bbstream::BeagleBoneStream, devs::AbstractDevice...)
name = readcmd[1]::String
idx = readcmd[2]::Integer
serialize(bbstream.stream, (Int32(2), Int32(1), (name, Int32(idx))))
setupwrite = getsetupwrite(bbstream, dev)
if setupwrite !== nothing
name = setupwrite[1]::String
idx = setupwrite[2]::Integer
commands = setupwrite[3]::Tuple
serialize(bbstream.stream, (Int32(1), Int32(1), (name, Int32(idx), commands)))
end
else
warn("Device $dev already added to a stream")
@warn "Device $dev already added to a stream"
end
end
return
......@@ -69,7 +77,6 @@ function read(bbstream::BeagleBoneStream, cmd)
end
function close(bbstream::BeagleBoneStream)
cmds = Tuple[]
for dev in bbstream.devices
close(dev)
end
......
......@@ -23,7 +23,7 @@ function init_devices!(comedistream::ComediStream, devs::AbstractDevice...)
push!(comedistream.devices, dev)
initialize(dev)
else
warn("Device $dev already added to the stream")
@warn "Device $dev already added to the stream"
end
end
return
......
......@@ -34,4 +34,5 @@ include("BeagleBoneStream.jl")
#Include the device definitions
include("SysLED.jl")
include("GPIO.jl")
include("10V.jl")
export GPIO
"""
GPIO(i::Integer, direction:Bool)
direction = true if output (write)
direction = false if input (read)
"""
mutable struct GPIO <: AbstractDevice
i::Int32
direction::Bool
stream::LabStream
GPIO(i::Int32, direction::Bool) = new(i, direction)
end
GPIO(i::Integer, direction::Bool) = GPIO(convert(Int32, i), direction)
function getsetupwrite(stream::BeagleBoneStream, gpio::GPIO)
if gpio.direction
return ("gpio", gpio.i, (Int32(2), "out"))
else
return ("gpio", gpio.i, (Int32(2), "in"))
end
end
#Stream specific methods
function getwritecommand(stream::BeagleBoneStream, gpio::GPIO, val::Bool)
if !gpio.direction
error("Can not write to GPIO input (read) device")
end
# TODO Check valid GPIO index
return ("gpio", gpio.i, (Int32(1), val ? "1" : "0"))
end
function getreadcommand(stream::BeagleBoneStream, gpio::GPIO)
# TODO Check valid GPIO index
return ("gpio", gpio.i)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment