toggle headphones with lua script

Post any technical issues here. This forum gets priority from our staff.
new reply
allergiecheck
Airman
Posts: 24
Joined: 14 Sep 2013, 16:03

toggle headphones with lua script

Post by allergiecheck »

Hi,

I have written a lua script which should switch on/off the headphones automatically when the avionics master switch is turned on/off.
The script catches the event of the avionics master offset and then exists of the 3 commands provided by A2A variable list:

Code: Select all

function Headphones(control, on_off)

ipc.writeLvar("L:Headphones", on_off)

ipc.writeLvar("L:SystemCondSelectFSX", 57)

ipc.writeLvar("L:SystemCondValueFSX", on_off)

end
While the "switching off" code works perfectly fine: I switch off the avionics and the headphones are unplugged immediately - it does NOT work to plugin in the headphones when avionics master is set to "on". For a second, I see the cables of the headphones, than they disappear and I have to use the mouse to plug in the headphones.
Interestingly, also the "map to joystick button" feature does not work either...If I press the assigned Joystick button - same as above: cables are visible for a second, then they disappear.

any ideas to overcome this? I am running P3D version 3.4 (latest built).

Thanks, Thomas

User avatar
renaissanceman
Technical Sergeant
Posts: 597
Joined: 13 Apr 2008, 08:29
Location: Bedford, Texas

Re: toggle headphones with lua script

Post by renaissanceman »

allergiecheck wrote:Hi,

I have written a lua script which should switch on/off the headphones automatically when the avionics master switch is turned on/off.
The script catches the event of the avionics master offset and then exists of the 3 commands provided by A2A variable list:

Code: Select all

function Headphones(control, on_off)

ipc.writeLvar("L:Headphones", on_off)

ipc.writeLvar("L:SystemCondSelectFSX", 57)

ipc.writeLvar("L:SystemCondValueFSX", on_off)

end
While the "switching off" code works perfectly fine: I switch off the avionics and the headphones are unplugged immediately - it does NOT work to plugin in the headphones when avionics master is set to "on". For a second, I see the cables of the headphones, than they disappear and I have to use the mouse to plug in the headphones.
Interestingly, also the "map to joystick button" feature does not work either...If I press the assigned Joystick button - same as above: cables are visible for a second, then they disappear.

any ideas to overcome this? I am running P3D version 3.4 (latest built).

Thanks, Thomas
Hi Thomas,

I'm still a novice at Lua programming, but this is an interesting exercise. I'll try to look at it later today.

Meanwhile someone who actually knows what they're doing may chime in.

Jim
i7-6700K @ 4.0 GHz | ASUS Maximus VIII Formula | 32 GB DDR4 | EVGA GeForce GTX 980TI Classified |
Win 10 Pro 64 | FSX SE | Registered FSUIPC | All Accu-Sim Birds | Accu-Feel v2 | TrackIR5 | AS16 | PRO-ATC/X

alan CXA651
Senior Master Sergeant
Posts: 2438
Joined: 15 Mar 2016, 08:23

Re: toggle headphones with lua script

Post by alan CXA651 »

Hi.
I dont know anything about lvars , but wondering if the words on/off could be replaced with toggle , just an idea.
regards alan. 8)
Image
Image
Image
Image

allergiecheck
Airman
Posts: 24
Joined: 14 Sep 2013, 16:03

Re: toggle headphones with lua script

Post by allergiecheck »

alan CXA651 wrote: ....but wondering if the words on/off could be replaced with toggle , just an idea.
regards alan. 8)
This is just the name of a variable, which is either 0 or 1.

Gypsy Baron
A2A Master Mechanic
Posts: 3396
Joined: 02 Aug 2008, 17:04
Location: San Francisco

Re: toggle headphones with lua script

Post by Gypsy Baron »

I use that same Lua script and I seem to recall that the operation doesn't always 'take' the
first time and I have had to repeat the triggering event again.

I seem to think there is some sort of timing issue with the setting og the condition select variable
and the condition value variable.

I've not flown this aircraft in a long time but what you might do to see if this can be rectified
is repeat the sequence after a short time delay.

function Headphones(control, on_off)

ipc.writeLvar("L:Headphones", on_off)

ipc.writeLvar("L:SystemCondSelectFSX", 57)

ipc.writeLvar("L:SystemCondValueFSX", on_off)

ipc.sleep(50)

ipc.writeLvar("L:Headphones", on_off)

ipc.writeLvar("L:SystemCondSelectFSX", 57)

ipc.writeLvar("L:SystemCondValueFSX", on_off)

end

Paul

Image

User avatar
renaissanceman
Technical Sergeant
Posts: 597
Joined: 13 Apr 2008, 08:29
Location: Bedford, Texas

Re: toggle headphones with lua script

Post by renaissanceman »

Hi Paul,

Thanks for the suggestion, a quick test shows it working. My problem was a little different from Thomas/allergiecheck. When I turned the Avionics Master on, the headphones would appear for a few seconds and disappear. Then turning the Avionics Master off, the headphones would disappear (if they were visible) and then reappear a few seconds later. As I said, with your suggestion it seems to be working. Here is my script, not as elegant as yours and Thomas' but I'm still a novice at Lua programming:

Code: Select all

function Headphones(offset, val)

ipc.setowndisplay("Headphones", 15, 5, 25, 5)	-- Set size and location of display window titled Headphones

AvionicsVal=val	-- Pass 'Master avionics switch' value to 'AvionicsVal' variable
	
	if AvionicsVal == 1 
	
		then
		
			ipc.display("Headphones On  "..AvionicsVal, 5)  -- Display red text for 5 sec
		
			ipc.writeLvar("L:Headphones", 1)
			ipc.writeLvar("L:SystemCondSelectFSX", 57)
			ipc.writeLvar("L:SystemCondValueFSX", 1)
		
			ipc.sleep(50)  -- Pause for 50 msec
		
			ipc.writeLvar("L:Headphones", 1)
			ipc.writeLvar("L:SystemCondSelectFSX", 57)
			ipc.writeLvar("L:SystemCondValueFSX", 1)
		
		else
		
			ipc.display("Headphones Off  "..AvionicsVal, 1, 5)  -- Display white text for 5 sec
		
			ipc.writeLvar("L:Headphones", 0)
			ipc.writeLvar("L:SystemCondSelectFSX", 57)
			ipc.writeLvar("L:SystemCondValueFSX", 0)
		
			ipc.sleep(50)  -- Pause for 50 msec
		
			ipc.writeLvar("L:Headphones", 0)
			ipc.writeLvar("L:SystemCondSelectFSX", 57)
			ipc.writeLvar("L:SystemCondValueFSX", 0)
		
	end
	
end

event.offset(0x2E80,"UB","Headphones")	-- Read value from FSX offset for 'Master avionics switch' and pass to 'Headphones' function above
I'm not sure how you guys are calling the Headphones function. Paul, looking at a FSUIPC.ini you posted last March, you are calling the Lua directly from a button but I don't understand the Cx0D0066C7,x01 in line 38 (38=B66C0=2 PA,2,Cx0D0066C7,x01 ;//Headphones Toggle via Lua Event ;//CM16:12,0 ; )

https://a2asimulations.com/forum/viewto ... 08&t=52377

Not a big deal, I'm just curious.

Jim
i7-6700K @ 4.0 GHz | ASUS Maximus VIII Formula | 32 GB DDR4 | EVGA GeForce GTX 980TI Classified |
Win 10 Pro 64 | FSX SE | Registered FSUIPC | All Accu-Sim Birds | Accu-Feel v2 | TrackIR5 | AS16 | PRO-ATC/X

Gypsy Baron
A2A Master Mechanic
Posts: 3396
Joined: 02 Aug 2008, 17:04
Location: San Francisco

Re: toggle headphones with lua script

Post by Gypsy Baron »

Jim,

The coding "Cx0D0066C7,x01" equates to :
Offset Byte - Toggle Bit 1 of Offset 0x66C7

In my Lua script, a change of the value in offset 0x66C7 ( a 'user defined' offset ) triggers
the headphones function.

Page 37 of the FSUIPC4 for Advanced Users.pdf.

The entire " line 38 (38=B66C0=2 PA,2,Cx0D0066C7,x01: statement shows that this is a 'conditional'
assignment in that when Controller A, button 2 is pressed, the action will only nbe performed if the
value in offset 0x66C0 is equal to '2'.

This is the method I use to create multiple 'modes' for my controllers, allowing multiple assignments for
each button/switch. I use another pair of buttons to INC/DEC that 'mode' value. Some of my A2A aircraft
have 7 or 8 'modes' so I can do a lot in the VC without having to resort to the mouse or keyboard.

Paul

User avatar
renaissanceman
Technical Sergeant
Posts: 597
Joined: 13 Apr 2008, 08:29
Location: Bedford, Texas

Re: toggle headphones with lua script

Post by renaissanceman »

Thanks Paul, I believe I understand. I'll dig in until it's clear in this old head.

Jim
i7-6700K @ 4.0 GHz | ASUS Maximus VIII Formula | 32 GB DDR4 | EVGA GeForce GTX 980TI Classified |
Win 10 Pro 64 | FSX SE | Registered FSUIPC | All Accu-Sim Birds | Accu-Feel v2 | TrackIR5 | AS16 | PRO-ATC/X

Gypsy Baron
A2A Master Mechanic
Posts: 3396
Joined: 02 Aug 2008, 17:04
Location: San Francisco

Re: toggle headphones with lua script

Post by Gypsy Baron »

JimI,

Here are three PDF files in the Modules\Documents folder that I find
are most helpful when creating Lua scripts and INI file entries\edits:

FSUIPC Lua Library.pdf
FSUIPC4 for Advanced Users.pdf
The 2016 List of FSX and P3D Controls.pdf

This PDF is also of interest as it calls out the formats of the
various offsts and their content.

FSUIPC4 Offsets Status.pdf

Paul

new reply

Return to “Piper Cherokee 180 Tech Support”

Who is online

Users browsing this forum: No registered users and 6 guests