hw_switch_add issue

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
jim_in_nh
Posts: 40
Joined: Sat Apr 11, 2020 11:54 am

hw_switch_add issue

#1 Post by jim_in_nh »

Hi folks,

My panel is coming together, the Arduino is mounted, and the wiring is being tied down.

Since my hardware "gauge" configuration settings sometimes get wiped-out, I'm going through my file and changing the hw "adds" from Named to Hardware ID formats, so they stay put. They aren't changing, so hard coding them is preferred at this point.

My rotary encoders switched over correctly, as did momentary buttons, and they all work just fine.

But my switches are not going so well. For example, my fuel selector 4 position switch went from ...
hw_switch_add("fuel selector", 4, fuel_selector)
with the four pins listed in the config page ... (don't know if this will show up or not)
Image

to ...
hw_switch_add("ARDUINO_MEGA2560_A_D36","ARDUINO_MEGA2560_A_D37","ARDUINO_MEGA2560_A_D39","ARDUINO_MEGA2560_A_D38", 4, fuel_selector)
and the switches no longer show up in the config page, as expected, but the switch no longer works.

I've looked for missing comma's, typos, misspellings, etc., but I can't see what I'm doing wrong. Any ideas?

Thanks,
Jim
Attachments
image.png
image.png

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

Re: hw_switch_add issue

#2 Post by Keith Baxter »

Hi Jim,

Try this

hw_switch_add("ARDUINO_MEGA2560_A_D36","ARDUINO_MEGA2560_A_D37","ARDUINO_MEGA2560_A_D39","ARDUINO_MEGA2560_A_D38", fuel_selector)

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 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: hw_switch_add issue

#3 Post by Sling »

Yep, Keith’s right. You do not need to specify the nr_pins when not using named hardware because it’s implicit in the number of hardware_ids you use.

jim_in_nh
Posts: 40
Joined: Sat Apr 11, 2020 11:54 am

Re: hw_switch_add issue

#4 Post by jim_in_nh »

Of course! Thank you very much guys. The syntax was right there in front of me in the wiki, and I missed it.

Works perfectly now, thank you.

Would you happen to know if there is a single command, perhaps a reset of sorts, that will cause AM to read all of the hardware and assert the settings accordingly? I've noticed that AM does this when it starts, and I'm in the process of creating a "sync" button that will, in response to a button push on my panel, read all of the switch settings and set them in the simulator? If I load a new flight scenario, I'd like to push one button and have the simulator synchronized to the switch settings, without having to manually cycle all of the switches. I'm learning a lot though, building this thing switch-by-switch, but it occurred to me that if AM does this at start up, there might be a way to initiate it in a Lua script.

Thank you again for your help with the switch set-up!
Jim

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: hw_switch_add issue

#5 Post by Sling »

What I do is continually monitor the sim data and compare it with the hardware states. If for some reason the command did not get through or as in your scenario you load a new flight then this can be used to fix any differences. You can force this to run at regular intervals if you wish but you could also link a button into doing a single pass if this is preferred. It just gives a belt and braces way of ensuring the sim is doing as it’s told. It also helps with dropped commands, although I haven’t seen this myself others have reported it.

Tony

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: hw_switch_add issue

#6 Post by Sling »

I didn’t have any issue. Confused.

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

Re: hw_switch_add issue

#7 Post by Keith Baxter »

Hi Mike,

For hardware switches you need to read the state then activate the commands so that the sim matches the hardware state. (switches and buttons)
For led, relays, stepper motors, 7seg displays, you read the state then set the hardware to suite.

Did you try that code I sent you?

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 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: hw_switch_add issue

#8 Post by Sling »

polarair wrote: Wed Nov 11, 2020 12:37 pm dont be confused :D
I was reading your tread and saw that you had the same issue i have now. I want to read all the hardware states in one go, or a fast way.
What thread is that? I’ve never had an issue with this. So like I say, confused.

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

Re: hw_switch_add issue

#9 Post by Keith Baxter »

Hi Mike

You are not answering my question in the previous post.

"Did you try that code I sent you?"

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 

Post Reply