Adapters
Adapters are the core foundation of PixPilot, which enable an easy and straightforward creation of new screens.
Use this template to create new adapter scripts for your flight controller and protocol. Adapter scripts are stored in /SCRIPTS/MIXES/
on the SD card and prefixed with Pix
.
Make sure the name of the script is not longer than 7 characters, else openTx will not recognize it!
--[[
My custom PixPilot adapter
]]--
pix_adapter_running = false
-- The name of your flight controller - e.g. PX4, APM, etc...
local controller = "ExampleController"
--[[
These are the normal telemetry fields that openTx will parse.
]]--
-- normal values --
local fuel
local alt
local vario
local accX
local accY
local accZ
local current
local vfas
local cells
local gps_lon_lat
local gps_alt
local gps_spd
local gps_crs
local gps_time
-- normal ids --
local fuelId = 1536
local altId = 256
local varioId = 272
local accXId = 1792
local accYId = 1808
local accZId = 1824
local currentId = 512
local vfasId = 528
local cellsId = 768
local gps_lon_latId = 2048
local gps_altId = 2080
local gps_spdId = 2096
local gps_crsId = 2112
local gps_timeId = 2128
--[[
These are custom and depend on the opentx 2.2 lua passthrough, and will highly depend on your flight controller
and the data it sends, so adjust accordingly.
]]--
-- custom values --
local nav_state
local gps_fix
local gps_sat
local arming_state
local roll
local pitch
local yaw
-- custom ids --
local nav_stateId = 20608
local gps_fix_satId = 20609
local arming_stateId = 20610
local rollId = 20611
local pitchId = 20612
local yawId = 20613
-- local functions --
local function init()
mavlink_messages_init()
pix_adapter_running = true
end
local function run()
update_pix_telemetry()
end
function update_pix_telemetry()
-- normal id parsing --
fuel = getValue(fuelId)
alt = getValue(altId)
vario = getValue(varioId)
accX = getValue(accXId)
accY = getValue(accYId)
accZ = getValue(accZId)
current = getValue(currentId)
vfas = getValue(vfasId)
cells = getValue(cellsId)
gps_lon_lat = getValue(gps_lon_latId)
gps_alt = getValue(gps_altId)
gps_spd = getValue(gps_spdId)
gps_crs = getValue(gps_crsId)
gps_time = getValue(gps_timeId)
--[[
Again, this part now is highly platform and protocol specific,
so adjust accordingly!!
]]--
-- telemetryPop() is only supported with OpenTx >= 2.2!
local physicalId, primId, dataId, value = telemetryPop()
if dataId == nav_stateId then
nav_state = value
elseif dataId == gps_fix_satId then
gps_fix = value % 10
gps_sat = (value - (value % 10)) * 0.1
elseif dataId == arming_stateId then
arming_state = value
elseif dataId == rollId then
roll = value / 100000.0
elseif dataId == pitchId then
pitch = value / 100000.0
elseif dataId == yawId then
yaw = value / 100000.0
end
end
--[[
These functions are global and exposed to the screen scripts.
Make sure to keep the names exactly the same, else scripts will stop working!!!!
]]--
-- global functions --
function pix_get_controller_name()
return controller
end
function pix_get_alt()
return alt
end
function pix_get_vario()
return vario
end
function pix_get_accX()
return accX
end
function pix_get_accY()
return accY
end
function pix_get_current()
return current
end
function pix_get_vfas()
return vfas
end
function pix_get_cells()
return cells
end
function pix_get_gps_lon_lan()
return gps_lon_lat
end
function pix_get_gps_alt()
return gps_alt
end
function pix_get_gps_spd()
return gps_spd
end
function pix_get_gps_crs()
return gps_crs
end
function pix_get_gps_time()
return gps_time
end
function pix_get_flightmode()
if nav_state == 0 then return "Manual"
elseif nav_state == 1 then return "Altitude Control"
elseif nav_state == 2 then return "Position Control"
elseif nav_state == 3 then return "Mission"
elseif nav_state == 4 then return "Loiter"
elseif nav_state == 5 then return "RTL"
elseif nav_state == 6 then return "RC Recover"
elseif nav_state == 7 then return "RTGS - Link Loss"
elseif nav_state == 8 then return "Land - Engine Fail"
elseif nav_state == 9 then return "Land - GPS Fail"
elseif nav_state == 10 then return "Acro"
elseif nav_state == 11 then return "Unused"
elseif nav_state == 12 then return "Descend"
elseif nav_state == 13 then return "Termination"
elseif nav_state == 14 then return "Offboard"
elseif nav_state == 15 then return "Stabilized"
elseif nav_state == 16 then return "RAttitude"
elseif nav_state == 17 then return "Takeoff"
elseif nav_state == 18 then return "Land"
elseif nav_state == 19 then return "Auto Follow"
elseif nav_state == 10 then return "Max"
end
end
function pix_get_gps_fix()
return gps_fix
end
function pix_get_gps_sat()
return gps_sat
end
function pix_get_arming_state()
if arming_state == 0 then return "Init"
elseif arming_state == 1 then return "Standby"
elseif arming_state == 2 then return "Armed"
elseif arming_state == 3 then return "Armed Error"
elseif arming_state == 4 then return "Standby Error"
elseif arming_state == 5 then return "Reboot"
elseif arming_state == 6 then return "In Air Restore"
elseif arming_state == 7 then return "Max"
end
end
function pix_get_roll()
return roll
end
function pix_get_pitch()
return pitch
end
function pix_get_yaw()
return yaw
end
function pix_say_flight_mode()
--TODO: Implement your desired way of saying flightmodes.
end
return { run=run, init=init }