Controlling the Baron D55 Electric Flaps Gauge

Are you building a cockpit, planning to build one or just dreaming, this is your cockpit builder meeting point

Moderators: russ, Ralph

Message
Author
BaronD55
Posts: 33
Joined: Tue Jul 21, 2020 3:52 am
Location: 40°S,177°E

Re: Controlling the Baron D55 Electric Flaps Gauge

#31 Post by BaronD55 »

I was going to start a new thread but then I realised that my question is still to do with controlling the Flaps Gauge so here we go:-

I have built a 4 position switch using three photo-switches.
So the switch passes one of three values to my callback function depending on its position (0, 1 or 2). I am having difficulty handling the situation where the variable is not assigned a value. The 'else' part was meant to handle this situation but it is not working.

Here is my code snippet for your comments:-

Code: Select all

function switch_callback (position)
      print("The switch got changed to position " .. position)
      if (position == 0) then 
           fsx_variable_write("TRAILING EDGE FLAPS LEFT PERCENT", "Percent", 33)     
        elseif (position == 1) then 
            fsx_variable_write("TRAILING EDGE FLAPS LEFT PERCENT", "Percent", 75)
        elseif (position == 2) then 
            fsx_event("FLAPS_DOWN")
        else
            fsx_event("FLAPS_UP")
     end
end
I am also not sure if I have correctly passed the 'value' parameter to the variable_write function.
Comments welcome

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Controlling the Baron D55 Electric Flaps Gauge

#32 Post by Keith Baxter »

Hi,


For what you want use hw_input_add()
Something along these lines.

Code: Select all

position_zero = hw_input_add("RPI_V2_P1_40", function(state)
    if state then
        fsx_variable_write("TRAILING EDGE FLAPS LEFT PERCENT", "Percent", 33) 
    end
end)
  
position_one = hw_input_add("RPI_V2_P1_41", function(state)
     if state then
        fsx_variable_write("TRAILING EDGE FLAPS LEFT PERCENT", "Percent", 75) 
    end
end)

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

BaronD55
Posts: 33
Joined: Tue Jul 21, 2020 3:52 am
Location: 40°S,177°E

Re: Controlling the Baron D55 Electric Flaps Gauge

#33 Post by BaronD55 »

Hi Keith,
Thank you for your input.

The problem for me was that I was trying to use a 3 position switch to give me four results. When switched to the fourth position nothing was connected and so my variable was not asigned any value.
I was wrongly calling this null, or nil value, a result.
I couldn't write code that could process a variable that is not assigned a value.
I rebuilt the switch as a four position switch that gave four results.
My variable is now always assigned a value and I can always do something with it.
Solved

Post Reply