3 position sw... code not quite right.. Help!

Questions about deployment and use of Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
dameng
Posts: 13
Joined: Tue Apr 12, 2022 2:03 am

3 position sw... code not quite right.. Help!

#1 Post by dameng »

hello, it's me again! i'm making progress with AM and figuring / learning quite a bit.
developed a routine for a 3 position sw, where the off = 0. , Norm = 0.71 , On = 1. and it works when i make the change directly in DR tool.

Issue i'm having is that on my panel, it will only reads the 1st pos, and i'm not sure it's noticing the dir

I verified in DataRefTool that the dr{2} value changes but only on the 1st line, so from Off to Norm. it won't click up to On, nor click down to Off.

here's my code:

Code: Select all

--CABIN 3 POS  almost there..
--"sim/cockpit2/switches/instrument_brightness_ratio" "FLOAT[32]" data[2]
-- ON = 1. NORM = 0.71 OFF = 0.0

function set_cabinltsw_callback(pos, dir)
 if pos == 0 and dir == 1 then
        xpl_dataref_write("sim/cockpit2/switches/instrument_brightness_ratio", "FLOAT[32]", {0.71},2)
    end
    if pos == 0.71 and dir == 1 then
        xpl_dataref_write("sim/cockpit2/switches/instrument_brightness_ratio", "FLOAT[32]", {1.},2)
    end
    if pos == 0.71 and dir == -1 then
        xpl_dataref_write("sim/cockpit2/switches/instrument_brightness_ratio", "FLOAT[32]", {0.},2)
    end
  if position == 1  and dir == -1 then
        xpl_dataref_write("sim/cockpit2/switches/instrument_brightness_ratio", "FLOAT[32]", {0.71},2)
    end
  
end


function cabinltsw_change(val)
    if val == 0.0 then
    switch_set_position(cabinlt_sw,0.)
    end
    if val == 0.71 then
    switch_set_position(cabinlt_sw,0.71)
    end
    if val == 1.0 then
    switch_set_position(cabinlt_sw,1.)
    end
end

cabinlt_sw = switch_add( "togswitch_off.png" , "togswitch_ctr.png","togswitch_on.png", 313,28,42,75, set_cabinltsw_callback)
 
 xpl_dataref_subscribe("sim/cockpit2/switches/instrument_brightness_ratio", "FLOAT[32]", cabinltsw_change)

--END CABIN
I've used this Logic on 2 other 3 position switches that do a dataref_write, but they are an INT, and this one is a FLOAT.
So i'm pretty sure i'm messing up one logic thing, or this format with the float, but trial and error has gotten me this far, now i'm stumped.

let me know,
Thanks,
Dave

Post Reply