Startup conditions

Announcements, questions
Post Reply
adrianp
Posts: 13
Joined: 03 Nov 2016, 14:26

Startup conditions

Post by adrianp » 04 May 2017, 21:21

Hello, I want implement code that reads states of switches in my cockpit (xplane) and writes datrefs acoordingly so when loading a plane there are no diferences in the state of the plane switches and my real switches. Of course this only at macro startup or when loading a new plane. i presume what i want to do is not posible as macros are event driven but i ask just in case.

thanks in advance

admin
Site Admin
Posts: 431
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Startup conditions

Post by admin » 05 May 2017, 07:33

You can check my luascript that I use for xplane: https://github.com/me2d13/luamacros/blo ... c.lua#L291
I have function setPlane which is called when I load some aircraft - it's hooked to variable change with aicraft name - works pretty well. That could be a good place for init stuff:

Code: Select all

lmc_on_xpl_var_change('sim/aircraft/view/acf_tailnum', setPlane)
Petr Medek
HIDmacros author

adrianp
Posts: 13
Joined: 03 Nov 2016, 14:26

Re: Startup conditions

Post by adrianp » 05 May 2017, 14:54

Thanks Petr, yes function SetPlane is good to put my init code but the problem is the code to put there, what i want is to read state of real switches (hardware) and syncronise in the model plane once loaded. As an example when i load a new plane PBrake is ON in the model, but my real switch is off (from last flight) so when i start taxi i have to turn ON - OFF to release PBrake on model, same for some other switches.
In short is there a way i can syncro states of real switches with modeled on aircraft. ?

I dont know if my idea is understandable my english is poor....

Thanks for your time...

admin
Site Admin
Posts: 431
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Startup conditions

Post by admin » 05 May 2017, 15:29

So why don't you read physical state of your hw switches in the init code and send appropriate commands to xplane?
It even does nothing (if the swicth and xpl are in sync) or toggle the switch (in xpl) to correct possition...
Petr Medek
HIDmacros author

adrianp
Posts: 13
Joined: 03 Nov 2016, 14:26

Re: Startup conditions

Post by adrianp » 05 May 2017, 16:53

sorry to post easy questions, it must be easy but i dont find how to do that... till now i send xplane commands in response to actions (switches changes) using something like :

lmc_set_handler('JOY1',function(button, direction, ts)
print('Callback for whole joystick: button ' .. button .. ', direction '..direction..', timestamp '..ts)

if (button == some button) and (direction == 1) then ..do some action.. end

end)

but how i read switches states and send commands without toggling them ?

thanks

admin
Site Admin
Posts: 431
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Startup conditions

Post by admin » 09 May 2017, 07:58

Ahh, you got me :-/
This is the way it was implemented in HidMacros (you can read current state) but LuaMacros is 100% event driven for game devices.
Hmm, looks like we have a feature request here...
Petr Medek
HIDmacros author

adrianp
Posts: 13
Joined: 03 Nov 2016, 14:26

Re: Startup conditions

Post by adrianp » 09 May 2017, 20:29

admin wrote: Hmm, looks like we have a feature request here...
Well if it`s posible would be nice for me... thanks gaian for your great app.

admin
Site Admin
Posts: 431
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Startup conditions

Post by admin » 15 Jul 2017, 20:25

From version 0.1.1.14 (made available for download now) there's a new function to find out current joystick button state even if no change was done (and no event came yet)

Code: Select all

print(lmc_get_button('LB2', 9))
First argument is of course device name and second is button number starting from 1 - same numbering as in windows device state window (where you can calibrate your joystick)
Petr Medek
HIDmacros author

adrianp
Posts: 13
Joined: 03 Nov 2016, 14:26

Re: Startup conditions

Post by adrianp » 24 Jul 2017, 15:32

Excelent !! thanks for your time spent on this feature.. will test in next few days.

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests