Marcnamara2021 menu and coding help

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

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

Marcnamara2021 menu and coding help

#1 Post by Keith Baxter »

@Marcnamara2021

I have created this thread as what I am about to share is OT to your previous one.

I see you are using some synoptic. So I am going to share how I do it.
This instrument will be WIP and we will add bit by bit. Here I am using synoptic's from the TBM850

Take a look at what I am doing and feel free to ask any questions and pass comment.
This is what we are drawing.
ice_screenshot_20211202-164912.png


Example Menu - tbm.siff
(7.85 KiB) Downloaded 166 times
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
Marcnamara2021
Posts: 83
Joined: Wed Dec 01, 2021 6:00 am
Location: Sao Jose dos Campos, SP

Re: Marcnamara2021 menu and coding help

#2 Post by Marcnamara2021 »

hI,

Thanks a lot. I will see.

:D

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

Re: Marcnamara2021 menu and coding help

#3 Post by Keith Baxter »

Hi,

The next page will be the electrical page. Here breakers move, color changes etc
ice_screenshot_20211202-171753.png
In other words we will do all these statuses.
ice_screenshot_20211202-172903.png
ice_screenshot_20211202-172914.png
ice_screenshot_20211202-172914.png (23.23 KiB) Viewed 2799 times



After that I will do a fuel page that shows fuel levels in the wings and crossover pumps working or not.
I will also do one checklist.

Then I will add the menu and how to select the various pages. After that you should be a master at menu's and canvas_draw() :mrgreen:

If anyone else would like to know something. Feel free to chime in.

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
Marcnamara2021
Posts: 83
Joined: Wed Dec 01, 2021 6:00 am
Location: Sao Jose dos Campos, SP

Re: Marcnamara2021 menu and coding help

#4 Post by Marcnamara2021 »

Hi. Thanks for the example, but I wasn't able to establish logical similarity parameters. perhaps because my knowledge is superficial for this task. In my logical thinking I would just need to make the pushbutton enable the visibility condition when pressed on certain VAR of point_pos. However when I insert the hardware pushbutton integration lines into any layer, Air Manager simply doesn't enable it, only in the instrument's default layer. This is normal?

I, in my limited knowledge, just thought of the logic that - <if the encoder positions the menu cursor over a certain line(point_pos) and if the push_button is pressed in this state, then it makes the respective requested screen visible. Im not working with canvas resources, just in the menu that you sent me.

Let me know if you've been sadly mistaken, as in fact, I already do these screen switchings on other instrument-specific pushbuttons.

see the example in the video from my google drive for better explanation

https://drive.google.com/file/d/1wpHvOK ... sp=sharing

Thank You

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

Re: Marcnamara2021 menu and coding help

#5 Post by Keith Baxter »

Hi,

Ok I knocked this up quick. Let me know if it helps?

Run it on a 600x600 instrument

Code: Select all

----Creat font styles
robR_16witC="font:arimo_bold.ttf; size:16px; color: white; halign:left; valign:center;"
robR_24witC="font:arimo_bold.ttf; size:24px; color: white; halign:left; valign:center;"

robR_16yelC="font:arimo_bold.ttf; size:16px; color: yellow; halign:left; valign:center;"
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------

--- I am creating canvases that simulate your pages for demo purposes
red_canvas         =canvas_add(0,0,600,600)
green_canvas      =canvas_add(0,0,600,600)
yellow_canvas     =canvas_add(0,0,600,600)
blue_canvas        =canvas_add(0,0,600,600)
orange_canvas    =canvas_add(0,0,600,600)

--Draw a background.
background = canvas_add(0, 0, 600, 600, function()
   _rect(0,0,400,512)
   _fill("blue")
end)
canvas_draw(red_canvas, function()
  _rect(0,0,600,600)
  _fill("red")
end)

canvas_draw(green_canvas, function()
  _rect(0,0,600,600)
  _fill("green")
end)

canvas_draw(yellow_canvas, function()
  _rect(0,0,600,600)
  _fill("yellow")
end)

canvas_draw(blue_canvas, function()
  _rect(0,0,600,600)
  _fill("blue")
end)

canvas_draw(orange_canvas, function()
  _rect(0,0,600,600)
  _fill("orange")
end)
visible(red_canvas,       false)
visible(green_canvas,    false)
visible(yellow_canvas,   false)
visible(blue_canvas,      false)
visible(orange_canvas,  false)
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
--Create table for different Menues
menu1               ={"Red page","Green page","Yellow page","Blue page","Orange page"}
--- Here we create tables that are used for switching
visible_table0      = {false,false,false,false,false}
visible_table1      = {true,false,false,false,false}
visible_table2      = {false,true,false,false,false}
visible_table3      = {false,false,true,false,false}
visible_table4      = {false,false,false,true,false}
visible_table5      = {false,false,false,false,true}

vis_count_table     = {visible_table1,visible_table2,visible_table3,visible_table4,visible_table5}
visible_master      = visible_table0 
print(visible_master)
---Test instrument to manually scroll pointer and highlight selected text

--Draw a menu.
menu = canvas_add(0, 0, 512, 512, function()
  for i=1,#menu1 do
    if i==1 then 
      _txt(menu1[i],robR_16yelC,50,10+(i*25)) 	
	else
      _txt(menu1[i],robR_16witC,50,10+(i*25))
    end	  
  end
end)
--Draw a marker.
marker = canvas_add(0, 0, 20, 20, function()
    _txt("►",robR_24witC,5,5,nil,nil) 
end)
--position the marker
move(marker,20,25,nil,nil)

menu_group=group_add(menu,marker,background)
---------------------------------------------------------------------------------------------------
---Functions
---------------------------------------------------------------------------------------------------
point_pos=1
function dial_change(dir)
  point_pos=var_cap(point_pos+dir,1,#menu1)
  
move(marker,20,0+(point_pos*25),nil,nil)  
 
canvas_draw(menu, function()
  for i=1,#menu1 do
    if i==point_pos then 
      _txt(menu1[i],robR_16yelC,50,10+(i*25))
    else	  
      _txt(menu1[i],robR_16witC,50,10+(i*25))	
	end
  end
end)

  visible_master      = vis_count_table[point_pos] 

  visibility()
end

but_count=0
function button_pressed()
   but_count=but_count+1
   if but_count > 1 then but_count =0 end
   visible(menu_group,but_count==0)
  print(but_count)
  
  visibility()
end


function visibility()
   visible(red_canvas,             visible_master[1]and but_count==1)
   visible(green_canvas,          visible_master[2]and but_count==1)
   visible(yellow_canvas,         visible_master[3]and but_count==1)
   visible(blue_canvas,            visible_master[4]and but_count==1)
   visible(orange_canvas,         visible_master[5]and but_count==1)
end


-- Create Hardware
hw_dial_add("Menu Scroll", dial_change)
hw_button_add("Select button", button_pressed)
Keith
Last edited by Keith Baxter on Thu Dec 02, 2021 11:52 pm, edited 2 times in total.
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
Marcnamara2021
Posts: 83
Joined: Wed Dec 01, 2021 6:00 am
Location: Sao Jose dos Campos, SP

Re: Marcnamara2021 menu and coding help

#6 Post by Marcnamara2021 »

Hi! Thanks..... I will try this.
:D

User avatar
Marcnamara2021
Posts: 83
Joined: Wed Dec 01, 2021 6:00 am
Location: Sao Jose dos Campos, SP

Re: Marcnamara2021 menu and coding help

#7 Post by Marcnamara2021 »

Exactly!!! Perfect!!! I will adapt in my script!!!!
Thank a lot.
:lol: :lol: :lol:

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

Re: Marcnamara2021 menu and coding help

#8 Post by Keith Baxter »

Marcnamara2021 wrote: Thu Dec 02, 2021 8:16 pm Exactly!!! Perfect!!! I will adapt in my script!!!!
Thank a lot.
:lol: :lol: :lol:
Hi,

Glad to assist.

Let me know if you want me to expand on the Synoptics and checklists. I will stop what I was trying to share. Should it be of interest then press my button and I will continue. :mrgreen:
Checklists go to another level. Just shout if you need help with that.

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
Marcnamara2021
Posts: 83
Joined: Wed Dec 01, 2021 6:00 am
Location: Sao Jose dos Campos, SP

Re: Marcnamara2021 menu and coding help

#9 Post by Marcnamara2021 »

My doubts is about - Nearest Way Point - in the especific topic published.

Thanks

Marcio

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

Re: Marcnamara2021 menu and coding help

#10 Post by Keith Baxter »

Marcnamara2021 wrote: Fri Dec 03, 2021 1:41 pm My doubts is about - Nearest Way Point - in the especific topic published.

Thanks

Marcio
Hi,

I will share what I do. But take a look here first.

http://siminnovations.com/wiki/index.ph ... et_nearest

And to get distance and direction..

https://www.forums.siminnovations.com/v ... 248#p30076

This code does nearest intersections.

Code: Select all

-------------------------------------------------------------------------------------------------------------------
---***Nearest Intersections***---
-------------------------------------------------------------------------------------------------------------------
	function timer2_callback(count)
		nrst_int_bearing_table={}
		nrst_int_distance_table={}
-- Find the nearest Intersections within a 25nm Radius from a certain latitude and longitude
		local function nearest_waypoints(wayp)
			nrst_int=wayp
		end
		nav_get_radius("WAYPOINT", lat1, lon1,25,100,nearest_waypoints)
		if nrst_int ~= nil then
		
			for i=1,#nrst_int do
				lat2 = nrst_int[i]["LATITUDE"]
				lon2 = nrst_int[i]["LONGITUDE"]
			R = 6371e3
				local a1 = math.rad(lat1)			-- φ1
				local a2 = math.rad(lat2)			-- φ2
				local o1 = math.rad(lon1)			-- λ1
				local o2 = math.rad(lon2)			-- λ2
				local ax = math.rad(lat2-lat1)	    -- Δφ
				local ay = math.rad(lon2-lon1)	    -- Δλ
		
---Bearing between two coordinates---
				y = math.sin(o2-o1) * math.cos(a2);
				x = math.cos(a1)*math.sin(a2) - math.sin(a1)*math.cos(a2)*math.cos(o2-o1)
				brng = math.atan(y, x)
				deg_brng=math.deg(brng)
				if deg_brng <0 then deg_brng=deg_brng+360+mag_var end 
				if deg_brng >360 then deg_brng=deg_brng-360+mag_var end 		
				nrst_int_bearing_table[i]=deg_brng--+mag_var
				
				a = (math.sin(ax/2)*math.sin(ax/2)) + math.cos(a1) * math.cos(a2) * (math.sin(ay/2)*math.sin(ay/2))
				c = 2 *  math.atan(math.sqrt(a)/math.sqrt(1-a))
				d = R * c		
				nrst_int_distance_table[i]=d/1852
				
---Calculate the Map scale Factor
				if nrst_int_distance_table[fms_cnt] ~= nil then
				new_dist=nrst_int_distance_table[fms_cnt]
				end

				if new_dist <= 3 then map_scale = 12000/2 rose_dist=2.0 end
				if new_dist > 3 and new_dist <= 3.75 then map_scale = 12000/2.5 rose_dist= 2.5 end
				if new_dist >3.75 and new_dist <= 5.625 then map_scale = 12000/3.75 rose_dist= 3.75 end
				if new_dist >5.625 and new_dist <= 7.5 then map_scale = 12000/5 rose_dist=5.0 end
				if new_dist >7.5 and new_dist <= 11.25then map_scale = 12000/7.5 rose_dist=7.5 end
				if new_dist >11.25 and new_dist <= 18.75 then map_scale = 12000/12.5 rose_dist=12.5 end				
				if new_dist >18.75 then map_scale = 12000/20 rose_dist=20.0 end				
				
---Deturmin intersection map position
			int_pos_lat=600+(nrst_int[fms_cnt]["LATITUDE"]-lat1)*-map_scale
			int_pos_lon=600+(nrst_int[fms_cnt]["LONGITUDE"]-lon1)*map_scale
							
			end
			canvas_draw(nrst_inter_text,function()
				for i = 1,#nrst_int do
				_txt(nrst_int[i]["ICAO"],arR_24blublkL,945,125+(i*30))
				_txt(string.format("%.0f°",nrst_int_bearing_table[i]),arR_24blublkR,1100,125+(i*30))
				_txt(string.format("%.1fnm",nrst_int_distance_table[i]),arR_24blublkR,1195,125+(i*30))
				end
			end)
			canvas_draw(cumpas_scale_int_canvas,function()
				_txt(rose_dist.."  NM",arB_20vlgC,730,460)	
			end)			

---Map Navagation Indicators Intersections	

		if int_pos_lat ~= nil and int_pos_lon ~= nil then
			canvas_draw(nav_canvas_nrst_int,function()
--				for i=1,#nrst_int do
--					_circle(600+(nrst_int[i]["LONGITUDE"]-lon1)*map_scale,600+(nrst_int[i]["LATITUDE"]-lat1)*-map_scale,1.5)
--					_fill("#05fcfe")
--					_txt(nrst_int[i]["ICAO"],arR_16vlgC,600+(nrst_int[i]["LONGITUDE"]-lon1)*map_scale,(600+(nrst_int[i]["LATITUDE"]-lat1)*-map_scale)-15)
--				end
				for i=1,#nrst_airp do
					_rect(591+(nrst_airp[i]["LONGITUDE"]-lon1)*map_scale,591+(nrst_airp[i]["LATITUDE"]-lat1)*-map_scale,18,18)
					_fill_img(image_airp,591+(nrst_airp[i]["LONGITUDE"]-lon1)*map_scale,591+(nrst_airp[i]["LATITUDE"]-lat1)*-map_scale,18,18)
				end
				_move_to(600,600)
				_line_to(int_pos_lon,int_pos_lat)
				_stroke("white",0.8)
				_txt(nrst_int[fms_cnt]["ICAO"],arR_20witC,int_pos_lon,int_pos_lat-15)
				_circle(int_pos_lon,int_pos_lat,1.5)
				_fill("white")

			end)			
		end
			move(nav_canvas_nrst_int,50,-150,nil,nil)
					
			canvas_draw(nrst_inter_info_text,function()
				---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 dir.."  "..deg .. "° " .. min .. "' " .. sec .. "\" " 
				end
			if nrst_int[fms_cnt]~= nil then	
				lat_dms = format_dms(nrst_int[fms_cnt]["LATITUDE"], "LAT")
				lon_dms = format_dms(nrst_int[fms_cnt]["LONGITUDE"], "LON")

				_txt(lat_dms,arR_24blublkL,945,527)
				_txt(lon_dms,arR_24blublkL,945,548)	
			end				
			end)			
		end
	end
	timer_start(0, 1000, timer2_callback)
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 

Post Reply