DigitalIn.jl 1.05 KB
Newer Older
Anders Blomdell's avatar
Anders Blomdell committed
1
2
3
4
5
6
7
8
9
mutable struct DigitalInChannel
    context::Ptr{Nothing}
    read::Ptr{Nothing}
end

mutable struct DigitalIn
    moberg::Moberg
    index::UInt32
    channel::DigitalInChannel
10
11
    function DigitalIn(moberg::Moberg, index::Unsigned)
        channel = DigitalInChannel(0,0)
Anders Blomdell's avatar
Anders Blomdell committed
12
13
14
15
        checkOK(ccall((:moberg_digital_in_open, "libmoberg"),
                       Status,
                       (Moberg, Cint, Ref{DigitalInChannel}),
                       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
28
29
30
31
32
33
34
35
36
37
end

function close(din::DigitalIn)
    # println("closing $(din)")
    checkOK(ccall((:moberg_digital_in_close, "libmoberg"),
                  Status,
                  (Moberg, Cint, DigitalInChannel),
                  din.moberg, din.index, din.channel))
end

function read(din::DigitalIn)
    result = Ref{Cint}(0)
    checkOK(ccall(din.channel.read,
                  Status,
                  (Ptr{Nothing}, Ptr{Cint}),
                  din.channel.context, result))
    return result[] != 0
end