Looking to add physical buttons to select what the Knobster will control.

Support for the SimWareKits Knobster in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
robertwaite
Posts: 9
Joined: Fri Sep 25, 2020 10:54 pm

Re: Looking to add physical buttons to select what the Knobster will control.

#11 Post by robertwaite »

My Pleasure Keith and Jph,
Thanks for pointing out the code tag.
I have also updated the code with many bug fixes. This instrument is still in the prototyping phase and I have many other ideas to implement this further.

My ideas are as follows
1) get the menu navigation into a JSON string structure to allow for custom menu navigation definitions. It would be a jagged array containing main categories and subpages to each main page. Im likely going to invers how i have it now so that Outer changes main page and inner changes sub page. this would stay consistent with how a GPS dail encoder works.
2) get the command pages to be defined with a JSON array as opposed to functions. Each page would have 5 commands as it is now Out-l, out-r, in-l, in-r, and button with maybe a 6th option with a long press definition. then you have the hold functions which intent to reserve for menu navigation but nothing says you can't define more functions on it if that what you desire.
2.1) Add a long button press event as to allow for an additional function to be defined on the control.
3) Add a visual element on the panel that would print out the current functions assigned commands. This will help you remember what was defined on the command page. Unlikely to help in VR unless we figure out a way to display it within a VR session. Worst case scenario, you forget what was programmed, you lift the headset and take a peek. Jph, im not wired into VR yet for MSFS, but, I will have the reverb G2 as soon as it's out. I have the Vive for X-Plane but dont care to dust that off. I'm more or less preparing. Maybe an audio readback on the menu via a long press could also be feasible.
4) Define other prefix structures to grant functionality based on different simulators as there is no reason we can get this strategy to work with other sims.
5) Define a quick navigation option on the Reset menu. There reset menu is the starting node. With the 5 native options, you can navigate to any of the main menus quickly.
6) create a mechanism that will dynamically set a different profile for the current aircraft being flown. See the button and switch strategy below for more context. That strategy uses a visual queue of where the button is as to be able to determine its location within this knobster strategy.

As for the strategy for buttons and switches, Im likely going to wire into physical buttons as the ideal, but it could be implemented with the Knobster as follows.
Im going to base the button assignments based on a visual queue from the cocktpit. For example lets take the autopilot buttons on the G1000. would would have the pages defined as follows

This profile would be ideal for a button pannel that toggle a function
Autopilot1
In-L=AP, In-R=FD
Out-L=HDG, Out-R=ALT
Autopilot2
In-L=NAV, In-R=VNV
Out-L=APR, Out-R=BC
Autopilot3
In-L=VS, In-R=UP
Out-L=FLC, Out-R=DN

Notice the pattern matches the location of the buttons in the cockpit, making it easy to remember where things are in the menu structure.

As for a switch panel, you can only divide each page with two switches instead of 4 buttons per page like the top example.
If we have switch 1 through 8 defined

SwitchPanel1
In-L=SW1-off, In-R=SW1-on
Out-L=SW2-off, Out-R=SW2-on
SwitchPanel2
In-L=SW3-off, In-R=SW4-on
Out-L=SW4-off, Out-R=SW4-on
SwitchPanel3
In-L=SW5-off, In-R=SW5-on
Out-L=SW6-off, Out-R=SW6-on
SwitchPanel4
In-L=SW7-off, In-R=SW7-on
Out-L=SW8-off, Out-R=SW8-on

So if i have a switch panel with eight switches and the pito-heat is the 8th switch, I would need to get to SwitchPannel4 and use the out-r as the switch. You could always also write logic that would toggle the options and get your switch panel down to 2 pages of 4 commands. The main takeaway is if you can see the switch panel, the definition should match in a way that would let you determine how to get the function based on its sequence or pattern in the cockpit.

One I pull this together, I will undoubtedly look into submitting it for use by others. I think im going to call it "One Knobster to rule them all."

robertwaite
Posts: 9
Joined: Fri Sep 25, 2020 10:54 pm

Re: Looking to add physical buttons to select what the Knobster will control.

#12 Post by robertwaite »

so this section documents what i have gotten so far in trying to wire up a G1000 layout of the auto-pilot buttons.
it depicts some of the challenges I'm having with the rather buggy MSFS2020 early stages


Im still testing this setup. ill report on any other funk going on.

Code: Select all

function KnobsterMode_AutoPilot1(typecmd)
    --there is a pattern to how these are laid out. This is structured
    --based on the G1000 autopilot. if you envision the buttons in three
    --blocks of 4 you will realize a pattern-making identifying what menu and 
    --direction goes with each block
    --in the first set we have buttons in this pattern
    -- Top Left    = AP , FD  = Top Right
    -- Botton LEft = HDG, ALT = Bottom Right
    --note how the inner dial(top) and outer dial(Bottom) of the knobster map out to this.
    --the next 2 autopilot pages map out the same way so that as long 
    --as you have a visual reference to the buttons you can quickly determine what Menu, 
    --dial, and direction is needed to engage the function.

    SoundToPlayOnRelease                      = "AutoPilot1"
    inner_knob_ccw_function       = msfsEventFlag .. "AP_MASTER" 
    inner_knob_cw_function        = msfsEventFlag .. "TOGGLE_FLIGHT_DIRECTOR" 
    --there is a super anoying bug in MSFS2020 where AP_HDG_HOLD resets the 
    --heading bug to the current heading. Im working on an alternate method to 
    --work around the issue but need to do more research. see commented out code at the
    --bottom for more detail
    --outter_knob_ccw_function      = "AP_HDG_HOLD"
    outter_knob_ccw_function      = msfsEventFlag .. "AP_HDG_HOLD" 
    outter_knob_cw_function       = msfsEventFlag .. "AP_ALT_HOLD" 
    
    pressed_outter_knob_ccw_function = resetMode
    pressed_outter_knob_cw_function   = "KnobsterMode_AutoPilot2"
    pressed_inner_knob_ccw_function  = resetMode
    pressed_inner_knob_cw_function   = "KnobsterMode_AutoPilot2"
    button_function                             = resetMode
    
    --todo: define an alternate autopilot system using the same strategy 
    --        to use physical location to determine how this page will  
    --        be laid out.   
    
end
si_command_subscribe("KnobsterMode_AutoPilot1", KnobsterMode_AutoPilot1)

function KnobsterMode_AutoPilot2(typecmd)
    SoundToPlayOnRelease                      = "AutoPilot2"
    --following the same pattern in AutoPilot1
    --envision the next block of buttons as
    -- Top Left    = NAV, VNV  = Top Right
    -- Botton LEft = APR, BC   = Bottom Right
    
    inner_knob_ccw_function       = msfsEventFlag .. "AP_NAV1_HOLD"
    --I cant find an event for Verticl Nav and assume its forth comming
    --if you have any insight on getting this to work please reach out to 
    --robertwaite77@gmail.com
    inner_knob_cw_function        = msfsEventFlag .. "VNV" --this does not work 
    outter_knob_ccw_function      = msfsEventFlag .. "AP_APR_HOLD" --AP_LOC_HOLD this seems similar
    outter_knob_cw_function       = msfsEventFlag .. "AP_BC_HOLD"

    pressed_outter_knob_ccw_function = "KnobsterMode_AutoPilot1"
    pressed_outter_knob_cw_function  = "KnobsterMode_AutoPilot3"
    pressed_inner_knob_ccw_function  = resetMode
    pressed_inner_knob_cw_function   = "KnobsterMode_AutoPilot3"
    button_function                  = resetMode
   
    --todo: define an alternate autopilot system using the same strategy 
    --        to use physical location to determine how this page will  
    --        be laid out.   
    
   
end
si_command_subscribe("KnobsterMode_AutoPilot2", KnobsterMode_AutoPilot2)

function KnobsterMode_AutoPilot3(typecmd)
    SoundToPlayOnRelease                     = "AutoPilot3"
    --following the same pattern in previous two blocks
    --envision the bottom block of buttons as
    -- Top Left    = VS , UP  = Top Right
    -- Botton LEft = FLC, DN  = Bottom Right

    -- I have not found any event yet that sets the Verticle Speed mode
    -- Please reach out if you know of a way to wire this up correctly
    inner_knob_ccw_function       = "AP_VS" --not working
    --in a G1000 the up and dn buttons control both the verticle speed and flight
    --level change speeds. I have not found an equivalent. If the VS speed was 
    --working i would likely code up AP_VS_VAR_DEC and AP_VS_VAR_INC to work
    --depending on which of the modes are selected. I suspect in the long run we will get a
    --direct event to engage this specific function so we need not code it.
    inner_knob_cw_function        = msfsEventFlag .. "AP_SPD_VAR_INC" 
    --the AP_AIRSPEED_HOLD event is also very buggy.
    --IF you try to engage it while not in FLC mode it does nothing. 
    --if this is invoked while already in FLC mode it will in turn sets your airspeed to 
    --over 300 knots and your plane goes into a dive. So further research is 
    --needed to find a better event or wait for a better fix.
    outter_knob_ccw_function      = msfsEventFlag .. "AP_AIRSPEED_HOLD"
    outter_knob_cw_function       = msfsEventFlag .. "AP_SPD_VAR_DEC"
    
    pressed_outter_knob_ccw_function = "KnobsterMode_AutoPilot2"
    pressed_outter_knob_cw_function  = "KnobsterMode_VOR1"
    pressed_inner_knob_ccw_function  = resetMode
    pressed_inner_knob_cw_function   = "KnobsterMode_VOR1"
    button_function                  = resetMode
    --AP_ATT_HOLD
    
    
    --todo: define a alternate autopilot system using the same strategy 
    --        to use phisical location to determin how this page will  
    --        be laid out.   
end
si_command_subscribe("KnobsterMode_AutoPilot3", KnobsterMode_AutoPilot3)

dpaget21
Posts: 12
Joined: Thu Sep 24, 2020 9:05 am

Re: Looking to add physical buttons to select what the Knobster will control.

#13 Post by dpaget21 »

I see you are having the same problem as me with the VS not working
TRY AP_PANEL_VS_ON
I am trying to find a way to use andurino buttons to select which instrument or knob the knobster will control like in your video at the start of this thread, is there any documentation that shows how to interact with the knobster like that?

robertwaite
Posts: 9
Joined: Fri Sep 25, 2020 10:54 pm

Re: Looking to add physical buttons to select what the Knobster will control.

#14 Post by robertwaite »

@dpaget21
I am so greatful for you sharing the AP_PANEL_VS_ON code. It worked like a charm and now have that mode dialed in.
Im curious how you knew that. I was unable to find that code in the references in the link on airmanager and assume thats on account of it technically being for the old FSX version.
I assume whatever reference you have might point me in the right direction for some other challenges i have. at this point the way i have the flight level change mode is very flaky and assume there might be an equivalent code for that control.
Being that everyone has a problem getting the G1000 or GPS dials to work I doubt it has anything in there for that

Anyway to answer your question the only thing you need to have called in your aurduino implementation is something like this.

Code: Select all

si_command("KnobsterMode_Altitude2")
Thats all you need and it can pretty much be implemented anywhere you can call code and it will in turn set the behaviour for the knobster

On the knobster control side whatever control you are using that is selected you would set the codes like this if you are using the strategy I am using in this thread

Code: Select all

function KnobsterMode_Altitude2(typecmd)
    SoundToPlayOnRelease                      = "VS_FLC_Mode"
    outter_knob_ccw_function = msfsEventFlag .. "AP_VS_VAR_DEC"
    outter_knob_cw_function  = msfsEventFlag .. "AP_VS_VAR_INC"
    inner_knob_ccw_function       = msfsEventFlag .. "AP_PANEL_VS_OFF"
    inner_knob_cw_function        = msfsEventFlag .. "AP_PANEL_VS_ON"
    pressed_outter_knob_ccw_function = "KnobsterMode_Altitude1"
    pressed_outter_knob_cw_function  = "KnobsterMode_Altitude3"
    pressed_inner_knob_ccw_function  = resetMode
    pressed_inner_knob_cw_function   = "KnobsterMode_COM1"
    button_function               = resetMode
   
end
si_command_subscribe("KnobsterMode_Altitude2", KnobsterMode_Altitude2) 
I hope this helps?

robertwaite
Posts: 9
Joined: Fri Sep 25, 2020 10:54 pm

Re: Looking to add physical buttons to select what the Knobster will control.

#15 Post by robertwaite »

I googled "AP_PANEL_VS_ON" and found my answer

http://www.fs2x.com/Tutorials_files/FS2 ... Events.txt

AP_PANEL_HEADING_HOLD solved my issue with the heading resetting to the current course when using AP_HDG_HOLD

The Flight level change, G1000, and GPS controls remain elusive but will report on any progress i make

Gixxar
Posts: 63
Joined: Mon Oct 03, 2016 9:55 pm

Re: Looking to add physical buttons to select what the Knobster will control.

#16 Post by Gixxar »

robertwaite wrote: Fri Sep 25, 2020 11:50 pm Hello,
I want to get the behavior depicted in the below screencast to use the knobster instead of a hard-wired dial knob encoder.
https://www.youtube.com/watch?v=mWfKkJd ... tion=share

As in the screencast, my intention is to use this for when MSFS2020 eventually gets VR support.

I assume at this point its not possible to wire in an Arduino button with a function to explicitly set a control as if we selected it with a touch screen.
I want to rule out that assumption before i start playing with an idea i have. Can anyone confirm that assumption?

Ive got some research to do to get up to speed on custom hardware controls before i can do this. My thought is to have a single dual dial control on the interface that is selectable via any normal Air Manager panel. this would be the only control selected while under VR and the Knobster would then always be manipulating that control. I should in theory I should be able to set Inter-instrument communication variables via the button presses on the Arduino to set what I want to control. The code on the primary dial dial control on the panel would send events based on what the active inter instrument variable are.

The only thing that is not clear to me yet is how to configure a dial control. the API documents and the online tutorial only shows a single dial. if you know of any reference that would point me in the right direction on how to set up dial with button control let me know. I only got my knobster yesterday and this will be my first air manager control i will be creating. So I understand i have a learning curve ahead of me.


Again the main thing I'm after is how to create a dial dial control that can be selected for control by a knobster in a conventional air manager panel. Once i figure that out everything else should fall into place. In the meantime ill be hitting the API documents and examples for clues.

thanks I'll be happy to share the end result here once i figure it out.
Robert
This is the exact code that Russ wrote for that VR box. I use it for X-Plane 11 at the moment and half way thought converting it for use with MSFS2020. Hope it helps you out. I have all the sound files also if you wnat them.

Code: Select all

heading_sound = sound_add("heading.wav")
altitude_sound = sound_add("altitude.wav") 
vertspd_sound = sound_add("verticalspd_baro.wav") 
com1_sound = sound_add("stby_com1.wav")
com2_sound = sound_add("stby_com2.wav")
nav1_sound = sound_add("stby_nav1.wav")
nav2_sound = sound_add("stby_nav2.wav")
com1xfr_sound = sound_add("com1_txfr.wav")
com2xfr_sound = sound_add("com2_txfr.wav")
nav1xfr_sound = sound_add("nav1_txfr.wav")
nav2xfr_sound = sound_add("nav2_txfr.wav")
obs1_sound = sound_add("obs_one.wav")
obs2_sound = sound_add("obs_two.wav")
dirv1_sound = sound_add("direct_vor1.wav")
dirv2_sound = sound_add("direct_vor2.wav")
nogps_1_sound = sound_add("no_gps1.wav")
nogps_2_sound = sound_add("no_gps2.wav")
g530_1_sound = sound_add("G530_1.wav")
g530_2_sound = sound_add("G530_2.wav")
g1000_1_sound = sound_add("G1000_1.wav")
g1000_2_sound = sound_add("G1000_2.wav")
ignition_1_sound = sound_add("eng1_ign.wav")
ignition_2_sound = sound_add("eng2_ign.wav")
sync_hdg_sound = sound_add("sync_hdg.wav")
sync_alt_sound = sound_add( "sync_alt.wav")
sync_vs_sound = sound_add( "sync_vs.wav")
cursor_sound = sound_add( "cursor.wav")
inop_sound = sound_add("inop.wav")
engage_1_sound = sound_add("engage_start1.wav")
engage_2_sound = sound_add("engage_start2.wav")
release_sound = sound_add("release_start.wav")
-- Play the sound
--sound_play(mysound1)

local outer_accel=3
local outer_clockwise= nil
local outer_counter_clockwise = nil
local inner_accel=1
local inner_clockwise= nil
local inner_counter_clockwise = nil
local button_push = "none"
local button_release = "none"
local type_gps1 = "NONE"
local type_gps2 = "NONE"
local dir_bear1= 0
local dir_bear2 = 0
local heading_bug = 0
local alt_bug = 0
local obs_1 = 0
local obs_2= 0
local play_sync = nil

-- User properties
gps1_prop = user_prop_add_enum("No. 1 GPS Type", "G530,G1000,NONE","NONE", "Choose type for GPS 1 knob")
type_gps1 = user_prop_get(gps1_prop)
gps2_prop = user_prop_add_enum("No. 2 GPS Type", "G530,G1000,NONE","NONE",  "Choose type for GPS 2 knob")
type_gps2 = user_prop_get(gps2_prop)


--Button 1,1   Headingx10, Heading, HDG sync

function button11_pressed()
	sound_play(heading_sound)
	outer_accel=10
	outer_clockwise= "sim/autopilot/heading_up"
	outer_counter_clockwise = "sim/autopilot/heading_down"
	inner_accel=1
	inner_clockwise= "sim/autopilot/heading_up"
	inner_counter_clockwise = "sim/autopilot/heading_down"
	button_push = "sim/autopilot/heading_sync"
	button_release = "none"
	play_sync = sync_hdg_sound
end

hw_button_add("ARDUINO_NANO_A_D7", button11_pressed)

--Button 1,2   ALTx10, Alt, Alt sync

function button12_pressed()
	sound_play(altitude_sound)
	outer_accel=10
	outer_clockwise= "sim/autopilot/altitude_up"
	outer_counter_clockwise = "sim/autopilot/altitude_down"
	inner_accel=1
	inner_clockwise= "sim/autopilot/altitude_up"
	inner_counter_clockwise = "sim/autopilot/altitude_down"
	button_push = "sim/autopilot/altitude_sync"
	button_release = "none"
	play_sync = sync_alt_sound
end

hw_button_add("ARDUINO_NANO_A_D8", button12_pressed)

--Button 1,3   VS, baro, VS sync

function button13_pressed()
	sound_play(vertspd_sound)
	outer_accel= 1
	outer_clockwise= "sim/autopilot/vertical_speed_up"
	outer_counter_clockwise = "sim/autopilot/vertical_speed_down"
	inner_accel= 1
	inner_clockwise= "sim/instruments/barometer_up"
	inner_counter_clockwise = "sim/instruments/barometer_down"
	button_push = "sim/autopilot/vertical_speed_sync"
	button_release = "none"
	play_sync = sync_vs_sound
end

hw_button_add("ARDUINO_NANO_A_D9", button13_pressed)

--Button 2,1   Com 1 stby, Com 2 stby, flip coms

local  com_sel = 0
function button21_pressed()
	outer_accel= 1
	inner_accel= 1
	com_sel = math.abs( com_sel -  1)
		if com_sel == 1 then
		n= "1"
		sound_play(com1_sound)
	else
		n= "2"
		sound_play(com2_sound)
	end
	outer_clockwise= "sim/radios/stby_com"..n.."_coarse_up_833"
	outer_counter_clockwise = "sim/radios/stby_com"..n.."_coarse_down_833"
	inner_clockwise= "sim/radios/stby_com"..n.."_fine_up_833"
	inner_counter_clockwise = "sim/radios/stby_com"..n.."_fine_down_833"
	button_push = "com_toggle"..n
	button_release = "none"
	play_sync = nil
end

hw_button_add("ARDUINO_NANO_A_D10", button21_pressed)

--Button 2,2   Nav 1 stby, Nav 2 stby, flip navs
local  nav_sel = 0
function button22_pressed()
	outer_accel= 1
	inner_accel= 1
	nav_sel = math.abs( nav_sel -  1)
	if nav_sel == 1 then
		n= "1"
		sound_play(nav1_sound)
	else
		n= "2"
		sound_play(nav2_sound)
	end
	outer_clockwise= "sim/radios/stby_nav"..n.."_coarse_up"
	outer_counter_clockwise = "sim/radios/stby_nav"..n.."_coarse_down"
	inner_clockwise= "sim/radios/stby_nav"..n.."_fine_up"
	inner_counter_clockwise = "sim/radios/stby_nav"..n.."_fine_down"
	button_push = "nav_toggle"..n
	button_release = "none"
	play_sync = nil
end

hw_button_add("ARDUINO_NANO_A_D11", button22_pressed)

--Button 2,3   Obs 1, Obs 2, Toggle
local  obs_sel = 0
function button23_pressed()
	outer_accel= 10
	inner_accel= 1
	obs_sel = math.abs( obs_sel -  1)
	if obs_sel == 1 then
		n= "1"
		sound_play(obs1_sound)
	else
		n= "2"
		sound_play(obs2_sound)
	end
	outer_clockwise= "sim/radios/obs"..n.."_up"
	outer_counter_clockwise = "sim/radios/obs"..n.."_down"
	
	inner_clockwise= "sim/radios/obs"..n.."_up"
	inner_counter_clockwise = "sim/radios/obs"..n.."_down"
	button_push = "direct"..n
	button_release = "none"
	play_sync = nil
end

hw_button_add("ARDUINO_NANO_A_D12", button23_pressed)

--Button 3, 1   GPS1

function button31_pressed()
	outer_accel= 1
	inner_accel= 1
	if type_gps1 == "NONE" then
		sound_play(nogps_1_sound)
		outer_clockwise=  "none"
		outer_counter_clockwise =  "none"
		inner_clockwise=  "none"
		inner_counter_clockwise =  "none"
		button_push = "none"
		button_release = "none"
		play_sync = inop_sound
	elseif  type_gps1 == "G530"  then
		sound_play(g530_1_sound)
		outer_clockwise= "sim/GPS/g430n1_chapter_up"
		outer_counter_clockwise = "sim/GPS/g430n1_chapter_dn"
		inner_clockwise= "sim/GPS/g430n1_page_up"
		inner_counter_clockwise = "sim/GPS/g430n1_page_dn"
		button_push = "sim/GPS/g430n1_cursor"
		button_release = "none"
		play_sync = cursor_sound
	elseif  type_gps1 == "G1000"  then
		sound_play(g1000_1_sound)
		outer_clockwise= "sim/GPS/g1000n1_fms_outer_up"
		outer_counter_clockwise = "sim/GPS/g1000n1_fms_outer_down"
		inner_clockwise= "sim/GPS/g1000n1_fms_inner_up"
		inner_counter_clockwise = "sim/GPS/g1000n1_fms_inner_down"
		button_push = "sim/GPS/g1000n1_cursor"
		button_release = "none"
		play_sync = cursor_sound
	end
	
end

hw_button_add("ARDUINO_NANO_A_A5", button31_pressed)

--Button 3, 2   GPS2

function button32_pressed()
	outer_accel= 1
	inner_accel= 1
	if type_gps2 == "NONE" then
		sound_play(nogps_2_sound)
		outer_clockwise=  "none"
		outer_counter_clockwise =  "none"
		inner_clockwise=  "none"
		inner_counter_clockwise =  "none"
		button_push = "none"
		button_release = "none"
		play_sync = inop_sound
	elseif  type_gps2 == "G530"  then
		sound_play(g530_2_sound)
		outer_clockwise= "sim/GPS/g430n2_chapter_up"
		outer_counter_clockwise = "sim/GPS/g430n2_chapter_dn"
		inner_clockwise= "sim/GPS/g430n2_page_up"
		inner_counter_clockwise = "sim/GPS/g430n2_page_dn"
		button_push = "sim/GPS/g430n2_cursor"
		button_release = "none"
		play_sync = cursor_sound
	elseif  type_gps2 == "G1000"  then
		sound_play(g1000_2_sound)
		outer_clockwise= "sim/GPS/g1000n2_fms_outer_up"
		outer_counter_clockwise = "sim/GPS/g1000n2_fms_outer_down"
		inner_clockwise= "sim/GPS/g1000n2_fms_inner_up"
		inner_counter_clockwise = "sim/GPS/g1000n2_fms_inner_down"
		button_push = "sim/GPS/g1000n2_cursor"
		button_release = "none"
		play_sync = cursor_sound
	end
	
end

hw_button_add("ARDUINO_NANO_A_A4", button32_pressed)

--Button 3,3   Start 1, start 2, Toggle
local  start_sel = 0
function button33_pressed()
	outer_accel= 1
	inner_accel= 1
	start_sel = math.abs( start_sel -  1)
	if start_sel == 1 then
		n= "1"
		sound_play(ignition_1_sound)
	else
		n= "2"
		sound_play(ignition_2_sound)
	end
	outer_clockwise= "sim/ignition/ignition_up_"..n
	outer_counter_clockwise = "sim/ignition/ignition_down_"..n
	
	inner_clockwise= "sim/ignition/ignition_up_"..n
	inner_counter_clockwise =  "sim/ignition/ignition_down_"..n
	button_push = "starter"..n
	button_release = "stop"..n
	
end

hw_button_add("ARDUINO_NANO_A_A3", button33_pressed)

-- Outer Knob Encoder


-- Callback function which is called when the rotary encoder is turned
-- direction 1 : The dial turned clockwise
-- direciton -1: The dial turned counterclockwise
function outer_dial_change(direction)

  if direction == 1 then

		xpl_command(outer_clockwise)

	

  elseif direction == -1 then
  

		xpl_command(outer_counter_clockwise)

  end

end

-- Bind to Arduino A 
--hw_dial_add("ARDUINO_NANO_A_D3", "ARDUINO_NANO_A_D2", outer_accel, outer_dial_change)
hw_dial_add("OUTER_KNOB", outer_accel, outer_dial_change)
-- Inner Knob Encoder

function inner_dial_change(direction)

  if direction == 1 then

		xpl_command(inner_clockwise)


  elseif direction == -1 then
  

		xpl_command(inner_counter_clockwise)

  end

end

-- Bind to Arduino A 
--hw_dial_add("ARDUINO_NANO_A_D4", "ARDUINO_NANO_A_D5", inner_accel, inner_dial_change)
hw_dial_add("INNER_KNOB", inner_accel, inner_dial_change)

function button_released()
	if button_release == "stop1" then

		xpl_command("sim/ignition/ignition_up_1", 0)
		sound_stop(engage_1_sound)
		sound_play(release_sound)

	elseif button_release == "stop2" then

		xpl_command("sim/ignition/ignition_up_2", 0)
		sound_stop(engage_2_sound)
		sound_play(release_sound)

	end
end

function button_pressed()
	if button_push == "com_toggle1" then
	sound_play(com1xfr_sound)
		xpl_command("sim/radios/com1_standy_flip")
	elseif button_push == "com_toggle2" then
		xpl_command("sim/radios/com2_standy_flip")
		sound_play(com2xfr_sound)
	elseif button_push == "nav_toggle1" then
		xpl_command("sim/radios/nav1_standy_flip")
		sound_play(nav1xfr_sound)
	elseif button_push == "nav_toggle2" then
		xpl_command("sim/radios/nav2_standy_flip")
		sound_play(nav2xfr_sound)
	elseif button_push == "direct1" then 
		sound_play(dirv1_sound)
		xpl_dataref_write("sim/cockpit2/radios/actuators/nav1_obs_deg_mag_pilot","FLOAT", dir_bear1)
	elseif button_push == "direct2" then
		sound_play(dirv2_sound)
		xpl_dataref_write("sim/cockpit2/radios/actuators/nav2_obs_deg_mag_pilot","FLOAT", dir_bear2)
	elseif button_push == "starter1" then
		sound_play(engage_1_sound)
		xpl_command("sim/ignition/ignition_up_1", 1)
	elseif button_push == "starter2" then
		sound_play(engage_2_sound)
		xpl_command("sim/ignition/ignition_up_2", 1)
	else
		xpl_command( button_push )
		if play_sync ~= nil then  sound_play(play_sync) end
	end


end

hw_button_add("ARDUINO_NANO_A_D6", button_pressed, button_released)


function set_values( dir1, dir2, hdg, alt, obs1, obs2 )
dir_bear1= dir1
dir_bear2 = dir2
heading_bug = hdg
alt_bug = alt
obs_1 = obs1
obs_2= obs2
end

xpl_dataref_subscribe("sim/cockpit2/radios/indicators/nav1_bearing_deg_mag", "FLOAT","sim/cockpit2/radios/indicators/nav2_bearing_deg_mag", "FLOAT", "sim/cockpit/autopilot/heading_mag", "FLOAT", "sim/cockpit/autopilot/altitude", "FLOAT","sim/cockpit/radios/nav1_obs_degm", "FLOAT", "sim/cockpit/radios/nav2_obs_degm", "FLOAT", set_values)
Lee

Gixxar
Posts: 63
Joined: Mon Oct 03, 2016 9:55 pm

Re: Looking to add physical buttons to select what the Knobster will control.

#17 Post by Gixxar »

Here is a link to the original post I started back in 2018
https://siminnovations.com/forums/viewt ... =38&t=1508

Post Reply