Commit 00c1ec6c authored by Fredrik Bagge Carlson's avatar Fredrik Bagge Carlson
Browse files

formatting + double GC.gc

parent 9e6d5436
...@@ -7,16 +7,16 @@ mutable struct AnalogIn ...@@ -7,16 +7,16 @@ mutable struct AnalogIn
moberg::Moberg moberg::Moberg
index::UInt32 index::UInt32
channel::AnalogInChannel channel::AnalogInChannel
AnalogIn(moberg::Moberg, index::Unsigned) = ( function AnalogIn(moberg::Moberg, index::Unsigned)
channel = AnalogInChannel(0,0); channel = AnalogInChannel(0,0)
checkOK(ccall((:moberg_analog_in_open, "libmoberg"), checkOK(ccall((:moberg_analog_in_open, "libmoberg"),
Status, Status,
(Moberg, Cint, Ref{AnalogInChannel}), (Moberg, Cint, Ref{AnalogInChannel}),
moberg, index, channel)); moberg, index, channel))
self = new(moberg, index, channel); self = new(moberg, index, channel)
finalizer(close, self); finalizer(close, self)
self self
) end
end end
function close(ain::AnalogIn) function close(ain::AnalogIn)
...@@ -35,4 +35,3 @@ function read(ain::AnalogIn) ...@@ -35,4 +35,3 @@ function read(ain::AnalogIn)
ain.channel.context, result)) ain.channel.context, result))
return result[] return result[]
end end
...@@ -7,16 +7,16 @@ mutable struct AnalogOut ...@@ -7,16 +7,16 @@ mutable struct AnalogOut
moberg::Moberg moberg::Moberg
index::UInt32 index::UInt32
channel::AnalogOutChannel channel::AnalogOutChannel
AnalogOut(moberg::Moberg, index::Unsigned) = ( function AnalogOut(moberg::Moberg, index::Unsigned)
channel = AnalogOutChannel(0,0); channel = AnalogOutChannel(0,0)
checkOK(ccall((:moberg_analog_out_open, "libmoberg"), checkOK(ccall((:moberg_analog_out_open, "libmoberg"),
Status, Status,
(Moberg, Cint, Ref{AnalogOutChannel}), (Moberg, Cint, Ref{AnalogOutChannel}),
moberg, index, channel)); moberg, index, channel));
self = new(moberg, index, channel); self = new(moberg, index, channel)
finalizer(close, self); finalizer(close, self)
self self
) end
end end
function close(aout::AnalogOut) function close(aout::AnalogOut)
...@@ -25,7 +25,7 @@ function close(aout::AnalogOut) ...@@ -25,7 +25,7 @@ function close(aout::AnalogOut)
Status, Status,
(Moberg, Cint, AnalogOutChannel), (Moberg, Cint, AnalogOutChannel),
aout.moberg, aout.index, aout.channel)) aout.moberg, aout.index, aout.channel))
end; end
function write(aout::AnalogOut, value::Cdouble) function write(aout::AnalogOut, value::Cdouble)
checkOK(ccall(aout.channel.write, checkOK(ccall(aout.channel.write,
......
...@@ -7,16 +7,16 @@ mutable struct DigitalIn ...@@ -7,16 +7,16 @@ mutable struct DigitalIn
moberg::Moberg moberg::Moberg
index::UInt32 index::UInt32
channel::DigitalInChannel channel::DigitalInChannel
DigitalIn(moberg::Moberg, index::Unsigned) = ( function DigitalIn(moberg::Moberg, index::Unsigned)
channel = DigitalInChannel(0,0); channel = DigitalInChannel(0,0)
checkOK(ccall((:moberg_digital_in_open, "libmoberg"), checkOK(ccall((:moberg_digital_in_open, "libmoberg"),
Status, Status,
(Moberg, Cint, Ref{DigitalInChannel}), (Moberg, Cint, Ref{DigitalInChannel}),
moberg, index, channel)); moberg, index, channel));
self = new(moberg, index, channel); self = new(moberg, index, channel)
finalizer(close, self); finalizer(close, self)
self self
) end
end end
function close(din::DigitalIn) function close(din::DigitalIn)
...@@ -35,4 +35,3 @@ function read(din::DigitalIn) ...@@ -35,4 +35,3 @@ function read(din::DigitalIn)
din.channel.context, result)) din.channel.context, result))
return result[] != 0 return result[] != 0
end end
...@@ -7,16 +7,16 @@ mutable struct DigitalOut ...@@ -7,16 +7,16 @@ mutable struct DigitalOut
moberg::Moberg moberg::Moberg
index::UInt32 index::UInt32
channel::DigitalOutChannel channel::DigitalOutChannel
DigitalOut(moberg::Moberg, index::Unsigned) = ( function DigitalOut(moberg::Moberg, index::Unsigned)
channel = DigitalOutChannel(0,0); channel = DigitalOutChannel(0,0)
checkOK(ccall((:moberg_digital_out_open, "libmoberg"), checkOK(ccall((:moberg_digital_out_open, "libmoberg"),
Status, Status,
(Moberg, Cint, Ref{DigitalOutChannel}), (Moberg, Cint, Ref{DigitalOutChannel}),
moberg, index, channel)); moberg, index, channel))
self = new(moberg, index, channel); self = new(moberg, index, channel)
finalizer(close, self); finalizer(close, self)
self self
) end
end end
function close(dout::DigitalOut) function close(dout::DigitalOut)
...@@ -25,7 +25,7 @@ function close(dout::DigitalOut) ...@@ -25,7 +25,7 @@ function close(dout::DigitalOut)
Status, Status,
(Moberg, Cint, DigitalOutChannel), (Moberg, Cint, DigitalOutChannel),
dout.moberg, dout.index, dout.channel)) dout.moberg, dout.index, dout.channel))
end; end
function write(dout::DigitalOut, value::Bool) function write(dout::DigitalOut, value::Bool)
checkOK(ccall(dout.channel.write, checkOK(ccall(dout.channel.write,
......
...@@ -7,16 +7,16 @@ mutable struct EncoderIn ...@@ -7,16 +7,16 @@ mutable struct EncoderIn
moberg::Moberg moberg::Moberg
index::UInt32 index::UInt32
channel::EncoderInChannel channel::EncoderInChannel
EncoderIn(moberg::Moberg, index::Unsigned) = ( function EncoderIn(moberg::Moberg, index::Unsigned)
channel = EncoderInChannel(0,0); channel = EncoderInChannel(0,0)
checkOK(ccall((:moberg_encoder_in_open, "libmoberg"), checkOK(ccall((:moberg_encoder_in_open, "libmoberg"),
Status, Status,
(Moberg, Cint, Ref{EncoderInChannel}), (Moberg, Cint, Ref{EncoderInChannel}),
moberg, index, channel)); moberg, index, channel))
self = new(moberg, index, channel); self = new(moberg, index, channel)
finalizer(close, self); finalizer(close, self)
self self
) end
end end
function close(ein::EncoderIn) function close(ein::EncoderIn)
...@@ -35,4 +35,3 @@ function read(ein::EncoderIn) ...@@ -35,4 +35,3 @@ function read(ein::EncoderIn)
ein.channel.context, result)) ein.channel.context, result))
return result[] return result[]
end end
...@@ -14,7 +14,7 @@ mutable struct moberg ...@@ -14,7 +14,7 @@ mutable struct moberg
handle::Ptr{Nothing} handle::Ptr{Nothing}
end end
function moberg() function moberg()
handle = ccall((:moberg_new, "libmoberg"), Ptr{Nothing}, ()) handle = ccall((:moberg_new, "libmoberg"), Ptr{Nothing}, ())
println(handle) println(handle)
m = moberg(handle) m = moberg(handle)
...@@ -31,46 +31,46 @@ mutable struct moberg_analog_in ...@@ -31,46 +31,46 @@ mutable struct moberg_analog_in
context::Ptr{Nothing} context::Ptr{Nothing}
do_read::Ptr{Nothing} do_read::Ptr{Nothing}
handle::moberg handle::moberg
moberg_analog_in(m::moberg, index::Unsigned) = ( function moberg_analog_in(m::moberg, index::Unsigned)
self = new(); self = new()
check_OK(ccall((:moberg_analog_in_open, "libmoberg"), check_OK(ccall((:moberg_analog_in_open, "libmoberg"),
moberg_status, moberg_status,
(Ptr{Nothing}, Cint, Ref{moberg_analog_in}), (Ptr{Nothing}, Cint, Ref{moberg_analog_in}),
m.handle, index, self)); m.handle, index, self))
self.handle = m; self.handle = m
function close(channel::moberg_analog_in) function close(channel::moberg_analog_in)
println(channel) println(channel)
ccall((:moberg_analog_in_close, "libmoberg"), ccall((:moberg_analog_in_close, "libmoberg"),
moberg_status, moberg_status,
(Ptr{Nothing}, Cint, moberg_analog_in), (Ptr{Nothing}, Cint, moberg_analog_in),
channel.handle.handle, index, self) channel.handle.handle, index, self)
end; end
finalizer(close, self); finalizer(close, self)
self self
) end
end end
mutable struct moberg_analog_out mutable struct moberg_analog_out
context::Ptr{Nothing} context::Ptr{Nothing}
do_write::Ptr{Nothing} do_write::Ptr{Nothing}
handle::moberg handle::moberg
moberg_analog_out(m::moberg, index::Unsigned) = ( function moberg_analog_out(m::moberg, index::Unsigned)
self = new(); self = new()
check_OK(ccall((:moberg_analog_out_open, "libmoberg"), check_OK(ccall((:moberg_analog_out_open, "libmoberg"),
moberg_status, moberg_status,
(Ptr{Nothing}, Cint, Ref{moberg_analog_out}), (Ptr{Nothing}, Cint, Ref{moberg_analog_out}),
m.handle, index, self)); m.handle, index, self))
self.handle = m; self.handle = m
function close(channel::moberg_analog_out) function close(channel::moberg_analog_out)
println(channel) println(channel)
ccall((:moberg_analog_out_close, "libmoberg"), ccall((:moberg_analog_out_close, "libmoberg"),
moberg_status, moberg_status,
(Ptr{Nothing}, Cint, moberg_analog_out), (Ptr{Nothing}, Cint, moberg_analog_out),
channel.handle.handle, index, self) channel.handle.handle, index, self)
end; end
finalizer(close, self); finalizer(close, self)
self self
) end
end end
function read(ain::moberg_analog_in) function read(ain::moberg_analog_in)
...@@ -92,12 +92,12 @@ end ...@@ -92,12 +92,12 @@ end
function test() function test()
m = moberg() m = moberg()
println(m) println(m)
for v in -10.0:2.0:10 for v in -10.0:2.0:10
for i in 30:31 for i in 30:31
try try
aout = moberg_analog_out(m, Unsigned(i)) aout = moberg_analog_out(m, Unsigned(i))
value = v + i - 32; value = v + i - 32
write(aout, value) write(aout, value)
print("$value ") print("$value ")
catch catch
...@@ -123,4 +123,5 @@ test() ...@@ -123,4 +123,5 @@ test()
println("DONE") println("DONE")
GC.gc() GC.gc()
GC.gc() # See https://github.com/JuliaCI/BenchmarkTools.jl/blob/af35d0513fe1e336ad0d8b9a35f924e8461aefa2/src/execution.jl#L1
println("Really DONE") println("Really DONE")
...@@ -8,12 +8,12 @@ import MobergIO: read, write ...@@ -8,12 +8,12 @@ import MobergIO: read, write
function test() function test()
m = MobergIO.Moberg() m = MobergIO.Moberg()
println(m) println(m)
for v in -10.0:2.0:10 for v in -10.0:2.0:10
for i in 30:31 for i in 30:31
try try
aout = MobergIO.AnalogOut(m, Unsigned(i)) aout = MobergIO.AnalogOut(m, Unsigned(i))
value = v + i - 32; value = v + i - 32
write(aout, value) write(aout, value)
print("$value ") print("$value ")
catch ex catch ex
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment