Page 1 of 1

Startup conditions

Posted: 04 May 2017, 21:21
by adrianp
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

Re: Startup conditions

Posted: 05 May 2017, 07:33
by admin
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)

Re: Startup conditions

Posted: 05 May 2017, 14:54
by adrianp
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...

Re: Startup conditions

Posted: 05 May 2017, 15:29
by admin
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...

Re: Startup conditions

Posted: 05 May 2017, 16:53
by adrianp
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

Re: Startup conditions

Posted: 09 May 2017, 07:58
by admin
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...

Re: Startup conditions

Posted: 09 May 2017, 20:29
by adrianp
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.

Re: Startup conditions

Posted: 15 Jul 2017, 20:25
by admin
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)

Re: Startup conditions

Posted: 24 Jul 2017, 15:32
by adrianp
Excelent !! thanks for your time spent on this feature.. will test in next few days.

Regards