EncoderIn.jl 1.05 KB
Newer Older
Anders Blomdell's avatar
Anders Blomdell committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
mutable struct EncoderInChannel
    context::Ptr{Nothing}
    read::Ptr{Nothing}
end

mutable struct EncoderIn
    moberg::Moberg
    index::UInt32
    channel::EncoderInChannel
    EncoderIn(moberg::Moberg, index::Unsigned) = (
        channel = EncoderInChannel(0,0);
        checkOK(ccall((:moberg_encoder_in_open, "libmoberg"),
                       Status,
                       (Moberg, Cint, Ref{EncoderInChannel}),
                       moberg, index, channel));
        self = new(moberg, index, channel);
        finalizer(close, self);
        self
    )
end

function close(ein::EncoderIn)
    # println("closing $(ein)")
    checkOK(ccall((:moberg_encoder_in_close, "libmoberg"),
                  Status,
                  (Moberg, Cint, EncoderInChannel),
                  ein.moberg, ein.index, ein.channel))
end

function read(ein::EncoderIn)
    result = Ref{Clong}(0)
    checkOK(ccall(ein.channel.read,
                  Status,
                  (Ptr{Nothing}, Ptr{Clong}),
                  ein.channel.context, result))
    return result[]
end