Skip to content

Commit

Permalink
Expand digitalio functions. Deprecate non ! mutating function names (#93
Browse files Browse the repository at this point in the history
)
  • Loading branch information
IanButterworth authored Sep 13, 2023
1 parent 7165821 commit 9774118
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
45 changes: 41 additions & 4 deletions src/camera/digitalio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,57 @@

# camera/digitalio.jl: Camera object digital io features

export line_mode!, line_mode,
line_inverter!, line_inverter,
v3_3_enable!, v3_3_enable

"""
line_mode(::Camera, state::Symbol)
line_mode!(::Camera, state::Symbol)
Sets the DigitalIO Line Mode. State can either be "Input" or "Output"
"""
function line_mode(cam::Camera, state::String)
function line_mode!(cam::Camera, state::String)
@assert state in ["Input", "Output"] "State can only be either \"Input\" or \"Output\""
set!(SpinEnumNode(cam, "LineMode"), state)
return nothing
end
@deprecate line_mode(cam::Camera, state::String) line_mode!(cam::Camera, state::String)

"""
line_mode(::Camera)
Gets the DigitalIO Line Mode. State can either be "Input" or "Output"
"""
line_mode(cam::Camera) = get(SpinEnumNode(cam, "LineMode"))

"""
v3_3_enable(::Camera, state::Bool)
line_inverter!(::Camera, enable::Bool)
Sets the DigitalIO LineInverter state.
"""
function line_inverter!(cam::Camera, state::Bool)
set!(SpinBooleanNode(cam, "LineInverter"), state)
return nothing
end

"""
line_inverter(::Camera)
Read the DigitalIO LineInverter state.
"""
line_inverter(cam::Camera) = get(SpinBooleanNode(cam, "LineInverter"))

"""
v3_3_enable!(::Camera, state::Bool)
Sets the DigitalIO 3.3V line state.
"""
v3_3_enable(cam::Camera, state::Bool) = set!(SpinBooleanNode(cam, "V3_3Enable"), state)
v3_3_enable!(cam::Camera, state::Bool) = set!(SpinBooleanNode(cam, "V3_3Enable"), state)
@deprecate v3_3_enable(cam::Camera, state::Bool) v3_3_enable!(cam::Camera, state::Bool)

"""
v3_3_enable(::Camera)
Gets the DigitalIO 3.3V line state.
"""
v3_3_enable(cam::Camera) = get(SpinBooleanNode(cam, "V3_3Enable"))
29 changes: 29 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,35 @@ else
stop!(cam)
end
end

@testset "Digital IO" begin
line_inverter!(cam, true)
@test line_inverter(cam)
line_inverter!(cam, false)
@test !line_inverter(cam)

line_mode!(cam, "Input")
@test line_mode(cam) == "Input"
line_mode!(cam, "Output")
@test line_mode(cam) == "Output"

v3_3_enable!(cam, true)
@test v3_3_enable(cam)
v3_3_enable!(cam, false)
@test !v3_3_enable(cam)

@testset "deprecated" begin
@test_deprecated line_mode(cam, "Input")
@test line_mode(cam) == "Input"
@test_deprecated line_mode(cam, "Output")
@test line_mode(cam) == "Output"

@test_deprecated v3_3_enable(cam, true)
@test v3_3_enable(cam)
@test_deprecated v3_3_enable(cam, false)
@test !v3_3_enable(cam)
end
end
end

@testset "#90: duplicate initialization crash" begin
Expand Down

0 comments on commit 9774118

Please sign in to comment.