Jump to content

Recommended Posts

Posted (edited)

Hi all,

First off, I apologize if these questions have been answered elsewhere.

Running into a couple of problems coding the IFF panel.

1st is with the Reply and Test LED's I am using 3.3v LED's + connected to the Arduino 3.3v and the - connected to the signal PIN.

//IFF REPLY Light (green) LED OUTPUT
DcsBios::LED iffReply(0x12d2, 0x0002, 37);

//IFF TEST Light (green) LED OUTPUT
DcsBios::LED iffTest(0x12d2, 0x0004, 39);

Problem is the LED's are constantly on.

 

2nd,

Is there a way to code the //IFF Code: ZERO - B - A - (HOLD) same way as the 
//IFF Master: OFF - STBY - LOW - NORM - EMER
const byte iffMasterPins[9] = {PIN_0, PIN_1, PIN_2, PIN_3, PIN_4}
DcsBios::SwitchMultiPos iffMaster("IFF_MASTER", iffMasterPins, 9);

Lastly,

I'm using these wheel switchs from PC Flights
 Pushwheel Decimal Switch - 4 Port 10 Positions

Along with the following code. Does not seem to be working correctly. Two clicks for every change in game. Am i doing something wrong?


//Mode-3A Wheel 1 ROTARY ENCODER
const byte iffMode3aWheel1Pins[3] = {54, 55, 56};
DcsBios::SwitchMultiPos iffMode3aWheel1("IFF_MODE3A_WHEEL1", iffMode3aWheel1Pins, 3);

//Mode-3A Wheel 2 ROTARY ENCODER
const byte iffMode3aWheel2Pins[3] = {60, 59, 58};
DcsBios::SwitchMultiPos iffMode3aWheel2("IFF_MODE3A_WHEEL2", iffMode3aWheel2Pins, 3);

//Mode-3A Wheel 3 ROTARY ENCODER
const byte iffMode3aWheel3Pins[3] = {63, 64, 65};
DcsBios::SwitchMultiPos iffMode3aWheel3("IFF_MODE3A_WHEEL3", iffMode3aWheel3Pins, 3);

//Mode-3A Wheel 4 ROTARY ENCODER
const byte iffMode3aWheel4Pins[3] = {66, 67, 68};
DcsBios::SwitchMultiPos iffMode3aWheel4("IFF_MODE3A_WHEEL4", iffMode3aWheel4Pins, 3);
 

 

 

20221030_134930.jpg

 

Thank you all in advance!

Bob

Edited by byteman59
Posted

Hi Bob,

 

Try the following snipped for the ZERO - B - A - (HOLD) switch

const byte iffCodePins[4] = {PIN_0, PIN_1, PIN_2, PIN_3}
DcsBios::SwitchMultiPos iffCode("IFF_CODE", iffCodePins, 9);

For the wheels, see Les's above post.

 

Regards, Vinc

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted
Just now, Vinc_Vega said:

Hi Bob,

 

Try the following snipped for the ZERO - B - A - (HOLD) switch

const byte iffCodePins[4] = {PIN_0, PIN_1, PIN_2, PIN_3}
DcsBios::SwitchMultiPos iffCode("IFF_CODE", iffCodePins, 9);

For the wheels, see Les's above post.

 

Regards, Vinc

Will do, thanks Les! 

Will post results.

Posted (edited)

BCD means "binary coded decimal", so the object already converts signals from the connected pins to decimal outputs (0 to 10), or in the IFF case 0 to 7.

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted
3 minutes ago, Vinc_Vega said:

BCD means "binary coded decimal", so the object already converts signals from the connected pins to decimal outputs (0 to 10), or in the IFF case 0 to 7.

 

I see, which should i be using for the Thumb wheels? Control References do not mention SwitchMultiPosBCD.

Posted (edited)

Yes, that class is not part of the Control Reference but is the right one for thumb wheel kind switches with BCD output. For the code and more explanation on that, please read the discussion linked above.

Edit: FSFIan is the author of DCS-BIOS and intruduced the SwitchMultiPosBCD in that posting.

 

Regards, Vinc

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted

You'r welcome Sir!

If you want to know how the signals are combined to make decimals, have a look at PC Flight's description of the switches.

Here "C" is the common ground (GND) and 1 to 8 are the switch pins. As you only need at max 3 bits for the IFF (you can dial only from 0 to 7), pins 1, 2 and 4 have to be connected to the arduino.

Regards, Vinc

tumbwheel_switch_quad_02-800x600.jpg

tumbwheel_switch_quad_01-800x600.jpg

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted
35 minutes ago, Vinc_Vega said:

You'r welcome Sir!

If you want to know how the signals are combined to make decimals, have a look at PC Flight's description of the switches.

Here "C" is the common ground (GND) and 1 to 8 are the switch pins. As you only need at max 3 bits for the IFF (you can dial only from 0 to 7), pins 1, 2 and 4 have to be connected to the arduino.

Regards, Vinc

tumbwheel_switch_quad_02-800x600.jpg

tumbwheel_switch_quad_01-800x600.jpg

Yes, have that. 

Thanks Vinc

Posted

Getting an error when compiling the code.

*****************************************************
IFF_PANEL:85:10: error: 'SwitchMultiPosBCD' in namespace 'DcsBios' does not name a type

 DcsBios::SwitchMultiPosBCD iffMode3aWheel4("IFF_MODE3A_WHEEL4", iffMode3aWheel4Pins, 3);
******************************************************

 

Posted (edited)

Hi Bob,

did you put in the namespace declaration for the SwitchMultiPosBCD before calling the DCSBios:: statements?

#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

namespace DcsBios {
   class SwitchMultiPosBCD : PollingInput {
   private:
     const char* msg_;
     const byte* pins_;
     char numberOfPins_;
     char lastState_;
 
     char readState() {
       unsigned char i;
       unsigned char state = 0;
       for (i=0; i<numberOfPins_; i++) {
         unsigned char j = numberOfPins_ - i - 1;
//     state |= (digitalRead(pins_[i]) << j);
       state |= ((digitalRead(pins_[i]) ^ 1) << j); // to invert logic
       }
       return state;
     }

     void pollInput() {
       char state = readState();
       if (state != lastState_) {
         char buf[7];
         utoa(state, buf, 10);
         if (tryToSendDcsBiosMessage(msg_, buf))
           lastState_ = state;
       }
     }
   public:
     SwitchMultiPosBCD(const char* msg, const byte* pins, char numberOfPins) : lastState_(0) {
       msg_ = msg;
       pins_ = pins;
       numberOfPins_ = numberOfPins;
       unsigned char i;
       for (i=0; i<numberOfPins; i++) {
         pinMode(pins[i], INPUT_PULLUP);
       }
       lastState_ = readState();
     }
 };
}

const byte iffMode1Wheel1Pins[4] = {5, 6, 7, 8};
DcsBios::SwitchMultiPosBCD iffMode1Wheel1("IFF_MODE1_WHEEL1", iffMode1Wheel1Pins, 4);

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

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

 

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted (edited)

Hi Bob,

 

As already stated, you don't have to connect all 4 switch pins to the arduino.

If you push the respective thumb wheels in the cockpit you'll see, that they only can be turned from 0 to 7 (3 bit).

The second Mode 1 wheel is turnable from 0 to 3 (2 bit).

 

Therefore for the most wheels the code snippets could read as follows:

const byte iffMode1Wheel1Pins[3] = {A14, 32, 34}; // tree bit (0 - 7)
DcsBios::SwitchMultiPosBCD iffMode1Wheel1("IFF_MODE1_WHEEL1", iffMode1Wheel1Pins, 3);

and for Mode1 Wheel2 you need to connect only 2 pins:

const byte iffMode1Wheel2Pins[2] = {A15, 33}; // only two bit (0 - 3)
DcsBios::SwitchMultiPosBCD iffMode1Wheel2("IFF_MODE1_WHEEL2", iffMode1Wheel2Pins, 2);

 

Regards, Vinc

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted (edited)

Sorry, did not add that code. Should any changes be made to that code or add as is?

 

 

7 minutes ago, Vinc_Vega said:

Hi Bob,

 

As already stated, you don't have to connect all 4 switch pins to the arduino.

If you push the respective thumb wheels in the cockpit you'll see, that they only can be turned from 0 to 7 (3 bit).

The second Mode 1 wheel is turnable from 0 to 3 (2 bit).

 

Therefore for the most wheels the code snippets could read as follows:

const byte iffMode1Wheel1Pins[3] = {A14, 32, 34}; // tree bit (0 - 7)
DcsBios::SwitchMultiPosBCD iffMode1Wheel1("IFF_MODE1_WHEEL1", iffMode1Wheel1Pins, 3);

and for Mode1 Wheel2 you need to connect only 2 pins:

const byte iffMode1Wheel2Pins[2] = {A15, 33}; // only two bit (0 - 3)
DcsBios::SwitchMultiPosBCD iffMode1Wheel2("IFF_MODE1_WHEEL2", iffMode1Wheel2Pins, 2);

 

Regards, Vinc

 

As for recent post, Yes, i understood that part, thanks. Only using 3 or 2 pins.

Edited by byteman59
Posted (edited)

Yes Bob,

you have to put your pin numbers within the curly brackets  😉

The line regarding the "invert logic" has to be observed. Just change if the wheels turn strange.

Regards, Vinc

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted

The code you posted is failing with my pins 
                


exit status 1
no matching function for call to 'DcsBios::PollingInput::PollingInput()'


 

 

 

#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

namespace DcsBios {
   class SwitchMultiPosBCD : PollingInput {
   private:
     const char* msg_;
     const byte* pins_;
     char numberOfPins_;
     char lastState_;
 
     char readState() {
       unsigned char i;
       unsigned char state = 0;
       for (i=0; i<numberOfPins_; i++) {
         unsigned char j = numberOfPins_ - i - 1;
//     state |= (digitalRead(pins_[i]) << j);
       state |= ((digitalRead(pins_[i]) ^ 1) << j); // to invert logic
       }
       return state;
     }

     void pollInput() {
       char state = readState();
       if (state != lastState_) {
         char buf[7];
         utoa(state, buf, 10);
         if (tryToSendDcsBiosMessage(msg_, buf))
           lastState_ = state;
       }
     }
   public:
     SwitchMultiPosBCD(const char* msg, const byte* pins, char numberOfPins) : lastState_(0) {
       msg_ = msg;
       pins_ = pins;
       numberOfPins_ = numberOfPins;
       unsigned char i;
       for (i=0; i<numberOfPins; i++) {
         pinMode(pins[i], INPUT_PULLUP);
       }
       lastState_ = readState();
     }
 };
}

const byte iffMode1Wheel1Pins[4] = {30, 31, 32 33};
DcsBios::SwitchMultiPosBCD iffMode1Wheel1("IFF_MODE1_WHEEL1", iffMode1Wheel1Pins, 4);

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

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

 

Posted (edited)

hmm, my desktop shows correctly. never the less, same error.

null

image.png

#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

namespace DcsBios {
   class SwitchMultiPosBCD : PollingInput {
   private:
     const char* msg_;
     const byte* pins_;
     char numberOfPins_;
     char lastState_;
 
     char readState() {
       unsigned char i;
       unsigned char state = 0;
       for (i=0; i<numberOfPins_; i++) {
         unsigned char j = numberOfPins_ - i - 1;
//     state |= (digitalRead(pins_[i]) << j);
       state |= ((digitalRead(pins_[i]) ^ 1) << j); // to invert logic
       }
       return state;
     }

     void pollInput() {
       char state = readState();
       if (state != lastState_) {
         char buf[7];
         utoa(state, buf, 10);
         if (tryToSendDcsBiosMessage(msg_, buf))
           lastState_ = state;
       }
     }
   public:
     SwitchMultiPosBCD(const char* msg, const byte* pins, char numberOfPins) : lastState_(0) {
       msg_ = msg;
       pins_ = pins;
       numberOfPins_ = numberOfPins;
       unsigned char i;
       for (i=0; i<numberOfPins; i++) {
         pinMode(pins[i], INPUT_PULLUP);
       }
       lastState_ = readState();
     }
 };
}

const byte iffMode1Wheel1Pins[4] = {30,31,32,33};
DcsBios::SwitchMultiPosBCD iffMode1Wheel1("IFF_MODE1_WHEEL1", iffMode1Wheel1Pins, 4);

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

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

 

Edited by byteman59
Posted

Sorry, can't help.

I use the original DCS-Bios version (not the Flightpanel's) and don't get any compilation errors.

Even not with an original and unmodified Switches.h file.

 

What version of DCS-Bios and what kind of Arduino board do you use?

 

Regards, Vinc

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted

Able to resolve Test and Reply LED and the CODE Rotary Switch to work. Below is my sketch.

Still having issues with the thumb wheels.  will go over the suggested post again and see if i can't figure this out.

Thank you all!

 

#define DCSBIOS_IRQ_SERIAL
#include "DcsBios.h"
#include <timer.h>
Timer tm;

int Code_dial_ingame = 1; // hold value from DCS

//Define the inputs for rotary switch
const int code_zero = 49;
const int code_B = 47;
const int code_A = 45;
const int code_hold = 43;

//IFF Code: ZERO - B - A - (HOLD)
void onIffCodeChange(unsigned int newValue_Code) {
 Code_dial_ingame = newValue_Code;
}
DcsBios::IntegerBuffer iffCodeBuffer(0x111a, 0xc000, 14, onIffCodeChange);


//IFF Master: OFF - STBY - LOW - NORM - EMER   ROTARY ENCODER
const byte iffMasterPins[5] = {34, 36, 38, 40, 42};
DcsBios::SwitchMultiPos iffMaster("IFF_MASTER", iffMasterPins, 5);


//IFF On/Out TOGGLE ON OFF
DcsBios::Switch2Pos iffOnOut("IFF_ON_OUT", 52);

//IFF Out: LIGHT - OFF - AUDIO TOGGLE ON OFF ON
DcsBios::Switch3Pos iffOutAudioLight("IFF_OUT_AUDIO_LIGHT", 32, 33);

//REPLY Push to Test PUSH BUTTON
DcsBios::Switch2Pos iffReplyTest("IFF_REPLY_TEST", 41);

//IFF REPLY Light (green) LED OUTPUT
void onIffReplyTestChange(unsigned int newValue) {
     if (newValue == 1) {
    digitalWrite(37,LOW);
  }
  else {
    digitalWrite(37,HIGH);
  } /* your code here */
}
DcsBios::IntegerBuffer iffReplyTestBuffer(0x1128, 0x8000, 15, onIffReplyTestChange);


//TEST Push to Test PUSH BUTTON
DcsBios::Switch2Pos iffTestTest("IFF_TEST_TEST", 35);

//IFF TEST Light (green) LED OUTPUT
void onIffTestTestChange(unsigned int newValue) {
   if (newValue == 1) {
    digitalWrite(39,LOW);
  }
  else {
    digitalWrite(39,HIGH);
  } /* your code here */
}
DcsBios::IntegerBuffer iffTestTestBuffer(0x112a, 0x0040, 6, onIffTestTestChange);

//Mode-1 Wheel 1 ROTARY ENCODER
const byte iffMode1Wheel1Pins[3] = {25, 26, 27};
DcsBios::SwitchMultiPos iffMode1Wheel1("IFF_MODE1_WHEEL1", iffMode1Wheel1Pins, 3);

//Mode-1 Wheel 2 ROTARY ENCODER
const byte iffMode1Wheel2Pins[2] = {23, 24};
DcsBios::SwitchMultiPos iffMode1Wheel2("IFF_MODE1_WHEEL2", iffMode1Wheel2Pins, 2);

//Mode-3A Wheel 1 ROTARY ENCODER
const byte iffMode3aWheel1Pins[3] = {54, 55, 56};
DcsBios::SwitchMultiPos iffMode3aWheel1("IFF_MODE3A_WHEEL1", iffMode3aWheel1Pins, 3);

//Mode-3A Wheel 2 ROTARY ENCODER
const byte iffMode3aWheel2Pins[3] = {60, 59, 58};
DcsBios::SwitchMultiPos iffMode3aWheel2("IFF_MODE3A_WHEEL2", iffMode3aWheel2Pins, 3);

//Mode-3A Wheel 3 ROTARY ENCODER
const byte iffMode3aWheel3Pins[3] = {63, 64, 65};
DcsBios::SwitchMultiPos iffMode3aWheel3("IFF_MODE3A_WHEEL3", iffMode3aWheel3Pins, 3);

//Mode-3A Wheel 4 ROTARY ENCODER
const byte iffMode3aWheel4Pins[3] = {66, 67, 68};
DcsBios::SwitchMultiPos iffMode3aWheel4("IFF_MODE3A_WHEEL4", iffMode3aWheel4Pins, 3);

//Test M-1 TOGGLE OFF-ON-ON
DcsBios::Switch3Pos iffTestM1("IFF_TEST_M1", 50, 48);

//Test M-2 OFF-ON-ON
DcsBios::Switch3Pos iffTestM2("IFF_TEST_M2", 51, 53);

//Test M-3 OFF-ON-ON
DcsBios::Switch3Pos iffTestM3("IFF_TEST_M3", 30, 31);

//Test M-4 OFF-ON-ON
DcsBios::Switch3Pos iffTestM4("IFF_TEST_M4", 28, 29);

//RAD Test/Mon TOGGLE ON-OFF-ON
DcsBios::Switch3Pos iffRadtest("IFF_RADTEST", 44, 46);

//Ident/Mic TOGGLE ON-OFF-ON
DcsBios::Switch3Pos iffMicIdent("IFF_MIC_IDENT", 18, 19);

void setup() {
  DcsBios::setup();
  
 // Reversing for LED lights on Reply and Test LED
 pinMode(39, OUTPUT);
 pinMode(37, OUTPUT);

 // CODE ROTARY SWITCH
 pinMode(code_zero, INPUT_PULLUP);
 pinMode(code_B, INPUT_PULLUP);
 pinMode(code_A, INPUT_PULLUP);
 pinMode(code_hold, INPUT_PULLUP);
 tm.startTimer(200, setIFF);

}


int inputCode_dial()
{
 int valueCode_dial;
 if (digitalRead(code_zero) == LOW) {
   valueCode_dial = 0; //ZERO
 }
 if (digitalRead(code_B) == LOW) {
   valueCode_dial = 1; //B
 }
 if (digitalRead(code_A) == LOW) {
   valueCode_dial = 2; //A
 }
 if (digitalRead(code_hold) == LOW) {
   valueCode_dial = 3; //HOLD
 }
 return valueCode_dial;

}

  


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

 tm.runTimers();
}

void setIFF(int timer) {

 if (Code_dial_ingame < inputCode_dial()) {
   sendDcsBiosMessage("IFF_CODE", "INC");
 }

 if (Code_dial_ingame > inputCode_dial()) {
   sendDcsBiosMessage("IFF_CODE", "DEC");
 }

  
}

 

 

Posted (edited)

Hi Bob,

 

I use DCS-BIOS Version: v0.10.0+64, most files of the Library are from April 2019.

The A-10C II modul should be from October 2020.

Regards, Vinc

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

  • Recently Browsing   0 members

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