Jump to content
The simFlight Network Forums

kaha

Members
  • Posts

    124
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by kaha

  1. I understand that. but please let me explain. It works differently for axes and buttons.

    This is part of my .ini file:

    [Axes]
    PollInterval=10
    RangeRepeatRate=10
    0=BS,256,F,66162,66163,66164,66165	-{ TO SIM: COWLFLAP1_SET, COWLFLAP2_SET, COWLFLAP3_SET, COWLFLAP4_SET }-
    1=CZ,256,F,x020025F2,0,0,0	-{ FSUIPC: offset word set, offset 25F2 }-
    
    [Buttons]
    PollInterval=25
    ButtonRepeat=20,10
    18=P72,19,C66080,0 	-{GEAR_DOWN}-
    19=P72,18,C66079,0 	-{GEAR_UP}-

    I now make profile specific assignments for button and an axis for a specific aircraft. After that I have:

    [Axes]
    PollInterval=10
    RangeRepeatRate=10
    0=BS,256,F,66162,66163,66164,66165	-{ TO SIM: COWLFLAP1_SET, COWLFLAP2_SET, COWLFLAP3_SET, COWLFLAP4_SET }-
    1=CZ,256,F,x020025F2,0,0,0	-{ FSUIPC: offset word set, offset 25F2 }-
    
    [Buttons]
    PollInterval=25
    ButtonRepeat=20,10
    18=P72,19,C66080,0 	-{GEAR_DOWN}-
    19=P72,18,C66079,0 	-{GEAR_UP}-
    
    [Axes.Beaver]
    RangeRepeatRate=10
    0=BS,256,F,66162,66163,66164,66165	-{ TO SIM: COWLFLAP1_SET, COWLFLAP2_SET, COWLFLAP3_SET, COWLFLAP4_SET }-
    1=CZ,256,F,x020025F2,0,0,0	-{ FSUIPC: offset word set, offset 25F2 }-
    2=KR,R0,F,67011,0,0,0	-{ TO SIM: ANTI_ICE_GRADUAL_SET }-
    
    [Buttons.Beaver]
    1=PC,11,CL30:R,1 	-{Lua Beav_TankSelect}-
    7=PC,15,CL31:R,0 	-{Lua Beav_FuelPump}-

    All the default axis assignments go into the Beaver axis section (which I don't want), but none of the default button assignments go to the Beaver button assignments.

    Now I change the default axis assignment from offset 25F2 to 25F4 and the button for gear down also changes from 19 to 13:

    [Axes]
    PollInterval=10
    RangeRepeatRate=10
    0=BS,256,F,66162,66163,66164,66165	-{ TO SIM: COWLFLAP1_SET, COWLFLAP2_SET, COWLFLAP3_SET, COWLFLAP4_SET }-
    1=CZ,256,F,x020025F2,0,0,0	-{ FSUIPC: offset word set, offset 25F4 }-
    
    [Buttons]
    PollInterval=25
    ButtonRepeat=20,10
    18=P72,13,C66080,0 	-{GEAR_DOWN}-
    19=P72,18,C66079,0 	-{GEAR_UP}-
    
    [Axes.Beaver]
    RangeRepeatRate=10
    0=BS,256,F,66162,66163,66164,66165	-{ TO SIM: COWLFLAP1_SET, COWLFLAP2_SET, COWLFLAP3_SET, COWLFLAP4_SET }-
    1=CZ,256,F,x020025F2,0,0,0	-{ FSUIPC: offset word set, offset 25F2 }-
    2=KR,R0,F,67011,0,0,0	-{ TO SIM: ANTI_ICE_GRADUAL_SET }-
    
    [Buttons.Beaver]
    1=PC,11,CL30:R,1 	-{Lua Beav_TankSelect}-
    7=PC,15,CL31:R,0 	-{Lua Beav_FuelPump}-

    Now gear down still works for all aircraft. If I would want to have a different button for a specific aircraft I would assign it profile specific.

    The axis that now goes to offset 25F4 only works for aircraft that do not have profile specific axes assignments.

     

    I think the way it works for buttons is the better one.

  2. 2 minutes ago, John Dowson said:

    Yes - to change an axis assignment (in the GUI) for a profile, you need to load an aircraft that uses that profile first.

    Yes, but the other way, if I want to change an axis assignment that is not profile specific, I have to load an aircraft that does not have any profile specific axis assingments.

    Then I change the axis assignment and it goes to the [AXIS] section.

     

    Now, all aircraft that do have profile specific axis assignments will not see the change, I have to manually update all [Axis.xx] sections in the .ini file.

  3. This:

    value = 34	
    
    calc_code = value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:1, Percent) " ..
    			value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:2, Percent) " ..
    			value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:3, Percent) " 
    
    ipc.execCalcCode(calc_code)

    results in the following string being executed:

    "34 (>A:GENERAL ENG THROTTLE LEVER POSITION:1, Percent) 34 (>A:GENERAL ENG THROTTLE LEVER POSITION:2, Percent) 34 (>A:GENERAL ENG THROTTLE LEVER POSITION:3, Percent) "

    This should be perfectly valid RPN code, isn't it?

     

    What do you mean when you say "using registers"

  4. Hello John,

    Doing 

    		calc_code = value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:1, Percent) " ..
    					value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:2, Percent) " ..
    					value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:3, Percent) " 
    		ipc.execCalcCode(calc_code)

    is the same as this, I think. At least it works perfectly:

    		calc_code = value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:1, Percent)"
    		ipc.execCalcCode(calc_code)
    		
    		calc_code = value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:2, Percent)"
    		ipc.execCalcCode(calc_code)
    		
    		calc_code = value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:3, Percent)" 
    		ipc.execCalcCode(calc_code)

    But maybe I'm missing something concerning "ipc.execCalcCode()?

     

     

    This:

    value = value > 99.0 and 100 or value < 1.0 and 0 or value

    can be done due to the fact that true and false work differently in lua than in any other language. It makes sure that any value greater than 99.0 becomes 100.0 and any value smaller than 1.0 becomes 0.0

    The construct

    x > y and a or b

    would in C/C++ read:

    x > y ? a : b;

     

  5. John, I've got a question: What's the better choice? To split code in seperate files like this:

    ------------ file 1 ----------------------------
    
    function throttle1(offset, value)	
    function throttle2(offset, value)	
    
    event.offset (0x25F0, "SW", "throttle1")	
    event.offset (0x25F2, "SW", "throttle2")	
    
    
    
    ------------ file 2 ----------------------------
    
    function mixture1(offset, value)	
    function mixture2(offset, value)	
    
    event.offset (0x2550, "SW", "mixture1")	
    event.offset (0x2552, "SW", "mixture2")	

    Or put everything in one file?

     

    Thank you,

    Karl

  6. 1 minute ago, John Dowson said:

    Ok, that makes sense, and is basically what the preset does. I don't understand why you cannot control multiple throttles in the same calculator code string though.

    I have 2 throttle levers and what I'm actually doing is controlling the left 3 and the right 3 seperately, or (by a switch) all 6 using the left throttle.


     

    event.offset (0x25F0, "SW", "throttle1")    
    event.offset (0x25F2, "SW", "throttle2")    
    
    
    function throttle1(offset, value)    
        if user_aircraft_type:find(special_aircraft_names["BAE146"], 1, true) then
            ipc.control(67103, value)
            ipc.control(67110, value)
            if logic.And(ipc.buttons("C"), 8388608) == 8388608 then    
                ipc.control(67117, value)
                ipc.control(67124, value)
            end
        elseif user_aircraft_type:find(special_aircraft_names["LATECOERE"], 1, true) then
            value = ((value + 16384) / 32767.0) * 100.0
            value = value > 99.0 and 100 or value < 1.0 and 0 or value
            calc_code = value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:1, Percent) " ..
                        value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:2, Percent) " ..
                        value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:3, Percent) " 
            ipc.execCalcCode(calc_code)
            if logic.And(ipc.buttons("C"), 8388608) == 8388608 then    
                calc_code = value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:4, Percent) " ..
                            value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:5, Percent) " ..
                            value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:6, Percent) " 
                ipc.execCalcCode(calc_code)
            end
        else
            ipc.control(67103, value)
            if logic.And(ipc.buttons("C"), 8388608) == 8388608 then    
                ipc.control(67110, value)
            end
        end
    end
    
    function throttle2(offset, value)    
        if user_aircraft_type:find(special_aircraft_names["BAE146"], 1, true) then
            if logic.And(ipc.buttons("C"), 8388608) ~= 8388608 then    
                ipc.control(67117, value)
                ipc.control(67124, value)
            end
        elseif user_aircraft_type:find(special_aircraft_names["LATECOERE"], 1, true) then
            value = ((value + 16384) / 32767.0) * 100.0
            value = value > 99.0 and 100 or value < 1.0 and 0 or value
            if logic.And(ipc.buttons("C"), 8388608) ~= 8388608 then    
                calc_code = value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:4, Percent) " ..
                            value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:5, Percent) " ..
                            value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:6, Percent) " 
                ipc.execCalcCode(calc_code)
            end
        else
            if logic.And(ipc.buttons("C"), 8388608) ~= 8388608 then    
                ipc.control(67110, value)
            end
        end
    end

     


    Karl

    • Like 1
  7. Thank you.

     

    I control throttles individually in a lua script using execCalcCode. This works from engine 1 to engine 6.

            calc_code = value .. " (>A:GENERAL ENG THROTTLE LEVER POSITION:1, Percent)"
            ipc.execCalcCode(calc_code)

     

    There are also variables for mixture and pitch: A:GENERAL ENG THROTTLE LEVER POSITION:1 and A:GENERAL ENG PROPELLER LEVER POSITION:1, but they only work for engines 1 to 4.

    Just wanted to be sure that those variables cannot be accessed somehow.

    Karl

     

  8. How can I get a notification that an aircraft is unloaded in an automatically loaded lua script [AUTO]?

    I use a bidirectional com communication between the Arduinos and my lua scripts. My Arduinos know which aircraft is currently loaded and can react accordingly. I do that using the offset event at 0x3D00. Now, as an example, if I go back to main menu in the sim no aircraft is loaded anymore but the Arduino doesn't know.

    At the moment the Arduino has to poll the lua script to check if it is still running. It would be nice to have sort of a callback in the lua script that tells me the script is about to end because the aircraft is unloaded.

    Any chance to get that?

  9. John, this works. 

    For the WBsim 172 I had all 4 lights working already. It was the Asobo classic 172 I was struggeling with. 

     

    I use a switch to switch the light on (to 75%) and off:

     

    local light = math.floor(ipcPARAM / 1000)
    local percent = ipcPARAM - light * 1000
    local n
    
    if light < 1 or light > 30 then return end
    
    local function rtrim(s)
    	n = #s
    	while n > 0 and string.byte(s:sub(n, n)) < 32 or string.byte(s:sub(n, n)) > 127 do 
    		n = n - 1 
    	end
    	return s:sub(1, n)
    end
    
    local aircraft_name = ipc.readSTR(0x3D00, 256)
    aircraft_name = rtrim(aircraft_name)
    
    --ipc.log("Aircraft = " .. aircraft_name)
    
    if aircraft_name:find("Cessna Skyhawk Asobo", 1, true) and not aircraft_name:find("WB", 1, true) then
    	if light == 5 then	-- pedestral lights
    		calc_code = percent .. " s0 (>L:LIGHTING_PEDESTRAL_1) l0 1 (>K:2:PEDESTRAL_LIGHTS_POWER_SETTING_SET) l2 ! 1 l0 (>K:2:PEDESTRAL_LIGHTS_SET)"
    		ipc.execCalcCode(calc_code)
    	end
    end
    

     

    Switch.jpg.ff266e66029e869571dfc3fbf5bae515.jpg

     

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.