AnalogOut.jl 1.03 KB
Newer Older
Anders Blomdell's avatar
Anders Blomdell committed
1
2
3
4
5
6
7
8
9
mutable struct AnalogOutChannel
    context::Ptr{Nothing}
    write::Ptr{Nothing}
end

mutable struct AnalogOut
    moberg::Moberg
    index::UInt32
    channel::AnalogOutChannel
10
11
    function AnalogOut(moberg::Moberg, index::Unsigned)
        channel = AnalogOutChannel(0,0)
Anders Blomdell's avatar
Anders Blomdell committed
12
13
14
15
        checkOK(ccall((:moberg_analog_out_open, "libmoberg"),
                       Status,
                       (Moberg, Cint, Ref{AnalogOutChannel}),
                       moberg, index, channel));
16
17
        self = new(moberg, index, channel)
        finalizer(close, self)
Anders Blomdell's avatar
Anders Blomdell committed
18
        self
19
    end
Anders Blomdell's avatar
Anders Blomdell committed
20
21
22
23
24
25
26
27
end

function close(aout::AnalogOut)
    # println("closing $(aout)")
    checkOK(ccall((:moberg_analog_out_close, "libmoberg"),
                  Status,
                  (Moberg, Cint, AnalogOutChannel),
                  aout.moberg, aout.index, aout.channel))
28
end
Anders Blomdell's avatar
Anders Blomdell committed
29
30
31
32
33
34
35

function write(aout::AnalogOut, value::Cdouble)
    checkOK(ccall(aout.channel.write,
                  Status,
                  (Ptr{Nothing}, Cdouble),
                  aout.channel.context, value))
end