Skip to content

Commit

Permalink
Bugfix for invalid call to set_compatibility introduced in a7e4318
Browse files Browse the repository at this point in the history
  • Loading branch information
vwout committed Jul 17, 2023
1 parent afbc8b0 commit 5a79fb3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 3 additions & 4 deletions libvisca.lua
Expand Up @@ -844,9 +844,7 @@ end

--- @param compatibility ViscaCompatibility
function Visca.Connection:set_compatibility(compatibility)
compatibility = compatibility or {}

for k,v in pairs(compatibility) do
for k,v in pairs(compatibility or {}) do
self.compatibility[k] = v
end
end
Expand Down Expand Up @@ -1278,10 +1276,11 @@ end
--- @param preset number The preset number (typically starting with the first preset at 1)
--- @return number, string
function Visca.Connection:Cam_Preset_Recall(preset)
if self.compatibility.preset_nr_offset then
if self.compatibility.preset_nr_offset ~= nil then
preset = preset - self.compatibility.preset_nr_offset
end
preset = math.max(math.min(preset or 0, 127), 0)

local msg = Visca.Message.new()
msg.payload_type = Visca.payload_types.visca_command
msg.payload = {
Expand Down
2 changes: 1 addition & 1 deletion obs-visca-control.lua
Expand Up @@ -452,7 +452,7 @@ local function open_visca_connection(camera_id)
end

if next(compatibility) then
connection.set_compatibility(compatibility)
connection:set_compatibility(compatibility)

local compat_a = {}
for k, v in pairs (compatibility) do
Expand Down
12 changes: 10 additions & 2 deletions test/libvisca_test.lua
Expand Up @@ -130,9 +130,17 @@ function test_cam_reset_recall_8_ptzoptics()
end

function test_cam_reset_recall_6_jvc()
connection:set_compatibility({ preset_nr_offset = 1 })
connection:set_compatibility(nil)
local _, data = connection:Cam_Preset_Recall(6)
local recv_msg = Visca.Message.new():from_data(data):dump("Cam_Preset_Recall 6 JVC")
local recv_msg = Visca.Message.new():from_data(data):dump("Cam_Preset_Recall 6 normal")
lunit.assert_not_nil(recv_msg.message.command)
lunit.assert_equal(6, recv_msg.message.command.arguments[2])

clear_transmission_queue(connection)

connection:set_compatibility({ preset_nr_offset = 1 })
_, data = connection:Cam_Preset_Recall(6)
recv_msg = Visca.Message.new():from_data(data):dump("Cam_Preset_Recall 6 JVC")
lunit.assert_not_nil(recv_msg.message.command)
lunit.assert_equal(5, recv_msg.message.command.arguments[2])
end
Expand Down

0 comments on commit 5a79fb3

Please sign in to comment.