Keith's LUA Help thread.
Re: Keith's LUA Help thread.
If Corjan can’t add that right now I would be confident in the code once the bugs are fixed. It works for a small array because I tested it and the logic is sound to scale up to 10x8. You could also buy a cheap array board for testing.
I have one of these.
I have one of these.
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
-
- Posts: 5339
- Joined: Thu Jul 27, 2017 12:22 am
Re: Keith's LUA Help thread.
Thanks Tony and KeithKeith Baxter wrote: ↑Fri Feb 07, 2020 6:30 am@SlingSling wrote: ↑Fri Feb 07, 2020 6:11 am Keith,
I don't remember coming up with a smart way for this one but after a quick look I've come up with a nice method that saves having to use any if..else's at all.
Some parts of the add function have bugs so the code is the way it is because of these. It can be tidied a little further once the bugs are fixed.
Its only for a 3x2 array but it will work for 10x8 by simply filling in the whole array with 80 elements and changing the n_rows and n_cols variable's to 10 & 8. The rest should be self explanatory.
@Ralph and @Corjan These are the issues.
--Note: named hardware for hw_button_array_add() function is broke in AM 3.7 beta 12 so do it the old way for now
--Note: the button_released argument is not required normally but a bug in AM 3.7 beta 12 exists that forces you to add it or you get an error
--Note: if you fail to declare the button_released function before the add it does not create an error, but it should
Code: Select all
local fmc_command = "laminar/B738/button/fmc1_" --array format = r1c1, r1c2, r2c1, r2c2, r3c1, r3c2 local fmc_command_array = {"A", "B", "C", "D", "E", "F"} local n_rows, n_cols = 3, 2 -- row function which is called after the column is established function button_pressed(row, col) local i = row * n_cols + (col + 1) xpl_command(fmc_command .. fmc_command_array[i]) print("button pressed at " .. row .. ", " .. col .. ", " .. fmc_command_array[i]) end function button_released(row, col) end -- Create button array with name "my keypad" with 10 rows and 8 columns --hw_button_array_add("my keypad", 3, 2, button_pressed, button_released) hw_button_array_add(n_rows, n_cols, "ARDUINO_UNO_A_D2", "ARDUINO_UNO_A_D3", "ARDUINO_UNO_A_D4", "ARDUINO_UNO_A_D8", "ARDUINO_UNO_A_D9", button_pressed, button_released)
Thank you Tony.
Yes I found those broken button array issues as well.
One of the reasons I was asking Corjan about support for the RPi zero is a remember having a chat to Ralph about 2 years ago.
With using the hw_button_array_add we cut down the number of pins used on the FMC from 69 to 18. That allows us to use a RPI for the 5" HDMI display and the button_array. Which is sweet.
I would want to test this first before I go to the effort of getting a PC board made and soldering 69 mini push buttons on it.
I did this before you posted your smart code. But it should work now. It is the Captains side FMC button hardware code.
@SimPassion
KeithCode: Select all
-- Callback function which is called when a button is pressed function button_pressed(row, column) --row1 if row == 1 and column == 1 then xpl_command("laminar/B738/button/fmc1_1L") elseif row == 1 and column == 2 then xpl_command("laminar/B738/button/fmc1_2L") elseif row == 1 and column == 3 then xpl_command("laminar/B738/button/fmc1_3L") elseif row == 1 and column == 4 then xpl_command("laminar/B738/button/fmc1_4L") elseif row == 1 and column == 5 then xpl_command("laminar/B738/button/fmc1_5L") elseif row == 1 and column == 6 then xpl_command("laminar/B738/button/fmc1_6L") --row 2 elseif row == 2 and column == 1 then xpl_command("laminar/B738/button/fmc1_1R") elseif row == 2 and column == 2 then xpl_command("laminar/B738/button/fmc1_2R") elseif row == 2 and column == 3 then xpl_command("laminar/B738/button/fmc1_3R") elseif row == 2 and column == 4 then xpl_command("laminar/B738/button/fmc1_4R") elseif row == 2 and column == 5 then xpl_command("laminar/B738/button/fmc1_5R") elseif row == 2 and column == 6 then xpl_command("laminar/B738/button/fmc1_6R") ---row 3 elseif row == 3 and column == 1 then xpl_command("laminar/B738/button/fmc1_init_ref") elseif row == 3 and column == 2 then xpl_command("laminar/B738/button/fmc1_rte") elseif row == 3 and column == 3 then xpl_command("laminar/B738/button/fmc1_clb") elseif row == 3 and column == 4 then xpl_command("laminar/B738/button/fmc1_crz") elseif row == 3 and column == 5 then xpl_command("laminar/B738/button/fmc1_des") ---row 4 elseif row == 4 and column == 1 then xpl_command("laminar/B738/button/fmc1_menu") elseif row == 4 and column == 2 then xpl_command("laminar/B738/button/fmc1_legs") elseif row == 4 and column == 3 then xpl_command("laminar/B738/button/fmc1_dep_app") elseif row == 4 and column == 4 then xpl_command("laminar/B738/button/fmc1_hold") elseif row == 4 and column == 5 then xpl_command("laminar/B738/button/fmc1_prog") elseif row == 4 and column == 6 then xpl_command("laminar/B738/button/fmc1_exec") --row 5 elseif row == 5 and column == 1 then xpl_command("laminar/B738/button/fmc1_n1_lim") elseif row == 5 and column == 2 then xpl_command("laminar/B738/button/fmc1_fix") elseif row == 5 and column == 3 then xpl_command("laminar/B738/button/fmc1_A") elseif row == 5 and column == 4 then xpl_command("laminar/B738/button/fmc1_B") elseif row == 5 and column == 5 then xpl_command("laminar/B738/button/fmc1_C") elseif row == 5 and column == 6 then xpl_command("laminar/B738/button/fmc1_D") elseif row == 5 and column == 7 then xpl_command("laminar/B738/button/fmc1_E") --row 6 elseif row == 6 and column == 1 then xpl_command("laminar/B738/button/fmc1_prev_page") elseif row == 6 and column == 2 then xpl_command("laminar/B738/button/fmc1_next_page") elseif row == 6 and column == 3 then xpl_command("laminar/B738/button/fmc1_F") elseif row == 6 and column == 4 then xpl_command("laminar/B738/button/fmc1_G") elseif row == 6 and column == 5 then xpl_command("laminar/B738/button/fmc1_H") elseif row == 6 and column == 6 then xpl_command("laminar/B738/button/fmc1_I") elseif row == 6 and column == 7 then xpl_command("laminar/B738/button/fmc1_J") --row 7 elseif row == 7 and column == 1 then xpl_command("laminar/B738/button/fmc1_1") elseif row == 7 and column == 2 then xpl_command("laminar/B738/button/fmc1_2") elseif row == 7 and column == 3 then xpl_command("laminar/B738/button/fmc1_3") elseif row == 7 and column == 4 then xpl_command("laminar/B738/button/fmc1_K") elseif row == 7 and column == 5 then xpl_command("laminar/B738/button/fmc1_L") elseif row == 7 and column == 6 then xpl_command("laminar/B738/button/fmc1_M") elseif row == 7 and column == 7 then xpl_command("laminar/B738/button/fmc1_N") elseif row == 7 and column == 8 then xpl_command("laminar/B738/button/fmc1_O") --row 8 elseif row == 8 and column == 1 then xpl_command("laminar/B738/button/fmc1_4") elseif row == 8 and column == 2 then xpl_command("laminar/B738/button/fmc1_5") elseif row == 8 and column == 3 then xpl_command("laminar/B738/button/fmc1_6") elseif row == 8 and column == 4 then xpl_command("laminar/B738/button/fmc1_P") elseif row == 8 and column == 5 then xpl_command("laminar/B738/button/fmc1_Q") elseif row == 8 and column == 6 then xpl_command("laminar/B738/button/fmc1_R") elseif row == 8 and column == 7 then xpl_command("laminar/B738/button/fmc1_S") elseif row == 8 and column == 8 then xpl_command("laminar/B738/button/fmc1_T") --row 9 elseif row == 9 and column == 1 then xpl_command("laminar/B738/button/fmc1_7") elseif row == 9 and column == 2 then xpl_command("laminar/B738/button/fmc1_8") elseif row == 9 and column == 3 then xpl_command("laminar/B738/button/fmc1_9") elseif row == 9 and column == 4 then xpl_command("laminar/B738/button/fmc1_U") elseif row == 9 and column == 5 then xpl_command("laminar/B738/button/fmc1_V") elseif row == 9 and column == 6 then xpl_command("laminar/B738/button/fmc1_W") elseif row == 9 and column == 7 then xpl_command("laminar/B738/button/fmc1_X") elseif row == 9 and column == 8 then xpl_command("laminar/B738/button/fmc1_Y") --row 10 elseif row == 10 and column == 1 then xpl_command("laminar/B738/button/fmc1_period") elseif row == 10 and column == 2 then xpl_command("laminar/B738/button/fmc1_0") elseif row == 10 and column == 3 then xpl_command("laminar/B738/button/fmc1_minus") elseif row == 10 and column == 4 then xpl_command("laminar/B738/button/fmc1_Z") elseif row == 10 and column == 5 then xpl_command("laminar/B738/button/fmc1_SP") elseif row == 10 and column == 6 then xpl_command("laminar/B738/button/fmc1_del") elseif row == 10 and column == 7 then xpl_command("laminar/B738/button/fmc1_slash") elseif row == 10 and column == 8 then xpl_command("laminar/B738/button/fmc1_clr") end print("button pressed at " .. row .. ", " .. column) end function button_released() end -- Create button array with name "my keypad" with 2 rows and 2 columns hw_button_array_add("my keypad", 10, 8, button_pressed, button_released)
I'll add this into the CDU/FMC logic for further work on it
I think I should also incorporate a new User Property to switch between the two method to avoid triggering twice a state : "Buttons only","Buttons array"
Gilles
Last edited by SimPassion on Wed Mar 11, 2020 4:18 pm, edited 1 time in total.
Re: Keith's LUA Help thread.
We'll give the issues reported a try next week.
Re: Keith's LUA Help thread.
The issue with the button array has been fixed for AM 3.7. Will be in next BETA.Sling wrote: ↑Fri Feb 07, 2020 6:11 am Keith,
I don't remember coming up with a smart way for this one but after a quick look I've come up with a nice method that saves having to use any if..else's at all.
Some parts of the add function have bugs so the code is the way it is because of these. It can be tidied a little further once the bugs are fixed.
Its only for a 3x2 array but it will work for 10x8 by simply filling in the whole array with 80 elements and changing the n_rows and n_cols variable's to 10 & 8. The rest should be self explanatory.
@Ralph and @Corjan These are the issues.
--Note: named hardware for hw_button_array_add() function is broke in AM 3.7 beta 12 so do it the old way for now
--Note: the button_released argument is not required normally but a bug in AM 3.7 beta 12 exists that forces you to add it or you get an error
--Note: if you fail to declare the button_released function before the add it does not create an error, but it should
Code: Select all
local fmc_command = "laminar/B738/button/fmc1_" --array format = r1c1, r1c2, r2c1, r2c2, r3c1, r3c2 local fmc_command_array = {"A", "B", "C", "D", "E", "F"} local n_rows, n_cols = 3, 2 -- row function which is called after the column is established function button_pressed(row, col) local i = row * n_cols + (col + 1) xpl_command(fmc_command .. fmc_command_array[i]) print("button pressed at " .. row .. ", " .. col .. ", " .. fmc_command_array[i]) end function button_released(row, col) end -- Create button array with name "my keypad" with 10 rows and 8 columns --hw_button_array_add("my keypad", 3, 2, button_pressed, button_released) hw_button_array_add(n_rows, n_cols, "ARDUINO_UNO_A_D2", "ARDUINO_UNO_A_D3", "ARDUINO_UNO_A_D4", "ARDUINO_UNO_A_D8", "ARDUINO_UNO_A_D9", button_pressed, button_released)
Corjan
Re: Keith's LUA Help thread.
Thanks Corjan. Will check when new beta is released.
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
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Keith's LUA Help thread.
@Sling
Tony you did this for me some time back. I am missing something. Please assist.
Keith
Tony you did this for me some time back. I am missing something. Please assist.
Code: Select all
LAT=-26.139200
LON=28.24600
---Formating decimal to dms ---
function format_dms(data, type)
local dir
if (type == "LAT") then
dir = fif (data < 0, "S", "N")
else
dir = fif (data < 0, "W", "E")
end
local data_abs = math.abs(data)
local deg = math.floor(data_abs)
local min = math.floor((data_abs % 1) * 60)
local sec = var_round((((data_abs % 1) * 60) % 1) * 60)
return deg .. "° " .. min .. "' " .. sec .. "\" " .. dir
end
lat_dms = format_dms(cent_lat, "LAT")
lon_dms = format_dms(cent_lon, "LON")
print("Latitude: " .. lat_dms)
print("Longitude: " .. lon_dms)
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
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Keith's LUA Help thread.
@Sling
No worries Tony. Worked it out. Had a bad day yesterday with some other issues and my mind went blank.
Amazing what a sleep does.
This happens at my age sometimes.
Keith
No worries Tony. Worked it out. Had a bad day yesterday with some other issues and my mind went blank.
Amazing what a sleep does.
This happens at my age sometimes.
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: Keith's LUA Help thread.
That saved me a job
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
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Keith's LUA Help thread.
Hi,
Please advise lua code.
How to convert to 24bit (0-16777215 or 0 - 0xFFFFFF) hexcode into a ASCII string?
Thanks,
Keith
Please advise lua code.
How to convert to 24bit (0-16777215 or 0 - 0xFFFFFF) hexcode into a ASCII string?
Thanks,
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: Keith's LUA Help thread.
tostring() ? Or wasn't that what you mean?