Thank you so much! This really works well!
I modified the script slightly, but this really is an idea solution.
Jessica
-- Using a trim wheel axis to operate with trim INC and DEC instead
-- http://forum.simflight.com/topic/72492-using-a-trim-wheel-axis-to-operate-with-trim-inc-and-dec-instead/
--
-- [Auto]
-- 1=Lua trimwheel
-- assign your axis, in the normal FS controls assignment on the left, to "Luavalue trimwheel".
boundary = 16384-2048
function trimwheel_trim(change)
trim = ipc.readSW(0x0BC0) - change
if trim < -16384 then
trim = -16384
elseif trim > 16383 then
trim = 16383
end
ipc.writeSW(0x0BC0, trim)
end
function trimwheel_ap_vs(change)
if ipc.readUW(0x07BC) == 0 then -- AP disabled
trimwheel_trim(change)
elseif change > 0 then
ipc.control(65895) -- AP_VS_VAR_DEC
elseif change < 0 then
ipc.control(65894) -- AP_VS_VAR_INC
end
end
function trimwheel_ap_pitch(change)
if ipc.readUW(0x07BC) == 0 then -- AP disabled
trimwheel_trim(change)
elseif change > 0 then
ipc.control(66584) -- AP_PITCH_REF_INC_DN
elseif change < 0 then
ipc.control(66583) -- AP_PITCH_REF_INC_UP
end
end
function trimwheel_ap_pitch_atthold(change)
if ipc.readUW(0x07BC) == 0 then -- AP disabled
trimwheel_trim(change)
elseif change > 0 then
if ipc.readUW(0x07D0) > 0 then -- AP alt lock
ipc.control(65804, 1) -- AP_ATT_HOLD_ON
end
ipc.control(66584) -- AP_PITCH_REF_INC_DN
elseif change < 0 then
if ipc.readUW(0x07D0) > 0 then -- AP alt lock
ipc.control(65804, 1) -- AP_ATT_HOLD_ON
end
ipc.control(66583) -- AP_PITCH_REF_INC_UP
end
end
function trimwheel_ap_pitch_althold(change)
if ipc.readUW(0x07BC) == 0 then -- AP disabled
trimwheel_trim(change)
elseif change > 0 then
if ipc.readUW(0x07D0) > 0 then -- AP alt lock
ipc.control(65816, 1) -- AP_ALT_HOLD_OFF
end
ipc.control(66584) -- AP_PITCH_REF_INC_DN
elseif change < 0 then
if ipc.readUW(0x07D0) > 0 then -- AP alt lock
ipc.control(65816, 1) -- AP_ALT_HOLD_OFF
end
ipc.control(66583) -- AP_PITCH_REF_INC_UP
end
end
function trimwheel_c182(change)
if ipc.readUW(0x07BC) == 0 then -- AP disabled
trimwheel_trim(change)
elseif change > 0 then
ipc.writeLvar("kap140_dn_button", 1)
elseif change < 0 then
ipc.writeLvar("kap140_up_button", 1)
else
ipc.writeLvar("kap140_dn_button", 0)
ipc.writeLvar("kap140_up_button", 0)
end
end
function aircraftchange(eventtype)
if ipc.readSTR(0x3D00, 5) == "C182_" then
trimwheel = trimwheel_c182
elseif ipc.readSTR(0x3D00, 12) == "Carenado A36" then
trimwheel = trimwheel_ap_vs
else
trimwheel = trimwheel_trim
end
end
aircraftchange(nil) -- initialize at least once
function checkvalue(val)
if prev ~= nil and val ~= prev then -- axis moved
if math.abs(val) > boundary then
ipc.display(string.format(
"Warning:\n\n" ..
"Trim wheel value near boundary: %d\n" ..
"Reconnect to restore full range.\n",
val), 10)
else
ipc.display("")
end
trimwheel(val - prev)
end
prev = val
end
event.sim(AIRCRAFTCHANGE, "aircraftchange")
event.param("checkvalue")