Blinking text
Blinking text
Hi
What would be the best way to make text on a canvas blinking?
There is no text style option for this , is a wait option in lua the way to go?
What would be the best way to make text on a canvas blinking?
There is no text style option for this , is a wait option in lua the way to go?
- Keith Baxter
- Posts: 4674
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Blinking text
Hi,
Use a timer.
Then change the color,make the text visible or not or simply change the opacity when pulse value is 1 or 0.
Keith
Use a timer.
Code: Select all
pulse=0
timer_start(0, 500, function()
pulse=pulse+1
if pulse>=2 then pulse=0 end
end)
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
Re: Blinking text
A little easier:
Code: Select all
timer_start(nil, 500, function(count)
visible(my_text, count%2 == 0)
end)
- Keith Baxter
- Posts: 4674
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Blinking text
Hi,
Yes that too.
But for text in a canvas_draw() use the pulse var as opacity. The var <pulse> will have a opacity of 1 or 0
Keith
Yes that too.
But for text in a canvas_draw() use the pulse var as opacity. The var <pulse> will have a opacity of 1 or 0
Code: Select all
canvas_draw(my_canvas, function()
_txt("The blinking Eye", text_style,30,30,pulse)
end)
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
Re: Blinking text
For canvas you have to redraw the txt each time so either you use a timer to control the canvas redraw or you make sure the canvas is continually getting redrawn and use OS time to provide the flash feature. It might even be better to not use the canvas for this text and use the normal txt_add() id with visibility. It really depends on the application.
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Re: Blinking text
hmm no luck yet ...
I've tried
but text is shown without blinking
I've tried
Code: Select all
canvas_draw(cas_alerts, function()
if CAS_Red_list ~= {} then
for i = 1, #CAS_Red_list do
_txt(CAS_Red_list[i], CAS_mess_red,5,0 + (i*20), text_style,30,30,pulse)
end
end
end)
- Keith Baxter
- Posts: 4674
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Blinking text
Hi,Shimokuta wrote: ↑Sun Apr 17, 2022 6:52 am hmm no luck yet ...
I've tried
but text is shown without blinkingCode: Select all
canvas_draw(cas_alerts, function() if CAS_Red_list ~= {} then for i = 1, #CAS_Red_list do _txt(CAS_Red_list[i], CAS_mess_red,5,0 + (i*20), text_style,30,30,pulse) end end end)
Try this.
Code: Select all
arb_28vlmagC="font:roboto_regular.ttf; size:28px; color: red; halign:rleft; valign:center;"
cas_alerts_canvas= canvas_add(0,0,600,600)
---Add a timer for blinking
pulse=0
timer_start(0, 500, function()
pulse=pulse+1
if pulse>=2 then pulse=0 end
cas_alerts()
end)
function cas_alerts()
canvas_draw(cas_alerts_canvas, function()
_txt("The Blinking Eye", arb_28vlmagC,30,30,pulse)
end)
end
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
Re: Blinking text
Great Keith!!
This code seems to work.
Now i have to figure out how to embed it in my code with cas messages inserted from a table :S
but this helped me a lot
This code seems to work.
Now i have to figure out how to embed it in my code with cas messages inserted from a table :S
but this helped me a lot
- Keith Baxter
- Posts: 4674
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Blinking text
Hi,
I create tables like this for the different color.
Code: Select all
---Bell407 alerts
bell_casW_alerts={"BATTERY HOT","ENGINE FIRE","ENGINE OIL HOT","ENGIN OIL PSI LOW","ENGINE OUT","ENGINE OVERSPEED","FADEC FAIL","XMSN OIL PRESS","XMSN OIL TEMP"}
bell_casC_alerts={"AP DEGRADED","AP FAILED","AUTOTRIM","BAGGAGE DOOR","BATTERY RLY","ENGINE CHIP","ENG FUEL FILTER","ENG OIL FILTER","ENG OIL PSI HI","ENGINE MGT","FADEC BEC","FADEC DEGRADED","FLOAT ARM","FUEL LOW","FUEL VALVE","GEN FAIL","HEATER OVERTEMP","HYDRAULIC SYS","L/FUEL BOOST","L/FUEL XFR","LITTER DOOR","MGT EXCEED","NG EXCEED","NR MISCOMP","NR EXCEED","PEDAL STOP","Q EXCEED","Q MISCOMP","R/FUEL BOOST","R/FUEL XFR","SLIDING DOOR","T/R CHIP","XMSN CHIP"}
bell_casA_alerts={"ALTN DATA FAIL","AUTO RELIGHT","ENG ANTI-ICE","ENG FUEL FILT","ENG MISCOMP","FADEC CHAN FAIL","FADEC MAINT","INST FAN","NG OAT LIMIT","QUITE MODE SEL","RESTART FAULT","START"}
bell_casS_alerts={"FLOAT TEST","IGW VNE","QUITE MODE ON","WOG"}
This code just lists what CAS items have been triggered.
You can include the blink function and a acknowledge function into the matrix.
Manipulating tables is the best I have found.
Code: Select all
-----------------------------------------------------------------------------------------------------
---CAS Alerts
-----------------------------------------------------------------------------------------------------
function xpl_dataref_subscribe_trottle(...)
-- Local variables
local args = {...}
local user_callback = args[#args - 1]
local delta_ms = table.remove(args, #args)
local data = nil
-- Replace the user callback with our own
args[#args] = function (...)
data = {...}
end
-- Do the actual subscribe
xpl_dataref_subscribe(table.unpack(args))
-- Start a timer that will fire the callback on requested interval
timer_start(0, delta_ms, function()
if data ~= nil then
user_callback(table.unpack(data))
data = nil
end
end)
end
function callback_w_cas(batH,fire,EoilT,EoilP,Eout,rpm,fadec,xmsnp,xmsnt,ap,ap_trim,baggage,Echip,oilpH,mgt_ex,float_arm,fuelQ,hydr,xfrL,xfrR,gen,ignit,antiice,wog,Q,nr1,np1,ng1,mgt1,Pstop,igw)
local casW_list ={}
if batH ==1 then table.insert(casW_list,bell_casW_alerts[1])end --BATTERY HOT
if fire[1] ==1 then table.insert(casW_list,bell_casW_alerts[2])end --ENGINE FIRE
if EoilT[1] ==1 then table.insert(casW_list,bell_casW_alerts[3])end --ENGINE OIL HOT
if EoilP[1] ==1 then table.insert(casW_list,bell_casW_alerts[4])end --ENGIN OIL PSI LOW
if Eout ==1 then table.insert(casW_list,bell_casW_alerts[5])end --ENGINE OUT
if rpm >=102.1 then table.insert(casW_list,bell_casW_alerts[6])end --ENGINE OVERSPEED
if fadec == 1 then table.insert(casW_list,bell_casW_alerts[7])end --FADEC FAIL
if xmsnp <=3 then table.insert(casW_list,bell_casW_alerts[8])end --XMSN OIL PRESS
if xmsnt >= 11 then table.insert(casW_list,bell_casW_alerts[9])end --XMSN OIL TEMP
local casC_list ={}
-- if then table.insert(casC_list,bell_casC_alerts[1])end --AP DEGRADED
if ap ~= 0 then table.insert(casC_list,bell_casC_alerts[2])end --AP FAILED
if ap_trim ~= 0 then table.insert(casC_list,bell_casC_alerts[3])end --AUTOTRIM
if baggage >= 0.1 then table.insert(casC_list,bell_casC_alerts[4])end --BAGGAGE DOOR
-- if then table.insert(casC_list,bell_casC_alerts[5])end --BATTERY RLY
if Echip[1] ~= 0 then table.insert(casC_list,bell_casC_alerts[6])end --ENGINE CHIP
-- if then table.insert(casC_list,bell_casC_alerts[7])end --ENG FUEL FILTER
-- if then table.insert(casC_list,bell_casC_alerts[8])end --ENG OIL FILTER
if oilpH[1] >= 140 then table.insert(casC_list,bell_casC_alerts[9])end --ENG OIL PSI HI
if mgt_ex == 1 then table.insert(casC_list,bell_casC_alerts[10])end --ENGINE MGT
-- if then table.insert(casC_list,bell_casC_alerts[11])end --FADEC BEC
-- if then table.insert(casC_list,bell_casC_alerts[12])end --FADEC DEGRADED
if float_arm == 1 then table.insert(casC_list,bell_casC_alerts[13])end --FLOAT ARM
if fuelQ*100 <=110 then table.insert(casC_list,bell_casC_alerts[14])end --FUEL LOW
-- if then table.insert(casC_list,bell_casC_alerts[15])end --FUEL VALVE
if gen == 1 then table.insert(casC_list,bell_casC_alerts[16])end --GEN FAIL
-- if then table.insert(casC_list,bell_casC_alerts[17])end --HEATER OVERTEMP
if hydr == 1 then table.insert(casC_list,bell_casC_alerts[18])end --HYDRAULIC SYS
-- if then table.insert(casC_list,bell_casC_alerts[19])end --L/FUEL BOOST
if xfrL == 0 then table.insert(casC_list,bell_casC_alerts[20])end --L/FUEL XFR
-- if then table.insert(casC_list,bell_casC_alerts[21])end --LITTER DOOR
if mgt1*100 >= 780 then table.insert(casC_list,bell_casC_alerts[22])end --MGT EXCEED
if ng1*10 >= 104 then table.insert(casC_list,bell_casC_alerts[23])end --NG EXCEED
-- if then table.insert(casC_list,bell_casC_alerts[24])end --NR MISCOMP
if nr1/4.13 >= 118 then table.insert(casC_list,bell_casC_alerts[25])end --NR EXCEED
if Pstop == 0 then table.insert(casC_list,bell_casC_alerts[26])end --PEDAL STOP
if Q/100*0.865 >=102.7 then table.insert(casC_list,bell_casC_alerts[27])end --Q EXCEED
-- if then table.insert(casC_list,bell_casC_alerts[28])end --Q MISCOMP
-- if then table.insert(casC_list,bell_casC_alerts[29])end --R/FUEL BOOST
if xfrR == 0 then table.insert(casC_list,bell_casC_alerts[30])end --R/FUEL XFR
-- if then table.insert(casC_list,bell_casC_alerts[31])end --SLIDING DOOR
-- if then table.insert(casC_list,bell_casC_alerts[32])end --T/R CHIP
-- if then table.insert(casC_list,bell_casC_alerts[33])end --XMSN CHIP
local casA_list ={}
-- if then table.insert(casA_list,bell_casA_alerts[1])end --ALTN DATA FAIL
if ignit[1] == 1 then table.insert(casA_list,bell_casA_alerts[2])end --AUTO RELIGHT
if antiice == 1 then table.insert(casA_list,bell_casA_alerts[3])end --ENG ANTI-ICE
-- if then table.insert(casA_list,bell_casA_alerts[4])end --ENG FUEL FILT
-- if then table.insert(casA_list,bell_casA_alerts[5])end --ENG MISCOMP
-- if then table.insert(casA_list,bell_casA_alerts[6])end --FADEC CHAN FAIL
-- if then table.insert(casA_list,bell_casA_alerts[7])end --FADEC MAINT
-- if then table.insert(casA_list,bell_casA_alerts[8])end --INST FAN
-- if then table.insert(casA_list,bell_casA_alerts[9])end --NG OAT LIMIT
-- if then table.insert(casA_list,bell_casA_alerts[10])end --QUITE MODE SEL
-- if then table.insert(casA_list,bell_casA_alerts[11])end --RESTART FAULT
-- if then table.insert(casA_list,bell_casA_alerts[12])end --START
local casS_list ={}
-- if then table.insert(casS_list,bell_casS_alerts[1])end --FLOAT TEST
if igw*2.20462 >=5000 then table.insert(casS_list,bell_casS_alerts[2])end --IGW VNE
-- if then table.insert(casS_list,bell_casS_alerts[3])end --QUITE MODE ON
if wog[1] == 1 then table.insert(casS_list,bell_casS_alerts[4])end --WOG
canvas_draw(cas_alerts_bell407, function()
if casW_list ~= nil then
for i = 1, #casW_list do
_rect(225,115+(i*20),190,20)
_fill("red")
_txt(casW_list[i],robR_20witL,230,125+(i*20))
end
end
if casC_list ~= nil then
for i = 1, #casC_list do
_txt(casC_list[i],robR_20yelL,230,125 + (#casW_list*20)+(i*20))
end
end
if casA_list ~= nil then
for i = 1, #casA_list do
_txt(casA_list[i],robR_20witL,230,125 + (#casW_list*20)+(#casC_list*20)+(i*20))
end
end
if casS_list ~= nil then
for i = 1, #casS_list do
_txt(casS_list[i],robR_20grnL,230,125 + (#casW_list*20)+(#casC_list*20)+(#casA_list*20)+(i*20))
end
end
end)
end
viewport_rect(cas_alerts_bell407,220,125,200,390)
xpl_dataref_subscribe_trottle("sim/cockpit2/annunciators/battery_charge_hi","INT",
"sim/cockpit/warnings/annunciators/engine_fires","INT[8]",
"sim/cockpit/warnings/annunciators/oil_temperature_high","INT[8]",
"sim/cockpit/warnings/annunciators/oil_pressure_low","INT[8]",
"B407/EngOut_Horn","FLOAT",
"B407/Panel/Np","FLOAT",
"B407/Fadec_Horn","FLOAT",
"sim/flightmodel/transmissions/xmsn_press","FLOAT",
"sim/flightmodel/transmissions/xmsn_temp","FLOAT",
"sim/cockpit2/annunciators/autopilot","INT",
"sim/cockpit2/annunciators/autopilot_trim_fail","INT",
"B407/Baggage","FLOAT",
"sim/cockpit2/annunciators/chip_detected","INT[8]",
"sim/flightmodel/engine/ENGN_oil_press_psi","FLOAT[8]",
"B407/Panel/Exceedance/MGT","FLOAT",
"B407/Float_Arm","FLOAT",
"B407/Panel/Fuel_Qty","FLOAT",
"sim/cockpit/warnings/annunciators/hydraulic_pressure","INT",
"B407/Overhead/Swt_BoostXFR_Left","FLOAT",
"B407/Overhead/Swt_BoostXFR_Right","FLOAT",
"sim/cockpit/warnings/annunciators/generator","INT",
"sim/cockpit/warnings/annunciators/igniter_on","INT[8]",
"B407/Overhead/Swt_Eng_AntiIce","FLOAT",
"sim/cockpit2/tcas/targets/position/weight_on_wheels","INT[64]",
"B407/Panel/Torque","FLOAT",
"B407/Panel/Nr","FLOAT",
"B407/Panel/Np","FLOAT",
"B407/Panel/Ng","FLOAT",
"B407/Panel/Mgt","FLOAT",
"B407/PedalStop","FLOAT",
"sim/flightmodel/weight/m_total","FLOAT",callback_w_cas,1000)
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
Re: Blinking text
Hey Keith
I have coded the CAS messages more or less like you have; i think i asked you in another thread about this
I am not sure how your code added functions.
What i understand this should make messages blink?
It resets data to nil , but how is this triggered?
grtz
Roel
I have coded the CAS messages more or less like you have; i think i asked you in another thread about this
I am not sure how your code added functions.
Code: Select all
-- Start a timer that will fire the callback on requested interval
timer_start(0, delta_ms, function()
if data ~= nil then
user_callback(table.unpack(data))
data = nil
end
end)
It resets data to nil , but how is this triggered?
grtz
Roel