Native Support for ON/OFF/ON Switches
- BradyBrother100
- Posts: 54
- Joined: Tue Oct 13, 2020 4:21 pm
- Location: United States MDT
Native Support for ON/OFF/ON Switches
Hi! It would be nice if Air Manager had a feature to support ON/OFF/ON switches without having to add two ON/OFF switches and combine the OFF states because that can break your code pretty easily. Having the abilty to assign a pin position to OFF or GROUND would be awesome. For example, you add the ON/OFF/ON with the hw_switch_add command and assign it three positions. You would then assign pin pos 0 and pin pos 2 to what ever pins you connected the two ON positions to. For pin pos 1, you could simply select OFF or GROUND and you would be good to go. You could also assign any pin pos to OFF or Ground if you have a Rotary Switch and the first position is OFF. If there is no signal for pin pos 0 and pin pos 2, AM would assume that the switch is in the OFF position. This would also be great for rotary switches since it is hard to find lets say an ON/ON/ON/ON switch that is also at a reasonable price. Could this be a future feature?
Thanks!
Brady
Thanks!
Brady
Re: Native Support for ON/OFF/ON Switches
Hi,
Can't you connect both signals from pos 0 and pos 2 to the same pin and make a two position hw_switch_add?
Corjan
Can't you connect both signals from pos 0 and pos 2 to the same pin and make a two position hw_switch_add?
Corjan
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Native Support for ON/OFF/ON Switches
Hi,
Yes this is far easier. You need the right switch though.
Keith
Yes this is far easier. You need the right switch though.
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
- BradyBrother100
- Posts: 54
- Joined: Tue Oct 13, 2020 4:21 pm
- Location: United States MDT
Re: Native Support for ON/OFF/ON Switches
Hi! The 3 Position switch I have only has three pins instead of six. The two outboard pins being the signal pins and the middle pin being the ground. How would that work?
Last edited by BradyBrother100 on Mon Mar 29, 2021 8:44 pm, edited 1 time in total.
Re: Native Support for ON/OFF/ON Switches
I would not be in favour of wasting an I/O pin for no use. Ask yourself a question. How would this work if it were just the switch and Arduino without AM. Answer the same as it currently works with AM.
12 way adjustable stop switches can be had for around $2 so not sure why you can’t make a 4 way.
12 way adjustable stop switches can be had for around $2 so not sure why you can’t make a 4 way.
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Native Support for ON/OFF/ON Switches
Hi,BradyBrother100 wrote: ↑Mon Mar 29, 2021 8:41 pm Hi! The 3 Position switch I have only has three pins instead of six. The two outboard pins being the signal pins and the middle pin being the ground. How would that work?
Look at getting something like this.
https://www.amplifiedparts.com/products ... 3-position
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
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Native Support for ON/OFF/ON Switches
Hi,
OK I have not tested it because I do not have an arduino set up but you can give this code a try. I suspect that a two position switch that is not in position 0 or 1 will return a nil. If that is the case then this should solve your issue.
Keith
OK I have not tested it because I do not have an arduino set up but you can give this code a try. I suspect that a two position switch that is not in position 0 or 1 will return a nil. If that is the case then this should solve your issue.
Code: Select all
---First we must read the switch state.
--Create a function to read the seatbelt sign position.
sign_state= 0
function seatbelt_callback(sign)
sign_state= sign
print("The sim sign state is "..sign_state)
end
xpl_dataref_subscribe("laminar/B738/toggle_switch/seatbelt_sign_pos","FLOAT",seatbelt_callback)
----------------------------------------------------------------------------------------------------------
new_pos=0
---Create a switch function
function switch_fasten_belts(pos)
---Create your 3 position switch
if pos == 0 then new_pos =0 end
if pos == nil then new_pos =1 end
if pos == 1 then new_pos = 2 end
if sign_state < new_pos then
xpl_command("laminar/B738/toggle_switch/seatbelt_sign_dn")
elseif sign_state > new_pos then
xpl_command("laminar/B738/toggle_switch/seatbelt_sign_up")
end
end
-- Create a new 2 position switch
fasten_belts_switch=hw_switch_add("Fasten Seat Belts",2,switch_fasten_belts)
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
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Native Support for ON/OFF/ON Switches
Hi,
Ok it looks like the switch is a one time read and there is no nil state.
Your only other option is to use a few 2N3904. But honestly as Tony says, far easier to just get the correct switch.
Keith
Ok it looks like the switch is a one time read and there is no nil state.
Your only other option is to use a few 2N3904. But honestly as Tony says, far easier to just get the correct switch.
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
Re: Native Support for ON/OFF/ON Switches
I was referring to the 4 way switch that was mentioned not the on-off-on switch. For that one the solution has already been given in Brady’s other thread about the same subject.Keith Baxter wrote: ↑Tue Mar 30, 2021 6:06 am Your only other option is to use a few 2N3904. But honestly as Tony says, far easier to just get the correct switch.
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Native Support for ON/OFF/ON Switches
Hi,
Ok I tested this HACK. This i think is the best one can do only using three iO pins that will accommodate your switches.
My beer of choice is Amstel.
Keith
Ok I tested this HACK. This i think is the best one can do only using three iO pins that will accommodate your switches.
My beer of choice is Amstel.
![Laughing :lol:](./images/smilies/icon_lol.gif)
Code: Select all
---First we must read the switch position.
--Create a function to read the seatbelt sign position.
sign_state= 0
new_pos =0
function seatbelt_callback(sign)
sign_state= sign
print("The sim sign state is "..sign_state)
end
xpl_dataref_subscribe("laminar/B738/toggle_switch/seatbelt_sign_pos","FLOAT",seatbelt_callback)
----------------------------------------------------------------------------------------------------------
--Create a function to send the command to the sim.
function send_command()
if sign_state < new_pos then
xpl_command("laminar/B738/toggle_switch/seatbelt_sign_dn")
elseif sign_state > new_pos then
xpl_command("laminar/B738/toggle_switch/seatbelt_sign_up")
end
end
--Simulate a switch using button array
-- Callback function which is called when a button is pressed
function button_pressed(row, column)
if column == 0 then new_pos = 0 else new_pos = 2 end
print(new_pos)
send_command()
end
-- Callback function which is called when a button is released
function button_released(row, column)
if row == 0 then new_pos = 1 end
print(new_pos)
send_command()
end
-- Create button array with name "my keypad" with 1 rows and 2 columns
hw_button_array_add("my keypad", 1, 2, button_pressed, button_released)
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