Toliss A321 Centre clock coding issue

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
SimPassion
Posts: 5346
Joined: Thu Jul 27, 2017 12:22 am

Re: Toliss A321 Centre clock coding issue

#21 Post by SimPassion »

Macsbig wrote: Wed Jan 11, 2023 8:00 pm ok, sounds good
Here's the script, it was a challenge due to some unavailable datarefs, together with the goal to be the more in sync able with the in-sim chrono
I've also added the center values to change while pushing Date button, so displaying the date : for this we have day and month datarefs but not the year, so we have to compute it based on current date. I guess this is similar to what Toliss done in their addon.

Now, for the main part, we should have behavior change on the chrono based on buttons pressed, but also the feedback of the sim when we press those same buttons in the virtual cockpit.
Additionally we are using timer triggering and timer state reading, to allow to be properly in sync with the in-sim values

Let me know Mark, the parts that should be clarified, just start with it, watch how it behave then try to understand how it work. I will help in next step. I guess, as it was your own logic at the start, things will go ahead quickly

When you get all is done here, we can go further by adding the visual knobs rotation for both the instrument and in-sim, in two ways.

Again feel free to ask again, this is not my instrument, even if it's interesting implement, my goal is only to help going ahead until you get the proper understanding.
Thanks having bring this nice idea, which make me ended to jump again in the Toliss A319, which is really amazing and takes its place nicely in X-Plane 12. I've already implemented new lighting for XP12 in a few aircrafts, in order to help their authors and the community to enjoy, though I have to admit I discover a high quality level with this one, as having just updated to 1.8.1 when starting working on your instrument. Toliss really have high skill and ability and the attention in details. Really enjoying this airplane :)

Code: Select all

--====================================================================================
--								CHECK PURPOSE
--====================================================================================

------------------------------------------
--A321 Center Clock						--
-- Author Mark B 22.12.2022				--
--Version 1.1							--
------------------------------------------

-- enjxp_SimPassion 10.01.2023
-- Mark B			22.12.2022

------------------------------------------
--  Load and display images in Z-order  --
------------------------------------------

img_add_fullscreen("background.png")
img_gpsswch = img_add("switch.png", 415, 210, 50, 85)
img_runswch = img_add("switch.png", 415, 335, 50, 85)

-- variables --

local timer_state    	= 0  -- 0: Stopped and reset / 1:running / 2:stopped
local timer_value    	= 0
local show_date			= 0
local time				= 0
local time_str			= ""
local curr_y			= 0

function get_year()
	time = math.floor(os.time())
	time_str = tostring(os.date("%Y", time))
	curr_y = string.sub(time_str,3,4)
end

-- Fonts --

style01					= "font:digital-7-mono.ttf; size:60px; color: #232937; halign: center;"
style02					= "font:digital-7-mono.ttf; size:65px; color: #232937; halign: center;"
style03					= "font:digital-7-mono.ttf; size:55px; color: #232937; halign: center;"
style04					= "font:digital-7-mono.ttf; size:60px; color: #FFFAD0; halign: center;"
style05					= "font:digital-7-mono.ttf; size:65px; color: #FFFAD0; halign: center;"
style06					= "font:digital-7-mono.ttf; size:55px; color: #FFFAD0; halign: center;"

-- Texts --

txt_bg_timer			= txt_add("88:88", style01,	180, 105, 158, 60)
txt_bg_grp1_grp2		= txt_add("88:88:", style02,134, 221, 208, 57)
txt_bg_grp3				= txt_add("88", style03,	328, 228,  80, 57)
txt_bg_et				= txt_add("88:88", style01,	183, 348, 158, 60)

txt_timer				= txt_add(" ", style04,		180, 105, 158, 60)
txt_clock_grp1_grp2		= txt_add(" ", style05,		134, 221, 208, 57)
txt_clock_grp3			= txt_add(" ", style06,		328, 228,  80, 57)
txt_et					= txt_add(" ", style04,		183, 348, 158, 60)

-- Buttons and Switches --

function chrbutton_pressed()
	xpl_command("toliss_airbus/chrono/ChronoStartStopPush")
end

button_add("button.png", "button_press.png", 415,100,60,60,chrbutton_pressed)
    
function rstbutton_pressed()
	xpl_command("toliss_airbus/chrono/ChronoResetPush")
end
    
button_add("button.png", "button_press.png",  54,100,60,60,rstbutton_pressed)

function datebutton_pressed()
	xpl_command("toliss_airbus/chrono/datePush","BEGIN")
end

function datebutton_released()
	xpl_command("toliss_airbus/chrono/datePush","END")
end

button_add("button.png", "button_press.png", 30, 215, 80, 80,datebutton_pressed,datebutton_released)

-- Timer----------------------------------------------
------------------------------------------------------

function timer_callback()
	if timer_state == 1 then
		timer_value = timer_value + 1       
	end
    txt_set(txt_timer, string.format("%02.0f:%02.0f", math.floor((timer_value / 60) % 60), (timer_value % 60)) )
end
    
function bus_volts(volts, showchr)
	visible(txt_timer, volts[1] >= 10 and showchr == 1)
end

xpl_dataref_subscribe (
						"sim/cockpit2/electrical/bus_volts", "FLOAT[6]",
						"AirbusFBW/ClockShowsChrono", "INT",
						bus_volts) 

-- Clock ----------------------------------------------
-------------------------------------------------------

function pr_dref(tZulu_hours, tZulu_minutes, tZulu_seconds, curr_m, curr_d, ethr, etmn, showet, etsw)

	if show_date == 0 then
		t_grp1 = tZulu_hours
		t_grp2 = math.floor(((tZulu_minutes/60)%1)*60)
		t_grp3 = tZulu_seconds
	else
		t_grp1 = curr_m
		t_grp2 = curr_d
		t_grp3 = curr_y
	end
	txt_set(txt_clock_grp1_grp2, string.format("%02d:%02d:", t_grp1, t_grp2))
	txt_set(txt_clock_grp3, string.format("%02d", t_grp3))
	txt_set(txt_et, string.format("%02.0f:%02.0f", (ethr), math.floor(((etmn/60)%1)*60)))
	visible(txt_et, showet == 1)
end

--  Data Refs --
                   
xpl_dataref_subscribe(
						"sim/cockpit2/clock_timer/zulu_time_hours", "INT", 
						"sim/cockpit2/clock_timer/zulu_time_minutes", "INT",
						"sim/cockpit2/clock_timer/zulu_time_seconds", "INT",
						"sim/cockpit2/clock_timer/current_month", "INT", 
						"sim/cockpit2/clock_timer/current_day", "INT", 
						"AirbusFBW/ClockETHours", "INT",
						"AirbusFBW/ClockETMinutes", "INT",
						"AirbusFBW/ClockShowsET", "INT",
						"AirbusFBW/ClockETSwitch", "INT",
					  pr_dref)

function pr_cmd_chr_startstop(chr_startstop)
	if timer_state == 0 then
		timer_state = 1
		timer_value = -1
		if timer_running(tmr_sec) == false then
			tmr_sec = timer_start(0,1000,timer_callback)
		end
	elseif timer_state == 1 then
		timer_state = 2
		if timer_running(tmr_sec) then
			timer_stop(tmr_sec)
		end
	elseif timer_state == 2 then
		timer_state = 1
		if timer_running(tmr_sec) == false then
			tmr_sec = timer_start(0,1000,timer_callback)
		end
	end
	visible(txt_timer, true)
end

function pr_cmd_chr_reset(chr_reset)
	timer_value   = 0
	if timer_state == 0 then
		if timer_running(tmr_sec) then
			timer_stop(tmr_sec)
		end
		visible(txt_timer, false)
	elseif timer_state == 1 then
		visible(txt_timer, true)
		if timer_running(tmr_sec) == false then
			tmr_sec = timer_start(0,1000,timer_callback)
		end
	elseif timer_state == 2 then
		if timer_running(tmr_sec) then
			timer_stop(tmr_sec)
		end
		timer_state = 0
		timer_value = -1
		visible(txt_timer, false)
	end
end

function pr_cmd_dateshow(dateshow)
	if dateshow == "BEGIN" or dateshow == "ONCE" then
		show_date = 1
	else
		show_date = 0
	end
end

xpl_command_subscribe("toliss_airbus/chrono/ChronoStartStopPush",
						pr_cmd_chr_startstop)
xpl_command_subscribe("toliss_airbus/chrono/ChronoResetPush",
						pr_cmd_chr_reset)
xpl_command_subscribe("toliss_airbus/chrono/datePush",
						pr_cmd_dateshow)

get_year()

Macsbig
Posts: 31
Joined: Sun Jan 01, 2023 9:02 pm

Re: Toliss A321 Centre clock coding issue

#22 Post by Macsbig »

Thank you so much SimPassion, you have gone way beyond what I asked initially, and I'm sure I will learn a great deal from your code.

I have spent all my time over many months designing, 3d printing and programming EFIS, FCU and MCDU, and designing a cockpit. This has stopped me from enjoying the sim, but I need to do this. Now I am learning Air Manager and LUA. It's a lot of learning... but very interesting!

I will spend the next day or two disecting your code, between giving my attention to my wife and children!

I did notice the odd date format of just a date number myself, and was thinking about how to format the data, I'll check out your ideas.

Thanks again, I appriciate your efforts.

Cheers

Mark
Currently building my own home cockpit, general purpose one with 3 x 32” wrap around monitors and two lower monitors for instruments and PFD’s. Currently, putting together parts for the Toliss A321

SimPassion
Posts: 5346
Joined: Thu Jul 27, 2017 12:22 am

Re: Toliss A321 Centre clock coding issue

#23 Post by SimPassion »

Nice !
Enjoy time with family and building your cockpit in free time. Time will come with great flights to perform.

Macsbig
Posts: 31
Joined: Sun Jan 01, 2023 9:02 pm

Re: Toliss A321 Centre clock coding issue

#24 Post by Macsbig »

Hi again SimPassion

I have been looking over your code, but as always for me, I find the best way is to code and get ideas/resolutions as I go along... I learn quicker, and my attention stays longer this way!

So I have started to code the switches, they work - well they pick up the datarefs from XP11 and move the position accordingly, which is good, but the mouse doesn't seem to move my instrument and when I tried to use the mouse_setting function, I just got an error - I'm not even sure I need this function?

If you get time, I would appreciate you taking a look, and giving my code the once over - maybe there is a better way to code my ideas!

I will send the file to you.

Cheers!
Currently building my own home cockpit, general purpose one with 3 x 32” wrap around monitors and two lower monitors for instruments and PFD’s. Currently, putting together parts for the Toliss A321

SimPassion
Posts: 5346
Joined: Thu Jul 27, 2017 12:22 am

Re: Toliss A321 Centre clock coding issue

#25 Post by SimPassion »

Macsbig wrote: Fri Jan 13, 2023 5:55 pm Hi again SimPassion

I have been looking over your code, but as always for me, I find the best way is to code and get ideas/resolutions as I go along... I learn quicker, and my attention stays longer this way!

So I have started to code the switches, they work - well they pick up the datarefs from XP11 and move the position accordingly, which is good, but the mouse doesn't seem to move my instrument and when I tried to use the mouse_setting function, I just got an error - I'm not even sure I need this function?

If you get time, I would appreciate you taking a look, and giving my code the once over - maybe there is a better way to code my ideas!

I will send the file to you.

Cheers!
Ok, I will have a look into it, not already opened PM at the moment, let me a bit of time please and I will report to you
I guess the mouse_settings is not required in any case ...
To soon !

Macsbig
Posts: 31
Joined: Sun Jan 01, 2023 9:02 pm

Re: Toliss A321 Centre clock coding issue

#26 Post by Macsbig »

yes, sure, there is no hurry :-)
Currently building my own home cockpit, general purpose one with 3 x 32” wrap around monitors and two lower monitors for instruments and PFD’s. Currently, putting together parts for the Toliss A321

SimPassion
Posts: 5346
Joined: Thu Jul 27, 2017 12:22 am

Re: Toliss A321 Centre clock coding issue

#27 Post by SimPassion »

Macsbig wrote: Fri Jan 13, 2023 8:48 pm yes, sure, there is no hurry :-)
Here's some inputs after answering by PM, this could be useful for anyone wanting a bit of more understanding on this instrument
They've made great and simple explanation and clarification here :
https://www.skalarki-electronics.com/en ... oject.html

Image


Macsbig
Posts: 31
Joined: Sun Jan 01, 2023 9:02 pm

Re: Toliss A321 Centre clock coding issue

#29 Post by Macsbig »

Thanks for your reply,

I seem to be having issues sending Pm's, so hopefully it will get to you
Currently building my own home cockpit, general purpose one with 3 x 32” wrap around monitors and two lower monitors for instruments and PFD’s. Currently, putting together parts for the Toliss A321

SimPassion
Posts: 5346
Joined: Thu Jul 27, 2017 12:22 am

Re: Toliss A321 Centre clock coding issue

#30 Post by SimPassion »

Macsbig wrote: Sat Jan 14, 2023 11:46 am Thanks for your reply,

I seem to be having issues sending Pm's, so hopefully it will get to you
Hi Mark, the PM still stay in "Outbox" with amount number of message between parenthesis, which indicates recipient not already opened your message, so no issue here

image.png
image.png (586 Bytes) Viewed 605 times
 

Post Reply