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