Jump to content

Little Problems interpreting exports from DCS-BIOS


Recommended Posts

Posted (edited)

Hello Friends.

I did an amazing progress in adopting and also understanding DCS-BIOS.

 

My MFDs (still a construction area) work like hell - including DCS-remote backlite).

 

Today I "cracked" the Fuel Quantity Selector.

Due to lack of space I decided to take a rotary encoder. Drawback of an encoder is, you have no feedback, where you are. Means, which state you have switched.

 

So I "invented" a feedback system wich uses 4 LEDs representing MAIN, WING, EXT WING and EXT CENTER tanks. Later will be there a small silhouette of the A10 were the LEDs placed at different Tanks positions.

By the way I found an error in german DCS A10C Manual on page 132. Function of Positions MAIN and INT are inverted. This made a little issue while coding my project.

 

My code works fine with a setback: The LEDs are not full fired. They smolder just at around 30 percent.

 

I think it's a matter of unclean C-coding. Cause the matter is so close to DCS-BIOS I place my problem here.

I would be so happy if one of you guys could risk an eye on my code.

Here it is. I commented almost every line. So it should be self explanating.

int fqisPin[] = {53, 51, 49, 47}; // all used OUTPUTS
int lastFqisPin = 0; // intitial data - last or actual value
...
// FuelQuantityIndicatorSelector by Encoder and 4 LEDs as feedback 	
/*	0: (all)INT      - Main and Wings - 0 and 1 are HIGH
1: MAIN     - MAIN Tank - 0 is HIGH
2: WING     - l/r WINGS - 1 is HIGH
3: EXT WING - l/r EXT Wing Tanks - 2 is HIGH
4: EXT CTR  - EXT CENTER Tank - 3 is HIGH					 */
if (address == 0x1106) { // FuelQuantityIndicatorSelector
unsigned int fqisSelectValue = (value & 0x1c00) >> 10;	// gives 0...4
if (fqisSelectValue != lastFqisPin){ // check for changed value
	for (int x = 0; x < 4; x++){ // loops all values
		if (x !=  fqisSelectValue){		// search for unused
			digitalWrite(fqisPin[x-1], LOW); // set unused Pins LOW
		}                     // x-1 cause of exception 0
		else {
			digitalWrite(fqisPin[x-1], HIGH); // set used Pin HIGH
		}
	}	
	if (fqisSelectValue == 0){ // exception 0: 2 Tanks are notified
		digitalWrite(fqisPin[0], HIGH); // MAIN
		digitalWrite(fqisPin[1], HIGH); // WINGS
	}
}
lastFqisPin = fqisPin[fqisSelectValue]; // set new old Value
}	

 

As an extra gift for Newcomers here my code for Backliting MFDs:

// Backlighting
if (address == 0x114c) { 
   unsigned int lcpAuxInstValue = (value & 0xffff) >> 0;
   analogWrite(PWM_Pin, lcpAuxInstValue/512); // adopt Output to Arduino-PWM-Scale
}	// end if

 

Note: I don't want to make the false impression, this code is made just by me!!! That all is based on Ian's great work. I can't stop say Thank You for that. Thank You.

Edited by Tekkx

Manual for my version of RS485-Hardware, contact: tekkx@dresi.de

Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.

Posted (edited)

This is the second time I answer my own question :)

 

After thinking and tinkering almost two days I found the solution.

 

My code above is OK.

Cause I am meanwhile a little spoiled of using Ian's (almost) ready-to-go solutions I forgot an important fact:

My

digitalWrite(fqisPin[xx], HIGH);

commands avoiding prebuilt DCS-BIOS functions.

So I forgot to make-up my OUTPUTs with

void setup() {
...
pinMode(fqisPin[xx], OUTPUT);
...
}

 

 

Each Output one line and everything is fine. :)

 

Thanx for watching :D

Edited by Tekkx

Manual for my version of RS485-Hardware, contact: tekkx@dresi.de

Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.

Posted

I think you want to change the last line of your code to the following:

 

lastFqisPin = fqisSelectValue;

 

The way it is written now, it does not properly check if the new value is different from the previous because you are storing the address and comparing it against the New index.

Posted (edited)

Welcome Spelmann.

 

Thank you for attentive reading my bullshit ;)

I'm right now not in the opportunity to check this out at the live object.

But practically it seems you are right.

 

That means, this line isn't really required. Cause it works very good as it is. Althow a change could take some load off the DCS-BIOS data stream...

 

I'll check this later.

 

PS (edit): I wonder if I don't get a notification of your Post. Subscription is ON...

 

Edit 2:

To be more consistent, I changed variable name lastFqisPin into lastFqisValue.

This way it makes a lot more sense and my fault is easy to recognize (especially to a beginner like me).

Edited by Tekkx

Manual for my version of RS485-Hardware, contact: tekkx@dresi.de

Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.

Posted (edited)

Here is the new - thanks to Spelmann - faultless code.

I tested it in a improvised Sim-Pit-Environment.

...

int fqisPin[] = {53, 51, 49, 47}; // all used OUTPUTS for FQIS
int lastFqisValue = 0; // intitial data - last or actual value

...

DcsBios::RotaryEncoder fqisSelect("FQIS_SELECT", "DEC", "INC", 39, 41);
DcsBios::Switch2Pos fqisTest("FQIS_TEST", 43); // Push-Button of Rotary

...

void setup() {

...

for (int x = 0; x < 5; x++){ // that's, what I've learned, IS important :)
	pinMode(fqisPin[x], OUTPUT);
}

...

}

...

void onDcsBiosWrite(unsigned int address, unsigned int value) { 

...

// FuelQuantityIndicatorSelector by Encoder and 4 LEDs as feedback 	
/*	0: (all)INT      - Main and Wings - 0 and 1 are HIGH
1: MAIN     - MAIN Tank - 0 is HIGH
2: WING     - l/r WINGS - 1 is HIGH
3: EXT WING - l/r EXT Wing Tanks - 2 is HIGH
4: EXT CTR  - EXT CENTER Tank - 3 is HIGH		*/
if (address == 0x1106) { // FuelQuantityIndicatorSelector
unsigned int fqisSelectValue = (value & 0x1c00) >> 10;	// gives 0...4
if (fqisSelectValue != lastFqisValue){ // check for changed value
	for (int x = 0; x < 5; x++){ // loops all values
		if (x !=  fqisSelectValue){		// search for unused
			digitalWrite(fqisPin[x-1], LOW); // set unused Pins LOW
		}                     // x-1 cause of exception 0
		else {
			digitalWrite(fqisPin[x-1], HIGH); // set used Pin HIGH
		}
	}	
	if (fqisSelectValue == 0){ // exception 0: 2 Tanks are notified
		digitalWrite(fqisPin[0], HIGH); // MAIN
		digitalWrite(fqisPin[1], HIGH); // WINGS
	}
}
lastFqisValue = fqisSelectValue; // set new old Value
}	
} // end void onDcsBiosWrite

1950320896_2015-12-19FQISPCB.thumb.jpg.9db3342df223ed2a17ba5eb8b96774e4.jpg

Edited by Tekkx

Manual for my version of RS485-Hardware, contact: tekkx@dresi.de

Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.

  • Recently Browsing   0 members

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