Code: Select all
laminar/c172/knob_TAS
So based on Jason Tatum's C172 Airspeed indicator, this snippet of code below works and the TAS scale can be operated either from AM or Xplane.
Of course the values of step and initial rotation angle of -27° needs to be adjusted to your own graphics. Some trial and error is required for fine tuning
Code: Select all
function new_knob(direction)-- The AM dial is turned
card_value=card_value-(0.01*direction) -- We increment/decrement the Xplane TAS value by +/-0.01
card_value=var_cap(card_value,-1.0,1.0) -- We keep it within range
xpl_dataref_write("laminar/c172/knob_TAS","FLOAT",card_value) --and we update the Dataref
end
step=4.5*10 -- Empirical step value to obtain the actual rotation of the card, found by trial and error
function card_pos(knob_TAS)-- The Xplane TAS dial is turned, hence the Dataref is changed
--print(knob_TAS)
card_value=var_cap(knob_TAS,-1.0,1.0)
rotate(as_card, -27-(card_value*step)) -- The initial card rotation angle when the Xplane TAS value is 0.0 is found to be -27 degrees, we turn the card according to the TAS value ranging between -1.0 to +1.0 times the step (note the negative value to turn counterclockwise)
--print( -27-(card_value*step))
end
---------------------------------------------
-- Controls Add --
---------------------------------------------
dial_knob = dial_add("airknob.png", 31, 395, 85, 85, new_knob)
dial_click_rotate(dial_knob,6)
hw_dial_add("KIAS/TAS card dial", 3, new_knob)-- hardware dial
---------------------------------------------
-- Simulator Subscriptions --
---------------------------------------------
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot", "FLOAT", new_speed)
xpl_dataref_subscribe("laminar/c172/knob_TAS","FLOAT",card_pos) -- new dataref subscribe for the Xplane TAS dial position