Blinking text

Help and techniques for creating Air Manager Instrument Graphics

Moderators: russ, Ralph

Message
Author
Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

Blinking text

#1 Post by Shimokuta »

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?

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Blinking text

#2 Post by Keith Baxter »

Hi,

Use a timer.

Code: Select all

pulse=0
timer_start(0, 500, function()
    pulse=pulse+1
    if pulse>=2 then pulse=0 end
end)
Then change the color,make the text visible or not or simply change the opacity when pulse value is 1 or 0.

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 

User avatar
Ralph
Posts: 7876
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Blinking text

#3 Post by Ralph »

A little easier:

Code: Select all

timer_start(nil, 500, function(count)
 visible(my_text, count%2 == 0)
end)

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Blinking text

#4 Post by Keith Baxter »

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

Code: Select all

canvas_draw(my_canvas, function()
   _txt("The blinking Eye", text_style,30,30,pulse)
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 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Blinking text

#5 Post by Sling »

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.

Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

Re: Blinking text

#6 Post by Shimokuta »

hmm no luck yet ...
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)
but text is shown without blinking

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Blinking text

#7 Post by Keith Baxter »

Shimokuta wrote: Sun Apr 17, 2022 6:52 am hmm no luck yet ...
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)
but text is shown without blinking
Hi,

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
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 

Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

Re: Blinking text

#8 Post by Shimokuta »

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

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Blinking text

#9 Post by Keith Baxter »

Shimokuta wrote: Sun Apr 17, 2022 7:55 am 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
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"}
Then I use a dataref throttle to restrict the number of dataref calls.
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)
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 

Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

Re: Blinking text

#10 Post by Shimokuta »

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.

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)
What i understand this should make messages blink?
It resets data to nil , but how is this triggered?

grtz

Roel

Post Reply