How to load a blinking image
How to load a blinking image
Some Annunciations involve blinking signals. I have been trying to use the timer_start to implement such function but in vane. Perhaps the gurus here can shed me a light please?
-
- Posts: 5339
- Joined: Thu Jul 27, 2017 12:22 am
Re: How to load a blinking image
Welcome to the forums @freedom
Without any complication, blinking is mostly accomplished in AM following the subscribed variable state : let say we hide the lighted annunciator when the state is 0 and we show it when the state is 1, as AM is event based, this works in real time
depending on your specific situation : could you post which variable is subscribed and from which addon ?
Gilles
Without any complication, blinking is mostly accomplished in AM following the subscribed variable state : let say we hide the lighted annunciator when the state is 0 and we show it when the state is 1, as AM is event based, this works in real time
depending on your specific situation : could you post which variable is subscribed and from which addon ?
Gilles
Re: How to load a blinking image
Code: Select all
timer_start(nil, 500, function(count)
visible(image_x, count%2 == 0)
end)
Don't put a timer within a simulator callback, unless you check if it's already running.
-
- Posts: 5339
- Joined: Thu Jul 27, 2017 12:22 am
Re: How to load a blinking image
Perhaps is there not any blinking variable to subscribe to, in this case Ralph is right
in the case of existing blinking status, like in the ZiboMod MCP digits, I would rather use the variable state, to make it simpler by not having to build such feature
Gilles
in the case of existing blinking status, like in the ZiboMod MCP digits, I would rather use the variable state, to make it simpler by not having to build such feature
Gilles
Re: How to load a blinking image
Problem with annunciators in a complex airplane is that they can have multiple states and among those, one is related to the Test button (the light should light up when the test button is pressed and come back to its current state when the test button is released), and also that they have to trigger the master warning/caution lights accordingly.
Not simple, the best method I found was to use binary operations to keep the track and status of all the annunciators, and reset one when needed without affecting the others, so the master caution/warning fires no matter what whenever the status byte of all annunciators is not zero
As per the blinking system, provided the blinking status is not already available as Gilles said, the trick I use is to fire a perpetual blinking timer function that merely sets a blink Boolean variable to true or false for every iteration. Then depending of the state of the trigger AND power AND blink variables, I turn the annunciator_on image visible or not.
The good thing with Booleans is that you can use something like blink=not(blink) to turn the blink variable to true/false alternatively whatever it’s previous state.
You will have of course to subscribe to the proper values to check for the trigger and power state, and set the variables accordingly.
The only drawback I found is that depending on the current state of the blink variable, it can start flashing only 500msec after the trigger condition is on.
You can add a visible() function for each annunciator light, they will all blink at the same moment.
There might be clever methods (this one can be fairly test intensive) but this one works well.
Jacques
Not simple, the best method I found was to use binary operations to keep the track and status of all the annunciators, and reset one when needed without affecting the others, so the master caution/warning fires no matter what whenever the status byte of all annunciators is not zero
As per the blinking system, provided the blinking status is not already available as Gilles said, the trick I use is to fire a perpetual blinking timer function that merely sets a blink Boolean variable to true or false for every iteration. Then depending of the state of the trigger AND power AND blink variables, I turn the annunciator_on image visible or not.
The good thing with Booleans is that you can use something like blink=not(blink) to turn the blink variable to true/false alternatively whatever it’s previous state.
Code: Select all
local blink=false — blinking state
local test=false — is the test button pressed?
local battery_on=true — is the plane powered?
local annunciator_on=true — annunciator trigger condition
function blink_callback()
blink=not(blink)
visible(img_annunciator_on, battery_on and ((blink and annunciator_on) or test))
end
....
timer_start(0,500,blink_callback)
The only drawback I found is that depending on the current state of the blink variable, it can start flashing only 500msec after the trigger condition is on.
You can add a visible() function for each annunciator light, they will all blink at the same moment.
There might be clever methods (this one can be fairly test intensive) but this one works well.
Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ
Re: How to load a blinking image
I am trying to adopt the Toliss A319 Master Warning/Caution light which flashes at 1 sec interval until pressed.
Unfortunately the lights dataref to not reflect the flashing status (its an on/off status). So direct subscription of the dataref is not going to work.
Will try Ralph’s way this week. May I know what does “count%2 == 0” mean in the code?
Unfortunately the lights dataref to not reflect the flashing status (its an on/off status). So direct subscription of the dataref is not going to work.
Will try Ralph’s way this week. May I know what does “count%2 == 0” mean in the code?
Re: How to load a blinking image
Thanks Jacques, indeed this is the button I am trying to work with. I saw your excellent work with the FF A320, are you interested for some collaboration together? I am dealing with the Toliss A319
JackZ wrote: ↑Wed Jul 29, 2020 10:13 pm Problem with annunciators in a complex airplane is that they can have multiple states and among those, one is related to the Test button (the light should light up when the test button is pressed and come back to its current state when the test button is released), and also that they have to trigger the master warning/caution lights accordingly.
Not simple, the best method I found was to use binary operations to keep the track and status of all the annunciators, and reset one when needed without affecting the others, so the master caution/warning fires no matter what whenever the status byte of all annunciators is not zero
As per the blinking system, provided the blinking status is not already available as Gilles said, the trick I use is to fire a perpetual blinking timer function that merely sets a blink Boolean variable to true or false for every iteration. Then depending of the state of the trigger AND power AND blink variables, I turn the annunciator_on image visible or not.
The good thing with Booleans is that you can use something like blink=not(blink) to turn the blink variable to true/false alternatively whatever it’s previous state.You will have of course to subscribe to the proper values to check for the trigger and power state, and set the variables accordingly.Code: Select all
local blink=false — blinking state local test=false — is the test button pressed? local battery_on=true — is the plane powered? local annunciator_on=true — annunciator trigger condition function blink_callback() blink=not(blink) visible(img_annunciator_on, battery_on and ((blink and annunciator_on) or test)) end .... timer_start(0,500,blink_callback)
The only drawback I found is that depending on the current state of the blink variable, it can start flashing only 500msec after the trigger condition is on.
You can add a visible() function for each annunciator light, they will all blink at the same moment.
There might be clever methods (this one can be fairly test intensive) but this one works well.
Jacques
Re: How to load a blinking image
Unfortunately, all my hard work on the FFA320 has been lost due to a W10 update that went terribly wrong and shame on me I hadn’t made a backup of the instruments in the works, be it the FCU, the Transponder or the OVH panel.
All the graphic assets are still here but the instruments and code were lost when the version of AM got reinstalled.
Kinda discouraged about it, and has given up for the moment on it.
When time will come I will (perhaps) resume work on it but for now I have other projects on the shelf.
You first have to find if there is a Dataref in the Toliss that triggers the Master Warning and/or Caution, then you can use the method I described earlier.
FYI: the trick Ralph used is to make the image_on visible every two callbacks, by checking if the variable “count“ (automatically incremented by one every callback) is even or odd.
To do that, he uses the Lua % operator.
count%2==0
% is the modulo division Lua function.
The variable count is divided by two and the % operator returns the rest of the division by two.
If the rest is zero, that means that the number is even (even numbers can be divided by two), and then the visible function is true.
Jacques
All the graphic assets are still here but the instruments and code were lost when the version of AM got reinstalled.
Kinda discouraged about it, and has given up for the moment on it.
When time will come I will (perhaps) resume work on it but for now I have other projects on the shelf.
You first have to find if there is a Dataref in the Toliss that triggers the Master Warning and/or Caution, then you can use the method I described earlier.
FYI: the trick Ralph used is to make the image_on visible every two callbacks, by checking if the variable “count“ (automatically incremented by one every callback) is even or odd.
To do that, he uses the Lua % operator.
count%2==0
% is the modulo division Lua function.
The variable count is divided by two and the % operator returns the rest of the division by two.
If the rest is zero, that means that the number is even (even numbers can be divided by two), and then the visible function is true.
Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ
Re: How to load a blinking image
Hi Jacques and Ralph
What a big shame on the loss of the files! Your artwork is among the best I have ever seen from the community. A lot of efforts has been put into the details. I feel the pain for losing them!
I have an idea, my work on Toliss is now half done (FCU 50%, EFIS, Warning/Caution, ECP, Gear) but I lack quality graphics. Would you mind sharing the artworks for me to use? I will offer them to the community for free when completed and certainly give you a credit.
And thanks Ralph for offering the code. It works like a magic! It’s a very neat trick indeed.
What a big shame on the loss of the files! Your artwork is among the best I have ever seen from the community. A lot of efforts has been put into the details. I feel the pain for losing them!
I have an idea, my work on Toliss is now half done (FCU 50%, EFIS, Warning/Caution, ECP, Gear) but I lack quality graphics. Would you mind sharing the artworks for me to use? I will offer them to the community for free when completed and certainly give you a credit.
And thanks Ralph for offering the code. It works like a magic! It’s a very neat trick indeed.