Jump to content
The simFlight Network Forums

PMDG J41 led


Recommended Posts

Hello pete,

Now i have been working whit the J41 from pmdg. as i was preparing for the new 737ngx and wanted to get into codes by them. But i have a problem whit AP+YD engage / disengage. the rest of the lvars works. but think it is the way it was build as thos 2 buttons work close togeter.

Is it possible to get the ipcready file read default comands like AUTOPILOT_OFF as i use macro for the buttons and in the fsuipc4.log by pressing the macro key command it shows when on and off and looks ok in the plane.

becaus if it was posible to read it that way i could assigne the led. or can i use the codes from the list of controls for FSX and create some codes that way?

Link to comment
Share on other sites

Is it possible to get the ipcready file read default comands like AUTOPILOT_OFF

Sorry, I don't understand. What do you mean by "read" in relation to commands? Commands are sent TO FS, not read FROM it.

Maybe you simply mean detect when the autopilot goes off? For that simply monitor the appropriate offset. If your Lua plug-in is event driven, it is easy -- just have an event.offset for the AP master offset, 0x07BC, and see when that changes from non-zero to zero. If you are using a never-ending loop instead of events you'd need to simply read the offset using the ipc.readUD function and check it that way.

Pete

Link to comment
Share on other sites

yes i mean detect when the AP Master turns on OR off in this case.

from the log:

47440 *** EVENT: Cntrl= 65792 (0x00010100), Param= 0 (0x00000000) AUTOPILOT_ON

48953 *** EVENT: Cntrl= 65791 (0x000100ff), Param= 0 (0x00000000) AUTOPILOT_OFF

then like this:

AP-OFF = ipc.readUD(the hexinumber)

if AP-OFF == 0 then--------------------corect?

gfd.SetLight(GFMCPPRO,0,2)

-------------------------------------------------------------------------------------------------

update

ok this works:

AP = ipc.readUD(0x07BC)

if (AP == 1) then

gfd.SetLight(GFMCPPRO,0,2)

else

gfd.ClearLight(GFMCPPRO,0,2)

end

but how to get to that 0x07BC i try to read in the manual but dont get it. what number is it you calculate ?

found that for the YAW damper it was: 0x0808

good file you made whit the offset variables,just woundering why it wasent in the folder whit the othere dokuments. i mean the FSUIPCOffsets.pdf

but again thanks for your grate help

Link to comment
Share on other sites

another thig isent i posible inside the ipcready file to get 3 variables work for the same led and how ?

As i have tryeid some things but then the led just flashes. because i want it if posible to get the variabels to work for the same led as i can´t reflect whats happening in the plane. as it use 3 modes. so i would think combining all 3 would work best in this case for Vertical speed, so the led would light up when engaged, until it capture ALT and start anothere led which already work. just need those codes combined.

	ALTCAP = ipc.readLvar("L:CoamingAPALTSEL")
	if (ALTCAP == 1) then
		gfd.SetLight(GFMCPPRO,0,21)
	else
		gfd.ClearLight(GFMCPPRO,0,21)
	end
	VSHOLD = ipc.readLvar("L:CoamingAPVS")
	if (VSHOLD == 1) then
		gfd.SetLight(GFMCPPRO,0,21)
	else
		gfd.ClearLight(GFMCPPRO,0,21)
	end
	ALTSEL = ipc.readLvar("L:CoamingAPALTSELCAP")
	if (ALTSEL == 1) then
		gfd.SetLight(GFMCPPRO,0,21)
	else
		gfd.ClearLight(GFMCPPRO,0,21)
	end

Link to comment
Share on other sites

but how to get to that 0x07BC i try to read in the manual but dont get it. what number is it you calculate ?

found that for the YAW damper it was: 0x0808

good file you made whit the offset variables,just woundering why it wasent in the folder whit the othere dokuments. i mean the FSUIPCOffsets.pdf

The offsets lists are in documents provided in the FSUIPC SDK (="software Development Kit"). They aren't installed with FSUIPC because most FSUIPC user's are not programmers and cannot use them easily. The SDK contains all you need in addition to the stuff FSUIPC installs.

Regards

Pete

Link to comment
Share on other sites

ALTCAP = ipc.readLvar("L:CoamingAPALTSEL")
        if (ALTCAP == 1) then
                gfd.SetLight(GFMCPPRO,0,21)
        else
                gfd.ClearLight(GFMCPPRO,0,21)
        end
        VSHOLD = ipc.readLvar("L:CoamingAPVS")
        if (VSHOLD == 1) then
                gfd.SetLight(GFMCPPRO,0,21)
        else
                gfd.ClearLight(GFMCPPRO,0,21)
        end
        ALTSEL = ipc.readLvar("L:CoamingAPALTSELCAP")
        if (ALTSEL == 1) then
                gfd.SetLight(GFMCPPRO,0,21)
        else
                gfd.ClearLight(GFMCPPRO,0,21)
        end

would it then be like the displayswhit

prevXXXXX = -1

while 1 do

ALTSEL = ipc.readLvar("L:CoamingAPALTSELCAP")

if (ALTSEL == 1) then

gfd.SetLight(GFMCPPRO,0,21)

else

gfd.ClearLight(GFMCPPRO,0,21)

end

As i tryeid to run the codes that way but seems i need somthing that can identify. becaus if the codes just run as the were it is clear that they would flash as all 3 codes are set whit if thos is 1 then els then they all 3 wants to give input to the display as all 3 codes are giving info.

Link to comment
Share on other sites

As i tryeid to run the codes that way but seems i need somthing that can identify. becaus if the codes just run as the were it is clear that they would flash as all 3 codes are set whit if thos is 1 then els then they all 3 wants to give input to the display as all 3 codes are giving info.

Sorry, can you re-phrase that? Because I simply do not understand it.

BTW two points about your code example:

1. You should not be setting or clearing the lights on every loop, only when they need to change. You need to keep a memory of what the previous value was and only change the lights when the values change. I'm sure you've done all that before. That's what "prev ... = -1" and "if prev ... ~= ... then" is all about.

2. In a continuous loop plug-in, as you are using, you should ALWAYS include a sleep, to regulate the frequency of updates. Without that the loop is executing as rapidly as it can on your PC, maybe 500 times per second or more, wasting performance and maybe filling queues up on the USB drivers. Regulate it to some large fraction of a second, like half, by, e.g. "ipc.sleep(500)" before the "end" of the loop

Really it is better to use events. With offset reads you can use event.offset to call functions when an offset changes. With L:Var reads you cannot do that, but you can have an event.timer, to call your L:Var checking routine at intervals, like 250 or 500 mSecs, for instance.

Regards

Pete

Link to comment
Share on other sites

well yes i use sleep it was a short version of it all here is the hole file:

prevCRS1 = -1
prevspeed = -1
prevhdg = -1
prevalt = -1
prevVS = -1
prevCRS2 = -1
while 1 do
	CRS1 = ipc.readLvar("L:LeftCRS")
    	if (CRS1 ~= prevCRS1) then
        	stringCRS1 = string.format("%03d", CRS1)
        	gfd.setDisplay(GFMCPPRO,0,0,stringCRS1)
        	prevCRS1 = CRS1
    	end
    	speed = ipc.readLvar("L:IASBug")
    	if (speed ~= prevspeed) then
        	stringspeed = string.format("%03d", speed)
        	gfd.setDisplay(GFMCPPRO,0,1,stringspeed)
        	prevspeed = speed
	end
    	hdg = ipc.readLvar("L:HDGBug")
    	if (hdg ~= prevhdg) then
        	stringhdg = string.format("%03d", hdg)
        	gfd.setDisplay(GFMCPPRO,0,2,stringhdg)
        	prevhdg = hdg
    	end
	alt = ipc.readLvar("L:AltSelAlt")
    	if (alt ~= prevalt) then
        	stringalt = string.format("%05d", alt)
        	gfd.setDisplay(GFMCPPRO,0,3,stringalt)
        	prevalt = alt
    	end
	VS = ipc.readLvar("L:VSIASTarget")
    	if (VS ~= prevVS) then
        	stringalt = string.format("%05d", VS)
        	gfd.setDisplay(GFMCPPRO,0,4,stringalt)
        	prevVS = VS
    	end
	CRS2 = ipc.readLvar("L:RightCRS")
    	if (CRS2 ~= prevCRS2) then
        	stringCRS2 = string.format("%03d", CRS2)
        	gfd.setDisplay(GFMCPPRO,0,5,stringCRS2)
        	prevCRS2 = CRS2
	end
	ALTCAP = ipc.readLvar("L:CoamingAPALTSEL")
	if (ALTCAP == 1) then
		gfd.SetLight(GFMCPPRO,0,21)
	else
		gfd.ClearLight(GFMCPPRO,0,21)
	end
	APPRCAP = ipc.readLvar("L:CoamingAPAPRCAP")
	if (APPRCAP == 1) then
		gfd.SetLight(GFMCPPRO,0,0)
	else
		gfd.ClearLight(GFMCPPRO,0,0)
	end
	BCCAP = ipc.readLvar("L:CoamingAPBCCAP")
	if (BCCAP == 1) then
		gfd.SetLight(GFMCPPRO,0,0)
	else
		gfd.ClearLight(GFMCPPRO,0,0)
	end
	NAVCAP = ipc.readLvar("L:CoamingAPNAVCAP")
	if (NAVCAP == 1) then
		gfd.SetLight(GFMCPPRO,0,0)
	else
		gfd.ClearLight(GFMCPPRO,0,0)
	end
	NAVHOLD = ipc.readLvar("L:CoamingAPNAV")
	if (NAVHOLD == 1) then
		gfd.SetLight(GFMCPPRO,0,1)
	else
		gfd.ClearLight(GFMCPPRO,0,1)
	end
	AP = ipc.readUD(0x07BC)
	if (AP == 1) then
		gfd.SetLight(GFMCPPRO,0,2)
	else
		gfd.ClearLight(GFMCPPRO,0,2)
	end
	YD = ipc.readUD(0x0808)
	if (YD == 1) then
		gfd.SetLight(GFMCPPRO,0,3)
	else
		gfd.ClearLight(GFMCPPRO,0,3)
	end
	BC = ipc.readLvar("L:CoamingAPBC")
	if (BC == 1) then
		gfd.SetLight(GFMCPPRO,0,7)
	else
		gfd.ClearLight(GFMCPPRO,0,7)
	end
	BCCAP = ipc.readLvar("L:CoamingAPBCCAP")
	if (BCCAP == 1) then
		gfd.SetLight(GFMCPPRO,0,7)
	else
		gfd.ClearLight(GFMCPPRO,0,7)
	end
	BANK = ipc.readLvar("L:APBankLimitSwitchSelect")
	if (BANK >= 1) then
		gfd.SetLight(GFMCPPRO,0,9)
	else
		gfd.ClearLight(GFMCPPRO,0,9)
	end
	SOFT = ipc.readLvar("L:APSoftRideSwitchSelect")
	if (SOFT >= 1) then
		gfd.SetLight(GFMCPPRO,0,10)
	else
		gfd.ClearLight(GFMCPPRO,0,10)
	end
	SBYHOLD = ipc.readLvar("L:CoamingAPSBY")
	if (SBYHOLD == 1) then
		gfd.SetLight(GFMCPPRO,0,15)
	else
		gfd.ClearLight(GFMCPPRO,0,15)
	end
	IASHOLD = ipc.readLvar("L:CoamingAPIAS")
	if (IASHOLD == 1) then
		gfd.SetLight(GFMCPPRO,0,16)
	else
		gfd.ClearLight(GFMCPPRO,0,16)
	end
	ALTSEL = ipc.readLvar("L:CoamingAPALTSELCAP")
	if (ALTSEL == 1) then
		gfd.SetLight(GFMCPPRO,0,21)
	else
		gfd.ClearLight(GFMCPPRO,0,21)
	end
	HDGHOLD = ipc.readLvar("L:CoamingAPHDG")
	if (HDGHOLD == 1) then
		gfd.SetLight(GFMCPPRO,0,18)
	else
		gfd.ClearLight(GFMCPPRO,0,18)
	end
	APPRHOLD = ipc.readLvar("L:CoamingAPAPR")
	if (APPRHOLD == 1) then
		gfd.SetLight(GFMCPPRO,0,19)
	else
		gfd.ClearLight(GFMCPPRO,0,19)
	end
	ALTHOLD = ipc.readLvar("L:CoamingAPALT")
	if (ALTHOLD == 1) then
		gfd.SetLight(GFMCPPRO,0,20)
	else
		gfd.ClearLight(GFMCPPRO,0,20)
	end
	VSHOLD = ipc.readLvar("L:CoamingAPVS")
	if (VSHOLD == 1) then
		gfd.SetLight(GFMCPPRO,0,21)
	else
		gfd.ClearLight(GFMCPPRO,0,21)
		gfd.ClearLight(GFMCPPRO,0,23)
	end
    ipc.sleep(50)
end

About:

Really it is better to use events. With offset reads you can use event.offset to call functions when an offset changes. With L:Var reads you cannot do that, but you can have an event.timer, to call your L:Var checking routine at intervals, like 250 or 500 mSecs, for instance.

yes but no offset for it only the Lvars asi can se in the log.

And You should not be setting or clearing the lights on every loop, only when they need to change, yes but all 3 lvars have 1 and 0 to identify if active.

so in reality do you mean that when L:CoamingAPVS is pressed it would be 1 as active delt the line for 0 as that cler the led then L:CoamingAPALTSEL is not required and when it come to its final step L:CoamingAPALTSELCAP then it reads the 0 and 1 is removed to as no need to set the light. was it ?

to give a clear wiev of what happens when AP is running you press the VS speed button it would engage the alt sel button as i set it to the same button insted of an seperate button when it gets to around the selected altitude SELCAP takes over until the light is turned off and Alt led lights up to indicate that ALT is now active.

Link to comment
Share on other sites

well yes i use sleep it was a short version of it all here is the hole file:

But with the first few tests you only change lights when the values change. In the later ones you change them every time, 20 times per second. I reckon this could mess up the USB driving of the MCP.

yes but no offset for it only the Lvars asi can se in the log.

yes, I know. That's why, for LVars, I suggested using a Timer event. Did you not see?

And You should not be setting or clearing the lights on every loop, only when they need to change, yes but all 3 lvars have 1 and 0 to identify if active.

But because you are not checking whether the 0 and 1 has changed, on every loop, that is 20 times per second, you are sending either a SetLight or a ClearLight to each one! You ONLY need to set or clear a light when it needs to change, not 20 times per second!!

so in reality do you mean that when L:CoamingAPVS is pressed it would be 1 as active delt the line for 0 as that cler the led then L:CoamingAPALTSEL is not required and when it come to its final step L:CoamingAPALTSELCAP then it reads the 0 and 1 is removed to as no need to set the light. was it ?

Sorry, i don't understand this question. It makes no sense to me.

Regards

Pete

Link to comment
Share on other sites

is i becaus of the placing of the ipc.sleep(50) it would changes them 20 times you are refering to so it shold be: ipc.sleep(50) after the displays then end and start whit the led for them self ?

so it would look like this:

prevCRS1 = -1
prevspeed = -1
prevhdg = -1
prevalt = -1
prevVS = -1
prevCRS2 = -1
while 1 do
        CRS1 = ipc.readLvar("L:LeftCRS")
        if (CRS1 ~= prevCRS1) then
                stringCRS1 = string.format("%03d", CRS1)
                gfd.setDisplay(GFMCPPRO,0,0,stringCRS1)
                prevCRS1 = CRS1
        end
        speed = ipc.readLvar("L:IASBug")
        if (speed ~= prevspeed) then
                stringspeed = string.format("%03d", speed)
                gfd.setDisplay(GFMCPPRO,0,1,stringspeed)
                prevspeed = speed
        end
        hdg = ipc.readLvar("L:HDGBug")
        if (hdg ~= prevhdg) then
                stringhdg = string.format("%03d", hdg)
                gfd.setDisplay(GFMCPPRO,0,2,stringhdg)
                prevhdg = hdg
        end
        alt = ipc.readLvar("L:AltSelAlt")
        if (alt ~= prevalt) then
                stringalt = string.format("%05d", alt)
                gfd.setDisplay(GFMCPPRO,0,3,stringalt)
                prevalt = alt
        end
        VS = ipc.readLvar("L:VSIASTarget")
        if (VS ~= prevVS) then
                stringalt = string.format("%05d", VS)
                gfd.setDisplay(GFMCPPRO,0,4,stringalt)
                prevVS = VS
        end
        CRS2 = ipc.readLvar("L:RightCRS")
        if (CRS2 ~= prevCRS2) then
                stringCRS2 = string.format("%03d", CRS2)
                gfd.setDisplay(GFMCPPRO,0,5,stringCRS2)
                prevCRS2 = CRS2
        end
    ipc.sleep(50)
end
        ALTCAP = ipc.readLvar("L:CoamingAPALTSEL")
        if (ALTCAP == 1) then
                gfd.SetLight(GFMCPPRO,0,21)
        else
                gfd.ClearLight(GFMCPPRO,0,21)
        end
        APPRCAP = ipc.readLvar("L:CoamingAPAPRCAP")
        if (APPRCAP == 1) then
                gfd.SetLight(GFMCPPRO,0,0)
        else
                gfd.ClearLight(GFMCPPRO,0,0)
        end
        BCCAP = ipc.readLvar("L:CoamingAPBCCAP")
        if (BCCAP == 1) then
                gfd.SetLight(GFMCPPRO,0,0)
        else
                gfd.ClearLight(GFMCPPRO,0,0)
        end
        NAVCAP = ipc.readLvar("L:CoamingAPNAVCAP")
        if (NAVCAP == 1) then
                gfd.SetLight(GFMCPPRO,0,0)
        else
                gfd.ClearLight(GFMCPPRO,0,0)
        end
        NAVHOLD = ipc.readLvar("L:CoamingAPNAV")
        if (NAVHOLD == 1) then
                gfd.SetLight(GFMCPPRO,0,1)
        else
                gfd.ClearLight(GFMCPPRO,0,1)
        end
        AP = ipc.readUD(0x07BC)
        if (AP == 1) then
                gfd.SetLight(GFMCPPRO,0,2)
        else
                gfd.ClearLight(GFMCPPRO,0,2)
        end
        YD = ipc.readUD(0x0808)
        if (YD == 1) then
                gfd.SetLight(GFMCPPRO,0,3)
        else
                gfd.ClearLight(GFMCPPRO,0,3)
        end
        BC = ipc.readLvar("L:CoamingAPBC")
        if (BC == 1) then
                gfd.SetLight(GFMCPPRO,0,7)
        else
                gfd.ClearLight(GFMCPPRO,0,7)
        end
        BCCAP = ipc.readLvar("L:CoamingAPBCCAP")
        if (BCCAP == 1) then
                gfd.SetLight(GFMCPPRO,0,7)
        else
                gfd.ClearLight(GFMCPPRO,0,7)
        end
        BANK = ipc.readLvar("L:APBankLimitSwitchSelect")
        if (BANK >= 1) then
                gfd.SetLight(GFMCPPRO,0,9)
        else
                gfd.ClearLight(GFMCPPRO,0,9)
        end
        SOFT = ipc.readLvar("L:APSoftRideSwitchSelect")
        if (SOFT >= 1) then
                gfd.SetLight(GFMCPPRO,0,10)
        else
                gfd.ClearLight(GFMCPPRO,0,10)
        end
        SBYHOLD = ipc.readLvar("L:CoamingAPSBY")
        if (SBYHOLD == 1) then
                gfd.SetLight(GFMCPPRO,0,15)
        else
                gfd.ClearLight(GFMCPPRO,0,15)
        end
        IASHOLD = ipc.readLvar("L:CoamingAPIAS")
        if (IASHOLD == 1) then
                gfd.SetLight(GFMCPPRO,0,16)
        else
                gfd.ClearLight(GFMCPPRO,0,16)
        end
        ALTSEL = ipc.readLvar("L:CoamingAPALTSELCAP")
        if (ALTSEL == 1) then
                gfd.SetLight(GFMCPPRO,0,21)
        else
                gfd.ClearLight(GFMCPPRO,0,21)
        end
        HDGHOLD = ipc.readLvar("L:CoamingAPHDG")
        if (HDGHOLD == 1) then
                gfd.SetLight(GFMCPPRO,0,18)
        else
                gfd.ClearLight(GFMCPPRO,0,18)
        end
        APPRHOLD = ipc.readLvar("L:CoamingAPAPR")
        if (APPRHOLD == 1) then
                gfd.SetLight(GFMCPPRO,0,19)
        else
                gfd.ClearLight(GFMCPPRO,0,19)
        end
        ALTHOLD = ipc.readLvar("L:CoamingAPALT")
        if (ALTHOLD == 1) then
                gfd.SetLight(GFMCPPRO,0,20)
        else
                gfd.ClearLight(GFMCPPRO,0,20)
        end
        VSHOLD = ipc.readLvar("L:CoamingAPVS")
        if (VSHOLD == 1) then
                gfd.SetLight(GFMCPPRO,0,21)
        else
                gfd.ClearLight(GFMCPPRO,0,21)
                gfd.ClearLight(GFMCPPRO,0,23)
end

and how to use Timer event? and isent it good enoug when it looks for when active and inactive the way i do now ?

bu i think a event is req as when i did as above the led dit not turn on anymore

Link to comment
Share on other sites

is i becaus of the placing of the ipc.sleep(50) it would changes them 20 times you are refering to so it shold be: ipc.sleep(50) after the displays then end and start whit the led for them self ?

No no no!

I mean you need "prev ... = -1" at the beginning for ALL values, not just a few, and you should check if the values have changed before doing a setLight or ClearLight!!

I get the feeling you don't read what I write.

so it would look like this:

No, what good does that do?

Why only loop on a few not all of them?

Now NONE of those after the loop ever get executed because the loop never ends!

You don't make sense, sorry.

and how to use Timer event? and isent it good enoug when it looks for when active and inactive the way i do now ?

It is okay, just less efficient. Events on take processing time when things happen.

You don't need to use events, I was just saying it is much easier for Offsets because the routines only get called when the offset changes. With LVars you'd need to read them at intervals, either in a loop as you are doing, or more tidily using event.timer.

The main mess in your code is simply that you are sending lots of unnecessary SetLights and ClearLights 20 times a second! THAT is what is wrong! Why don't you just write the new parts like the previous ones? I don't understand why you insist on doing it differently!

Pete

Link to comment
Share on other sites

ok i re done it

prevCRS1 = -1
prevspeed = -1
prevhdg = -1
prevalt = -1
prevVS = -1
prevCRS2 = -1
prevALTCAP = 0
prevAPPRCAP = 0
prevBCCAP = 0
prevNAVCAP = 0
prevNAVHOLD = 0
prevAP = 0
prevYD = 0
prevBC = 0
prevBCCAP = 0
prevBANK = 0
prevSOFT = 0
prevSBYHOLD = 0
prevIASHOLD = 0
prevALTSEL = 0
prevHDGHOLD = 0
prevAPPRHOLD = 0
prevALTHOLD = 0
prevVSHOLD = 0
while 1 do
	CRS1 = ipc.readLvar("L:LeftCRS")
    	if (CRS1 ~= prevCRS1) then
        	stringCRS1 = string.format("%03d", CRS1)
        	gfd.setDisplay(GFMCPPRO,0,0,stringCRS1)
        	prevCRS1 = CRS1
    	end
    	speed = ipc.readLvar("L:IASBug")
    	if (speed ~= prevspeed) then
        	stringspeed = string.format("%03d", speed)
        	gfd.setDisplay(GFMCPPRO,0,1,stringspeed)
        	prevspeed = speed
	end
    	hdg = ipc.readLvar("L:HDGBug")
    	if (hdg ~= prevhdg) then
        	stringhdg = string.format("%03d", hdg)
        	gfd.setDisplay(GFMCPPRO,0,2,stringhdg)
        	prevhdg = hdg
    	end
	alt = ipc.readLvar("L:AltSelAlt")
    	if (alt ~= prevalt) then
        	stringalt = string.format("%05d", alt)
        	gfd.setDisplay(GFMCPPRO,0,3,stringalt)
        	prevalt = alt
    	end
	VS = ipc.readLvar("L:VSIASTarget")
    	if (VS ~= prevVS) then
        	stringalt = string.format("%05d", VS)
        	gfd.setDisplay(GFMCPPRO,0,4,stringalt)
        	prevVS = VS
    	end
	CRS2 = ipc.readLvar("L:RightCRS")
    	if (CRS2 ~= prevCRS2) then
        	stringCRS2 = string.format("%03d", CRS2)
        	gfd.setDisplay(GFMCPPRO,0,5,stringCRS2)
        	prevCRS2 = CRS2
	end
	ALTCAP = ipc.readLvar("L:CoamingAPALTSEL")
	if (ALTCAP ~= prevALTCAP) then
		gfd.SetLight(GFMCPPRO,0,17)
	else
		gfd.ClearLight(GFMCPPRO,0,17)
		prevALTCAP = ALTCAP
	end
	APPRCAP = ipc.readLvar("L:CoamingAPAPRCAP")
	if (APPRCAP ~= prevAPPRCAP) then
		gfd.SetLight(GFMCPPRO,0,0)
	else
		gfd.ClearLight(GFMCPPRO,0,0)
		prevAPPRCAP = APPRCAP
	end
	BCCAP = ipc.readLvar("L:CoamingAPBCCAP")
	if (BCCAP ~= prevBCCAP) then
		gfd.SetLight(GFMCPPRO,0,0)
	else
		gfd.ClearLight(GFMCPPRO,0,0)
		prevBCCAP = BCCAP
	end
	NAVCAP = ipc.readLvar("L:CoamingAPNAVCAP")
	if (NAVCAP ~= prevNAVCAP) then
		gfd.SetLight(GFMCPPRO,0,0)
	else
		gfd.ClearLight(GFMCPPRO,0,0)
		prevNAVCAP = NAVCAP
	end
	NAVHOLD = ipc.readLvar("L:CoamingAPNAV")
	if (NAVHOLD ~= prevNAVHOLD) then
		gfd.SetLight(GFMCPPRO,0,1)
	else
		gfd.ClearLight(GFMCPPRO,0,1)
		prevNAVHOLD = NAVHOLD
	end
	AP = ipc.readUD(0x07BC)
	if (AP ~= prevAP) then
		gfd.SetLight(GFMCPPRO,0,2)
	else
		gfd.ClearLight(GFMCPPRO,0,2)
		prevAP = AP
	end
	YD = ipc.readUD(0x0808)
	if (YD ~= prevYD) then
		gfd.SetLight(GFMCPPRO,0,3)
	else
		gfd.ClearLight(GFMCPPRO,0,3)
		prevYD = YD
	end
	BC = ipc.readLvar("L:CoamingAPBC")
	if (BC ~= prevBC) then
		gfd.SetLight(GFMCPPRO,0,7)
	else
		gfd.ClearLight(GFMCPPRO,0,7)
		prevBC = BC
	end
	BCCAP = ipc.readLvar("L:CoamingAPBCCAP")
	if (BCCAP ~= prevBCCAP) then
		gfd.SetLight(GFMCPPRO,0,7)
	else
		gfd.ClearLight(GFMCPPRO,0,7)
		prevBCCAP = BCCAP
	end
	BANK = ipc.readLvar("L:APBankLimitSwitchSelect")
	if (BANK ~= prevBANK) then
		gfd.SetLight(GFMCPPRO,0,9)
	else
		gfd.ClearLight(GFMCPPRO,0,9)
		prevBANK = BANK
	end
	SOFT = ipc.readLvar("L:APSoftRideSwitchSelect")
	if (SOFT ~= prevSOFT) then
		gfd.SetLight(GFMCPPRO,0,10)
	else
		gfd.ClearLight(GFMCPPRO,0,10)
		prevSOFT = SOFT
	end
	SBYHOLD = ipc.readLvar("L:CoamingAPSBY")
	if (SBYHOLD ~= prevSBYHOLD) then
		gfd.SetLight(GFMCPPRO,0,15)
	else
		gfd.ClearLight(GFMCPPRO,0,15)
		prevSBYHOLD = SBYHOLD
	end
	IASHOLD = ipc.readLvar("L:CoamingAPIAS")
	if (IASHOLD ~= prevIASHOLD) then
		gfd.SetLight(GFMCPPRO,0,16)
	else
		gfd.ClearLight(GFMCPPRO,0,16)
		prevIASHOLD = IASHOLD
	end
	ALTSEL = ipc.readLvar("L:CoamingAPALTSELCAP")
	if (ALTSEL ~= prevALTSEL) then
		gfd.SetLight(GFMCPPRO,0,17)
	else
		gfd.ClearLight(GFMCPPRO,0,17)
		prevALTSEL = ALTSEL
	end
	HDGHOLD = ipc.readLvar("L:CoamingAPHDG")
	if (HDGHOLD ~= prevHDGHOLD) then
		gfd.SetLight(GFMCPPRO,0,18)
	else
		gfd.ClearLight(GFMCPPRO,0,18)
		prevHDGHOLD = HDGHOLD
	end
	APPRHOLD = ipc.readLvar("L:CoamingAPAPR")
	if (APPRHOLD ~= prevAPPRHOLD) then
		gfd.SetLight(GFMCPPRO,0,19)
	else
		gfd.ClearLight(GFMCPPRO,0,19)
		prevAPPRHOLD = APPRHOLD
	end
	ALTHOLD = ipc.readLvar("L:CoamingAPALT")
	if (ALTHOLD ~= prevALTHOLD) then
		gfd.SetLight(GFMCPPRO,0,20)
	else
		gfd.ClearLight(GFMCPPRO,0,20)
		prevALTHOLD = ALTHOLD
	end
	VSHOLD = ipc.readLvar("L:CoamingAPVS")
	if (VSHOLD ~= prevVSHOLD) then
		gfd.SetLight(GFMCPPRO,0,21)
	else
		gfd.ClearLight(GFMCPPRO,0,21)
		gfd.ClearLight(GFMCPPRO,0,23)
		prevVSHOLD = VSHOLD
	end
    ipc.sleep(50)
end

and had to face that i had to give ALTSEL and ALTCAP the same led insted of all 3 codes to 1 led as told earlyer (VS button) as those are required for othere things in the autopilot, so i had to include a seperate led for those 2.

but still have the problem as it would flash. if i changes as you say to remove not nessecary setled and clear led it would work but if you then press the button again it would turn off corectly. as thos 2 codes works close togeter it only works whit the flashing effect so think i have to let it be so when that is engaged that button. as i dont know how to get it identify which is onn as it is led for the same button. but in the plane it is abel to show the text CAP and ARM. so thats why i need it to led id cap is engaged or ARM is engaged.

Link to comment
Share on other sites

and had to face that i had to give ALTSEL and ALTCAP the same led insted of all 3 codes to 1 led as those are required for othere things in the autopilot

but still have the problem as it would flash. if i changes as you say to remove not nessecary setled and clear led it would work but if you then press the button again it would turn off corectly. as thos 2 codes works close togeter it only works whit the flashing effect so think i have to let it be so when that is engaged that button. as i dont know how to get it identify which is onn as it is led for the same button. but in the plane it is abel to show the text CAP and ARM. so thats why i need it to led id cap is engaged or ARM is engaged.

Sorry, I don't understand much of that if any of it.

Can you spell it out in separate lines and keep it simple. I don't understand the way you phrase things.

If you want flashing LEDs, as when things are being captured but are not yet captured, you will need to keep account of the time (you can get the time in mSecs using an ipc library function) , and alternate the light setting every, say 500 mSecs. (This is where using a time event would be much tidier).

BTW I'm out now till tomorrow, or maybe very late this evening.

Pete

Link to comment
Share on other sites

well whit the code the led flashes it was what i mean, and i know why it does it because the code say so.

I just cant se how to get the ARM and CAP mode to work together for the same led.

Inside the plane on the autopilot, you select a button can´t remember its name right now but when it is pressed it engage ARM (Armed mode) then you press IAS or VS mode as then you set the speed or vertical speed. then the plane would catch the selected IAS or VS until it gets near the altitude you have set. As when the plane gets near the selected altitude it switch from ARM to CAP (capture mode) on the autopilot.

It is here i have a problem to just let the led light at both stages, because in the plane the ap button just light whit text ARM then CAP for the same button. there are more buttons that does the same but to keep it simple 1 step at a time.

becaus if i just say sel would turn on the led and when cap is over it turns off the led. but then there is the problem what if you want to turn the mode off again then it dosent reach the Cap which turns-off the led.

do you se the problem as then i need some thing when it is 1 it turns on led if 0 it turns off but that 0 would block when capture is in use right?

it is here i keep thinking how to do so they work for the same led but dont block the othere which would result in the flashing effect.

Link to comment
Share on other sites

the best result i got so fra was by combining the files like this snipit of the codes

	ALTSEL = ipc.readLvar("L:CoamingAPALTSEL")
	ALTCAP = ipc.readLvar("L:CoamingAPALTSELCAP")
	if (ALTSEL ~= prevALTSEL) then
		gfd.SetLight(GFMCPPRO,0,17)
		end
	if (ALTSEL == prevALTSEL) then	
		gfd.ClearLight(GFMCPPRO,0,17)
		end
	if (ALTCAP == prevALTCAP) then
	gfd.SetLight(GFMCPPRO,0,17)
		prevALTSEL = ALTSEL
		prevALTCAP = ALTCAP
	end

you can see the led when in capture mode the led flash a little but not that much only visble that the light intensity goes litel up and down. so still cant find out how to do it as changes the prevXXX= 0 or 1 and edit the codes dident help. if they just have used the same lvar whit different numbers like 0 for oFF 1 for arm and mabe 2 for Cap. as 2 codes there need to be abel to turn off the same dosent seem that easy.

Becaus how to... i cant see it as if i skip the cler for the 1 lvar and the set from the othere it works but if you dis engage before it gets to Capture mode nothing would happen to tthe led as no programing. so is there a way to chek the othere Lvar so it mabee could identify that way.

Link to comment
Share on other sites

well whit the code the led flashes it was what i mean, and i know why it does it because the code say so.

Does it?

I just cant se how to get the ARM and CAP mode to work together for the same led.

Why? Sorry, I don't understand the problem, evidently.

Inside the plane on the autopilot, you select a button can´t remember its name right now but when it is pressed it engage ARM (Armed mode) then you press IAS or VS mode as then you set the speed or vertical speed. then the plane would catch the selected IAS or VS until it gets near the altitude you have set. As when the plane gets near the selected altitude it switch from ARM to CAP (capture mode) on the autopilot.

Yes. And these are indicated by words like that on the screens. What are you wanting the lights to do?

It is here i have a problem to just let the led light at both stages, because in the plane the ap button just light whit text ARM then CAP for the same button.

And ...? Do you want ARM to flash the light and CAP to make it set on? What is it doing instead?

becaus if i just say sel would turn on the led and when cap is over it turns off the led. but then there is the problem what if you want to turn the mode off again then it dosent reach the Cap which turns-off the led.

Sorry, I don't understand that.

If I'm right in assuming you want it to flash on ARM and be steady on CAP, but off when both are off, all you want is this logic (this isn't real code, just logic):

-- outside loop
flashtime = 0
flashlit = 0


-- inside loop
if ARM changed or CAP changed then
   	if ARM or CAP then
            	if CAP then
   	             	setlight
 	      	else
   	                 if  (timenow - flashtime) > 500 then
          	             	if flashlit ~= 0 then
         	                    	clearlight
	          	         	else
                  	              setlight
                	          end
                         	flashlit = 1 - flashlit
                        	flashtime = timenow
                 	end
         	end
      else
          	clearlight
  	end
end

Regards

Pete

]

Link to comment
Share on other sites

well i mean when ARM and CAP is on it should just light up steady, no flash at all.

but whit the codes i showed you the led would flash. as it seems like when ARM light up in the plane it say 1 for on but when that goes off it turns to 0 whitch turns off that led again. and thats where the problem is becaus if i then does the same for the CAP 1 for turn on and 0 for off. ARM and CAP fight against each other as ARM want it to turn off when CAP is in use and Cap want to turn on the led. and the othere way. as i said, i might be able to turn on the led by seting the led when engage the ARM and turn it of whit a 0 clear light when CAP turns off but then it would reconise if the button ARM was turned off again.

hope that explanes and sorry for my confusing pete.

Link to comment
Share on other sites

well i mean when ARM and CAP is on it should just light up steady, no flash at all.

Not flashing when ARM but not CAP., like a Bendix-King A/P?

but whit the codes i showed you the led would flash. as it seems like when ARM light up in the plane it say 1 for on but when that goes off it turns to 0 whitch turns off that led again. and thats where the problem is becaus if i then does the same for the CAP 1 for turn on and 0 for off. ARM and CAP fight against each other as ARM want it to turn off when CAP is in use and Cap want to turn on the led. and the othere way. as i said, i might be able to turn on the led by seting the led when engage the ARM and turn it of whit a 0 clear light when CAP turns off but then it would reconise if the button ARM was turned off again.

hope that explanes and sorry for my confusing pete.

No, sorry, I am now even more confused.

If you simply want it ON all the time when ARM or CAP is on, and OFF all the time when neither are on, it is MUCH simpler than the logic I showed you. Just treat ARM and CAP together. i.e.

-- inside loop
if ARM changed or CAP changed then
      if ARM or CAP then
            setlight              
      else
            clearlight
      end
end

How many other combinations of two conditions and one light are there? I think you are exhausting them!

Pete

Link to comment
Share on other sites

like this?

	ALTSEL = ipc.readLvar("L:CoamingAPALTSEL")
	ALTCAP = ipc.readLvar("L:CoamingAPALTSELCAP")
	if ALTSEL changed or ALTCAP changed then
        	if ALTSEL or ALTCAP then
		gfd.SetLight(GFMCPPRO,0,17)
	else
		gfd.ClearLight(GFMCPPRO,0,17)
		end
	end

but what about?

if (ALTCAP ~= prevALTCAP) then

if (ALTSEL ~= prevALTSEL) then

Link to comment
Share on other sites

like this?

	ALTSEL = ipc.readLvar("L:CoamingAPALTSEL")
	ALTCAP = ipc.readLvar("L:CoamingAPALTSELCAP")
	if ALTSEL changed or ALTCAP changed then
      		if ALTSEL or ALTCAP then
            		setlight              
 	         else
            		clearlight
               end
	end

Well, yes, but you have to fill in the code, not just write the logic out as I did for you!! That's not Lua!

but what about?

if (ALTCAP ~= prevALTCAP) then

if (ALTSEL ~= prevALTSEL) then

Oh dear. That's how to test "changed" in Lua. I thought you were understanding at least a little bit of all this? I really cannot keep writing all this code for you. I have other things to do. What did you think "changed" meant?

:-(

Pete

Link to comment
Share on other sites

yes i know That's how to test if "changed" in the Lua. but just get confused as if i just use if xxx then after each othere as far as i remember it would work.

	ALTSEL = ipc.readLvar("L:CoamingAPALTSEL")
	ALTCAP = ipc.readLvar("L:CoamingAPALTSELCAP")
	if (ALTCAP ~= prevALTCAP) then
	if (ALTSEL ~= prevALTSEL) then 
	if ALTSEL changed or ALTCAP changed then
        	if ALTSEL or ALTCAP then
		gfd.SetLight(GFMCPPRO,0,17)
	else
		gfd.ClearLight(GFMCPPRO,0,17)
		prevALTSEL = ALTSEL
                prevALTCAP = ALTCAP
	end

as this would also not work. i realy try much more then i tell here, but it isent easy, whell when it works you say ofcause but when you have all the codes to puzzel whit it aint easy.

Link to comment
Share on other sites

	ALTSEL = ipc.readLvar("L:CoamingAPALTSEL")
	ALTCAP = ipc.readLvar("L:CoamingAPALTSELCAP")
	if (ALTCAP ~= prevALTCAP) then
	if (ALTSEL ~= prevALTSEL) then 
	if ALTSEL changed or ALTCAP changed then
        	if ALTSEL or ALTCAP then
		gfd.SetLight(GFMCPPRO,0,17)
	else
		gfd.ClearLight(GFMCPPRO,0,17)
		prevALTSEL = ALTSEL
                prevALTCAP = ALTCAP
	end

as this would also not work.

Of course not. Not

	if (ALTCAP ~= prevALTCAP) then
	if (ALTSEL ~= prevALTSEL) then 

but

	if (ALTCAP ~= prevALTCAP) or (ALTSEL ~= prevALTSEL) then 

that's what I meant by " if ALTSEL changed or ALTCAP changed then". ALL YOU HAD TO DO WAS FILL IN THE "CHANGED" TEST!!!#

And not only have you put the extra lines in but you forgot they were replacing the line

	if ALTSEL changed or ALTCAP changed then

which of course they replace! That line was merely to show you what to do! It isn't Lua! I told you that already! You must now delete it!

Also you need another "end" before "prevALTSEL = ALTSEL".

I'm very sorry, but I have to discontinue writing code for you. I hoped you'd be learning, but the more I explain the less you seem to know. I realise i am not a good teacher and so I will not try any more. It seems I make things worse not better. May be someone else can help in future.

Regards

Pete

Link to comment
Share on other sites

well about: I hoped you'd be learning, but the more I explain the less you seem to know. well no thats not the case i just dident get it what you ment. as for the looping in those cases here it is basicly the same things, the same construction, it is more that i missed some pices as i dident know that you just simply could do: if (ALTCAP ~= prevALTCAP) or (ALTSEL ~= prevALTSEL) then as thats in some way what i was missing was a way to use OR in this case to say if this or this is the case it shuld light up. as basicly we used this all the time:

prevALTCAP = 0

while 1 do

ALTCAP = ipc.readLvar("L:CoamingAPALTSELCAP") --- here it reads the variable (lvar) and give it some kind of short name = ALTCAP

if (ALTCAP ~= prevALTCAP) then -------------------------------------------------- here we test it. as if ALTCAP is different from prevALTCAP which could be 0 and if ALTCAP is 1 then led would turn on as it would then

gfd.SetLight(GFMCPPRO,0,0) be different from 0 as it is now 1.

else-------------------------------------else is used when both are 0 so there is no difference i think.

gfd.ClearLight(GFMCPPRO,0,0)

prevALTCAP = ALTCAP

end

so yes you have learned me the basic of the structure of the codes, i just think it is my confusing there is the problem for your understanding of what i am looking for or need.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.