Complex coding for Backlights
Complex coding for Backlights
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
Mikemike
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Complex coding for Backlights
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.
()
keith
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
Re: Complex coding for Backlights
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.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
Joe
Joe. CISSP, MSc.
Re: Complex coding for Backlights
Hi,
Request_callback should only be used on subscription callback functions, not on your own function like 'dim_my_canvas'.
Corjan
Request_callback should only be used on subscription callback functions, not on your own function like 'dim_my_canvas'.
Corjan
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Complex coding for Backlights
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
Re: Complex coding for Backlights
See the wiki?
Corjan
Corjan
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Complex coding for Backlights
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
Re: Complex coding for Backlights
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
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
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: Complex coding for Backlights
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
Re: Complex coding for Backlights
Thanks Keith, this should keep me busy for a few days, lol.