Jump to content

DCS-BIOS A-10 Panel Backlighting Enable


No1sonuk

Recommended Posts

TL : DR Is there an output from DCS-BIOS I can use to enable panel backlighting in sync with the game?

 

 

I've got some code working that reads the potentiometer position on the Lighting Control Panel (LCP) and uses that number, suitably remapped, to adjust the master brightness control of a strip of WS2812 or neopixel addressable LEDs for the panel backlight.

 

However, at present, the lights come on as soon as the control is moved as my code only detects the control position. This is obviously not how it works IRL or in game.

 

So, is there an output, or set of outputs, from DCS-BIOS I can use to enable panel backlighting in sync with the game?

Link to comment
Share on other sites

If you have physical panels, why not use the physical switch? If there is an output from DCS-BIOS to tell if you have power it will be great but if you use a check list and turn up lighting at the proper time it wouldn't be an issue...

Link to comment
Share on other sites

If you have physical panels, why not use the physical switch?

Two reasons:

1) It syncs with the game screens (apart from the enable issue)

2) It saves wiring the controls to every other panel - each instrument can read the appropriate control from the main data stream.

Link to comment
Share on other sites

bool power_is_on;

void onMainElectricPowerChange(unsigned in newValue) {
power_is_on = newValue;
}
DcsBios::IntegerBuffer MainElectricPowerBuffer(0x..., 0x...., 00, onMainElectricPowerChange);

 

Then on backlight change check if power is on or not and turn power on if so and so on.

 

This is what I use to check if power is on etc to make my solenoid for my start switch in the Viggen to engage only when all the needed switches is in the correct position.

Link to comment
Share on other sites

This is what I use to check if power is on etc to make my solenoid for my start switch in the Viggen to engage only when all the needed switches is in the correct position.

Thanks, but the A-10 doesn't have the "MainElectricPowerBuffer" function. I tried anyway in case the proper address worked (I got it from the Viggen's control reference), but it didn't.

 

What I HAVE found is "aoaPwroffBuffer" which is the Angle Of Attack gauge power off Flag.

It's not 100% the right flag, but I think it'll do as a workaround.

Link to comment
Share on other sites

No need for workarounds. You can just use the actual output parameter for the console lights (and the other cockpit lights if you'd like).

 

You need to add it yourself to the A10C.lua though. Put this at the end of the file, just above "BIOS.protocol.endModule()" to avoid changing the addresses of the other functions:

defineFloat("INTERNAL_CONSOLE_LIGHTS", 800, {0, 1}, "zAdditional Parameters", "Console Lights")
defineFloat("INTERNAL_ENG_INST_LIGHTS", 801, {0, 1}, "zAdditional Parameters", "Engine Instrument Lights")
defineFloat("INTERNAL_FLT_INST_LIGHTS", 802, {0, 1}, "zAdditional Parameters", "Flight Instruments Lights")
defineFloat("INTERNAL_AUX_INST_LIGHTS", 803, {0, 1}, "zAdditional Parameters", "Auxiliary Instruments Lights")
defineFloat("INTERNAL_FLOOD_LIGHTS", 806, {0, 1}, "zAdditional Parameters", "Flood Lights")

Run a mission and your control reference should have the new outputs that you can remap to the PWM for your LED strip or whatever.

You can give the group of outputs another name than "zAdditional Parameters", if you'd like.

Link to comment
Share on other sites

No need for workarounds. You can just use the actual output parameter for the console lights (and the other cockpit lights if you'd like).

Thanks. I'll give that a try tomorrow.

 

I have it working the way I want now, with no mods to existing files.

This code is partial code for the CMS panel which I'm using for testing:

/*
 Tell DCS-BIOS to use a serial connection and use interrupt-driven
 communication. The main program will be interrupted to prioritize
 processing incoming data.
 
 This should work on any Arduino that has an ATMega328 controller
 (Uno, Pro Mini, many others).
*/

//  This code was written to test combining some functions of the CMS panel and
//  addressable LED backlighting
//  It includes some code purely for use in testing, such as test value display


#define DCSBIOS_IRQ_SERIAL

// #include <Servo.h>

#include <FastLED.h>

#include <Wire.h>
/*
I2C connections:
Board           I2C / TWI pins
Uno, Nano       A4 (SDA), A5 (SCL)
Mega2560        20 (SDA), 21 (SCL)
Leonardo        2 (SDA), 3 (SCL)
Due             20 (SDA), 21 (SCL), SDA1, SCL1
*/

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 20 chars and 4 line display


#include "DcsBios.h"

/* paste code snippets from the reference documentation here */

//  Some parameters for the addressable backlight LEDs

#define BACKLIGHTPIN  9  // Which pin on the Arduino is connected to the NeoPixels?
#define NUMPIXELS  12    // How many NeoPixels are attached to the Arduino?

uint8_t backlightBrightness = 64; // initial value - will be reset in brightness function later (255 max)

CRGB BacklightLEDs[NUMPIXELS];  // Memory array for the fastLED function


//  Some extra bits for testing
DcsBios::LED masterCaution(0x1012, 0x0800, 13);  // Master caution light
DcsBios::Switch2Pos ufcMasterCaution("UFC_MASTER_CAUTION", 10); // Master caution reset



//  This section determines which control the backlight LEDs respond to
void onLcpConsoleChange(unsigned int newValue) {

   backlightBrightness = map(newValue,0, 65535, 0, 255); // Change 16-bit input to 8-bit for FastLED brightness function

// For test purposes (as I'm using a 4-line display for testing)
   lcd.setCursor(0,3);  // set cursor position (column,line) starting at 0
   lcd.print("Pnl BL Brt ctrl ");
   lcd.print(backlightBrightness);  // Control position
   lcd.print(" ");                  // Trailing spaces to clear the line
// End of test display

LEDbacklight(backlightBrightness); // Run the lighting routine

}
DcsBios::IntegerBuffer lcpConsoleBuffer(0x1150, 0xffff, 0, onLcpConsoleChange);

// End of backlight control section

// This setion reads the CMS display strings and sends them to the LCD

void onCmsp1Change(char* newValue) {
 lcd.setCursor(0,0);  // set cursor position (column,line) starting at 0
 lcd.print(newValue);  // Write the line to the display
}
DcsBios::StringBuffer<19> cmsp1Buffer(0x1000, onCmsp1Change);

void onCmsp2Change(char* newValue) {
 lcd.setCursor(0,1);  // set cursor position (column,line) starting at 0
 lcd.print(newValue);  // Write the line to the display
}
DcsBios::StringBuffer<19> cmsp2Buffer(0x1014, onCmsp2Change);

// End of CMS display string section

// This function checks if the power is on to enable the backlight brightness control to work
// Currently using the Angle of Attack gauge power flag as it changes state with the lighting power

bool power_is_off;     //  Power on/off flag

void onAoaPwroffChange(bool newValue) {
power_is_off = newValue;

// For test purposes (as I'm using a 4-line display for testing)
   lcd.setCursor(0,2);  // set cursor position (column,line) starting at 0
   lcd.print("AoA power flag ");
   lcd.print(power_is_off);  // flag value
   lcd.print("  ");                  // Trailing spaces to clear the line
// End of test display

LEDbacklight(backlightBrightness); // Run the lighting routine

}
DcsBios::IntegerBuffer aoaPwroffBuffer(0x1076, 0xffff, 0, onAoaPwroffChange);
// End of backlight enable section

// Backlight brightness and on/off output
// This was made separate to allow the power on/off setup to work properly

void LEDbacklight(unsigned int newValue) { //  LED backlight brightness control

if (power_is_off == false){    // check if power is on
   FastLED.setBrightness(newValue);  // Set the new level
   FastLED.show();                              // Send it to the LEDs
}
else {
   FastLED.setBrightness(0);                    // Set the LEDs off
   FastLED.show();                              // Send it to the LEDs
}

}
// End of backlight brightness and on/off output

void setup() {
 DcsBios::setup();

//I2C LCD initialisation
 lcd.init();                      // initialize the lcd 
 lcd.backlight();                  // Trun on the LCD backlight
 lcd.setCursor(0,0);  // set LCD cursor position (column,line) starting at 0
 lcd.print("Display online");
 lcd.setCursor(0,1);  // set LCD cursor position (column,line) starting at 0
 lcd.print("Awaiting DCS");

// Backlight LED initialisation
 FastLED.addLeds<NEOPIXEL, BACKLIGHTPIN>(BacklightLEDs, NUMPIXELS);  // Set up LED strip parameters

 FastLED.setBrightness(backlightBrightness);   // Set strip initial master brightness

 fill_solid( BacklightLEDs, NUMPIXELS, CRGB::Green); // Fill strip with green - CRGB(0,255,0) also works

 BacklightLEDs[0] = CRGB::Red; // Set 1st led as red - because why not?

 FastLED.show();  // Send LED changes to the strip

}

void loop() {
 DcsBios::loop();

}

It's not pretty, but it's commented and it works.

 

Changing the .lua may make the code more efficient, but I don't know if that'll cause issues with MP servers, etc.

Link to comment
Share on other sites

Whatever works for you :thumbup:

 

To clarify, I was referring to your A10C.lua module in DCS BIOS (\Scripts\DCS-BIOS\lib\A10C.lua) - changing that will not affect MP. DCS BIOS is an add on script in the first place.

 

I see they have added similar cockpit outputs to the Hornet module in the dcs-flightpanels branch of DCS-BIOS (though as an IndicatorLight function). They must not have gotten around to put it in for the Warthog yet.

Link to comment
Share on other sites

I look what I find in the luas to cover these outputs.

 

Check out \DCS World\Mods\aircraft\A-10C\Cockpit\Scripts\LightSystem\LightSystem.lua

Thanks.

 

What would reduce the Arduino code considerably would be if the actual backlight levels were output.

Then it would simply be a case of using one of those "onchange" functions to set the brightness, which would include off.

That would eliminate reading the control and then checking if the lights should be on or off.

 

And it would probably be useful for more than just the A10.

Link to comment
Share on other sites

Thanks.

 

What would reduce the Arduino code considerably would be if the actual backlight levels were output.

Then it would simply be a case of using one of those "onchange" functions to set the brightness, which would include off.

That would eliminate reading the control and then checking if the lights should be on or off.

 

And it would probably be useful for more than just the A10.

 

Yes, this is exactly what the new output does :) It is the actual backlight intensity parameter in the A10. So if you cut electrical power in the jet it goes to 0, even if console lights knob is set differently.

Link to comment
Share on other sites

To clarify, I was referring to your A10C.lua module in DCS BIOS (\Scripts\DCS-BIOS\lib\A10C.lua) - changing that will not affect MP. DCS BIOS is an add on script in the first place.

 

I don't seem to have that file.

I'm using the hub version of DCS-BIOS.

Link to comment
Share on other sites

in our fork (master branch) it is integraded (link in sig)

 

hub version will upgraded in near future. Some tests are running fore some other problems.

 

edit: Hub is updated too


Edited by BlackLibrary
Link to comment
Share on other sites

  • 2 months later...

@BlackLibrary: Thank you. So, if I understand correctly these variables will take all things that influence the different lighting channels into account. This means if the lights are off for whatever reason (batt switch off, ...) they will be off regardless of the position of the brightness dial, correct?

 

Can it be that you have a minor copy/paste error in the A-10C.lua file?

 

defineFloat("INT_FLOOD_L_BRIGHT", 806, {0, 1}, [color="yellow"]"Light System Control Panel", "Flood Light Brightness"[/color])
defineFloat("INT_CAUTION_L_BRIGHT", 905, {0, 1}, [color="Yellow"]"Light System Control Panel", "Flood Light Brightness"[/color])

 

Regards,

 

Rusti

Link to comment
Share on other sites

  • 1 year later...
On 5/14/2020 at 8:35 AM, DeadMeat said:

No need for workarounds. You can just use the actual output parameter for the console lights (and the other cockpit lights if you'd like).

 

You need to add it yourself to the A10C.lua though. Put this at the end of the file, just above "BIOS.protocol.endModule()" to avoid changing the addresses of the other functions:

 

defineFloat("INTERNAL_CONSOLE_LIGHTS", 800, {0, 1}, "zAdditional Parameters", "Console Lights")
defineFloat("INTERNAL_ENG_INST_LIGHTS", 801, {0, 1}, "zAdditional Parameters", "Engine Instrument Lights")
defineFloat("INTERNAL_FLT_INST_LIGHTS", 802, {0, 1}, "zAdditional Parameters", "Flight Instruments Lights")
defineFloat("INTERNAL_AUX_INST_LIGHTS", 803, {0, 1}, "zAdditional Parameters", "Auxiliary Instruments Lights")
defineFloat("INTERNAL_FLOOD_LIGHTS", 806, {0, 1}, "zAdditional Parameters", "Flood Lights")

 

 

Run a mission and your control reference should have the new outputs that you can remap to the PWM for your LED strip or whatever.

You can give the group of outputs another name than "zAdditional Parameters", if you'd like.

Is this possible for the Fa18 as well??  

Win11 64bit, AMD Ryzen 58003DX, GeForce 3070 8GB, 2TB SSD, 64GB DDR4 RAM at 3200MHz _ full 1:1 FA-18C Cockpit https://www.youtube.com/@TheHornetProject

Link to comment
Share on other sites

On 10/18/2021 at 10:09 AM, Sting57 said:

Is this possible for the Fa18 as well??  

Short answer - yes.

EDIT

DCS flighpanels branch was updated. Refer to my next post for an example of how to use the new outputs.


Edited by DeadMeat
Info no longer valid
Link to comment
Share on other sites

Ok thank you for replying.  I have updated the lua as you suggested.  My code in sketch is simply

#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

DcsBios::LED consoleIntLt(0x74d4, 0x2000, 6);
/* paste code snippets from the reference documentation here */

void setup() {
  DcsBios::setup();
}

void loop() {
  DcsBios::loop();
}

using pin 6 as it is a pwm pin.

 

now the light does not even come on, so i am obviously missing some steps here  (sorry n00b) 

 

 

Not sure what you mean here:

 

. So read this afterwards and map to your output:

void onConsolesDimmerChange(unsigned int newValue) {
    /* your code here */
}
DcsBios::IntegerBuffer consolesDimmerBuffer(0x7544, 0xffff, 0, onConsolesDimmerChange);

or here?

Map to your PWM range and you're good to go.

 

 

 

 


Edited by Sting57

Win11 64bit, AMD Ryzen 58003DX, GeForce 3070 8GB, 2TB SSD, 64GB DDR4 RAM at 3200MHz _ full 1:1 FA-18C Cockpit https://www.youtube.com/@TheHornetProject

Link to comment
Share on other sites

Don't worry, it's not easy at first.

First thing - when you change your lua, you need to start a mission (any) all the way into the cockpit. This updates your reference documentation automatically, allowing you to paste the correct code snippets into your Arduino sketch.

Next, quit back to main menu and load up the reference doc. Go into advanced view which will give you multiple code snippets for each switch and light allowing you to do various things. This how mine looks:

73mRbwJ.png

Grab the code I highlighted (or the one that looks most like it) and put into your sketch. We will now have the raw value available for the intensity of the actual backlight in the sim. It runs from 0 (off) to 65535 (max). The PWM output needs to be in a range from 0-255 however, so we just need to re-map the data into a usable range with the handy "map" function. I declared a new variable at the top of the sketch for this purpose and then did the re-mapping as you can see below:

Spoiler

unsigned int ConsolesIntensity = 0; //consoles lights intensity

#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

/* paste code snippets from the reference documentation here */

void onIntConsoleLightChange(unsigned int newValue) {
    ConsolesIntensity = map(newValue, 0, 65535, 0 , 255);
    analogWrite(6, ConsolesIntensity);

}
DcsBios::IntegerBuffer intConsoleLightBuffer(0x5550, 0xffff, 0, onIntConsoleLightChange);


void setup() {
  DcsBios::setup();
}

void loop() {
  DcsBios::loop();
}

Note that you will have to re-create the code with copy+paste from your own reference documentation, since I use a modified library. Yours will likely have slightly different names and addresses (highlighted in red), but I hope you get the idea 🙂

For extra credit, you can play with map function to cap the upper limit if you find it gets too bright (just set it to 180 for example), or you might even want to break it into segments to have a more gradual ramp-up, like so:

Spoiler

void onIntConsoleLightChange(unsigned int newValue) {
    if (newValue < 32000) {
      ConsolesIntensity = map(newValue, 0, 31999, 0 , 50);  //slower kick-in to match sim
    }
    
    else {
      ConsolesIntensity = map(newValue, 32000, 65535, 50 , 180); //output capped to lower max brightness
    }
    analogWrite(10, ConsolesIntensity);
}
DcsBios::IntegerBuffer intConsoleLightBuffer(0x5550, 0xffff, 0, onIntConsoleLightChange);

 

Link to comment
Share on other sites

2 hours ago, BlackLibrary said:
defineFloat("CONSOLE_INT_LT", 460, {0, 1}, "Internal Lights", "Console Lightning (light green)")

will be (light renamed) integraded in F-18 for BIOS fork

Cheers. Recommend you change the rest of the indicators in that block as well, except 

CMSD_JET_SEL_L
EMERG_INSTR_INT_LT
ENG_INSTR_INT_LT

They're just off or full on so might as well leave them as defineIndicatorLight


Edited by DeadMeat
Link to comment
Share on other sites

It's working 🙂 Anybody reading the my instructions above - you can now just use the latest version. No need to change the F18 lua yourself. The sketch example I provided for inspiration still applies though if you want to use the new outputs.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...