Skip to content

Commit

Permalink
Lua RunCam: Add support to automatically start/stop video recording o…
Browse files Browse the repository at this point in the history
…n arm/disarm
  • Loading branch information
martinwilco committed Jul 9, 2024
1 parent b8a8957 commit 86bcd16
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions ROMFS_custom/scripts/RunCam.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--[[
This script starts RunCam video recording on arm and stops video recording on disarm.
To access the camera controls the port the RunCam is connected to must be set as a scripting port.
--]]

local runcam = serial:find_serial(0)

if not runcam then
gcs:send_text(0, "RunCam: No scripting serial port")
return
end

runcam:begin(115200)
runcam:set_flow_control(0)

local RUNCAM_HEADER = 0xCC
local RCDEVICE_PROTOCOL_COMMAND_CAMERA_CONTROL = 0x01
local RCDEVICE_PROTOCOL_SIMULATE_POWER_BTN = 0x01
local recording = false

local function send_packet(command, action)
local buffer = {}
buffer[1] = RUNCAM_HEADER
buffer[2] = command
buffer[3] = action
buffer[#buffer + 1] = 0xE7 -- hard coded CRC-8/DVB-S2 checksum (0xCC 0x01 0x01)
for i = 1, #buffer do
runcam:write(buffer[i])
end
end

function start_stop_recording()
if not recording and arming:is_armed() then
send_packet(RCDEVICE_PROTOCOL_COMMAND_CAMERA_CONTROL, RCDEVICE_PROTOCOL_SIMULATE_POWER_BTN)
gcs:send_text(6, 'RunCam recording started')
recording = true
elseif recording and not arming:is_armed() then
send_packet(RCDEVICE_PROTOCOL_COMMAND_CAMERA_CONTROL, RCDEVICE_PROTOCOL_SIMULATE_POWER_BTN)
gcs:send_text(6, 'RunCam recording stopped')
recording = false
end
return start_stop_recording, 1000
end

return start_stop_recording()
2 changes: 1 addition & 1 deletion ROMFS_custom/scripts/read_and_log_hmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
--]]

-- create parameter table
local PARAM_TABLE_KEY = 73 -- parameter table key must be used by only one script on a particular flight controller, unique index value between 0 and 200
local PARAM_TABLE_KEY = 74 -- parameter table key must be used by only one script on a particular flight controller, unique index value between 0 and 200
local PARAM_TABLE_PREFIX = 'HMP_'
assert(param:add_table(PARAM_TABLE_KEY, PARAM_TABLE_PREFIX, 1),
string.format('Could not add param table %s', PARAM_TABLE_PREFIX))
Expand Down

0 comments on commit 86bcd16

Please sign in to comment.