Complex coding for Backlights

Questions about deployment and use of Air Manager Instruments

Moderators: Ralph, russ

Message
Author
Mikemike
Posts: 41
Joined: Thu Feb 11, 2021 11:33 pm

Complex coding for Backlights

#1 Post by Mikemike » Tue Mar 09, 2021 9:14 pm

Ok, I have tried and failed. I don't want it done for me, but where do I start getting the actual AM instrument to dim with hardware? I have it working fine in the sim. Is it done with a SI variable, Xplane subscription through the AM data viewer, instrument properties addition? I've tried some scripting without success and probably for good reason....because I'm ignorant and I can't figure it out. I'm starting with the cessna RPM tach dial first. Is this just something that is too complex for a newbie? Should I just live with it? I know this isn't a new topic, I just haven't found one that can explain it.

Mikemike

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

Re: Complex coding for Backlights

#2 Post by Keith Baxter » Tue Mar 09, 2021 11:18 pm

Hi,

Don't get frustrated.
Start at the beginning. Create a test instrument with an image or a canvas_draw. Something like this.
There are other ways but this should give you the gist.

Code: Select all

my_canvas=canvas_add(0,0,400,400)

---lets draw the inital red box
  canvas_draw(my_canvas, function()
     _rect(50,50,200,200)
     _fill("red",1) --Note the 1 after the "red". It is the opacity
  end)
  
---now lets dim the red box

--create a var for dimming/opacity
dim_var=1
--Add a function
function dim_my_canvas()
  canvas_draw(my_canvas, function()
     _rect(50,50,200,200)
     _fill("red",dim_var) ---Note we have used the var we created vary the opacity
  end)
end

---add your dial
function dial_change(dir)
   dim_var=dim_var+(dir*0.1) ---Change the opacity value
   var_cap(dim_var,0,1) ---Limit the scope of the opacity value.
   request_callback(dim_my_canvas()) --force a callback to the dim function
end

-- Create a new rotary encoder
hw_dial_add("dimmer", dial_change)
()


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
jph
Posts: 661
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Complex coding for Backlights

#3 Post by jph » Wed Mar 10, 2021 11:02 am

Keith Baxter wrote:
Tue Mar 09, 2021 11:18 pm
Hi,

Don't get frustrated.
Start at the beginning. Create a test instrument with an image or a canvas_draw. Something like this.
There are other ways but this should give you the gist.

Code: Select all

my_canvas=canvas_add(0,0,400,400)

---lets draw the inital red box
  canvas_draw(my_canvas, function()
     _rect(50,50,200,200)
     _fill("red",1) --Note the 1 after the "red". It is the opacity
  end)
  
---now lets dim the red box

--create a var for dimming/opacity
dim_var=1
--Add a function
function dim_my_canvas()
  canvas_draw(my_canvas, function()
     _rect(50,50,200,200)
     _fill("red",dim_var) ---Note we have used the var we created vary the opacity
  end)
end

---add your dial
function dial_change(dir)
   dim_var=dim_var+(dir*0.1) ---Change the opacity value
   var_cap(dim_var,0,1) ---Limit the scope of the opacity value.
   request_callback(dim_my_canvas()) --force a callback to the dim function
end

-- Create a new rotary encoder
hw_dial_add("dimmer", dial_change)
()


keith
Nice one Keith, it is really great to see good commenting in code. It is SO helpful to others. imho, ALL code submitted should be adequately commented as it is THE best learning tool for others. Hats off to you sir.
Joe
“Everything in moderation, including moderation.”
“Experience is merely the name men gave to their mistakes.”
Joe (CISSP) -IT security consultant

User avatar
Corjan
Posts: 2371
Joined: Thu Nov 19, 2015 9:04 am

Re: Complex coding for Backlights

#4 Post by Corjan » Wed Mar 10, 2021 11:16 am

Hi,

Request_callback should only be used on subscription callback functions, not on your own function like 'dim_my_canvas'.

Corjan

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

Re: Complex coding for Backlights

#5 Post by Keith Baxter » Wed Mar 10, 2021 11:32 am

Corjan wrote:
Wed Mar 10, 2021 11:16 am
Hi,

Request_callback should only be used on subscription callback functions, not on your own function like 'dim_my_canvas'.

Corjan
Corjan,

I did not know that. Please explain what a "subscription callback function" is.


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
Corjan
Posts: 2371
Joined: Thu Nov 19, 2015 9:04 am

Re: Complex coding for Backlights

#6 Post by Corjan » Wed Mar 10, 2021 11:36 am

See the wiki?

Corjan

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

Re: Complex coding for Backlights

#7 Post by Keith Baxter » Wed Mar 10, 2021 11:50 am

Corjan wrote:
Wed Mar 10, 2021 11:36 am
See the wiki?

Corjan
:lol: :lol: :lol:
Ok I get it.

I am now worried that I abuse the argument.

Keith
Last edited by Keith Baxter on Wed Mar 10, 2021 1:04 pm, edited 1 time 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
Sling
Posts: 4440
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Complex coding for Backlights

#8 Post by Sling » Wed Mar 10, 2021 12:52 pm

Keith,

If you want to call one of your own functions you just call it by name. The request_callback() is just for forcing a subscribe callback to run with the latest state of the subscribes.

Tony

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

Re: Complex coding for Backlights

#9 Post by Keith Baxter » Wed Mar 10, 2021 1:03 pm

Sling wrote:
Wed Mar 10, 2021 12:52 pm
Keith,

If you want to call one of your own functions you just call it by name. The request_callback() is just for forcing a subscribe callback to run with the latest state of the subscribes.

Tony
Thanks Tony.

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 

Mikemike
Posts: 41
Joined: Thu Feb 11, 2021 11:33 pm

Re: Complex coding for Backlights

#10 Post by Mikemike » Wed Mar 10, 2021 4:56 pm

Thanks Keith, this should keep me busy for a few days, lol.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests