Jump to content

[DCS-BIOS v0.5.5] IFF Panel Thumb wheel help


GSS Rain

Recommended Posts

The thumb wheels that I have for the IFF panel are BCD output type.

0000 = Display 0

0001 = Display 1

0010 = Display 2

0011 = Display 3

etc.

 

I was trying to write code to make the conversion. DCS-BIOS for thumb wheel is rotary switch. So I figure that a switch just returns a HIGH or a LOW. So I wanted to substitute a variable name for this. But some of my problems were if I have a variable name, how do I assign it the data type HIGH or LOW? The closest I saw was data type boolean. Needless to say, I tried different approaches but I can't even get it to hard code a value to display it.

 

I'm looking for the smart software guy to point me in the right direction to convert BCD to something I can insert into the SwitchMultiPos function and have it still work.

 

Thanks.

 

 

/*
IFF Panel
DCS-BIOS version 0.5.5
Arduino Mega
*/

#define DCSBIOS_IRQ_SERIAL
#include "DcsBios.h"

/* BCD IN = DATA SENT TO DCS-BIOS 
* 0000   = 10000000  FOR 0
* 0001   = 01000000  FOR 1
* 0010   = 00100000  FOR 2
* 0011   = 00010000  FOR 3
* 0100   = 00001000  FOR 4
* 0101   = 00000100  FOR 5
* 0110   = 00000010  FOR 6
* 0111   = 00000001  FOR 7
* 1000   = 00000001  FOR 7
* 1001   = 00000001  FOR 7
*/

// Define and initiallize output varable to DCS-BIOS
// Only one will be LOW at a given time, the rest are HIGH, just like a rotary switch.

// Thumbwheel 1
byte Wheel_1_0 = LOW;
byte Wheel_1_1 = HIGH;
byte Wheel_1_2 = HIGH;
byte Wheel_1_3 = HIGH;
byte Wheel_1_4 = HIGH;
byte Wheel_1_5 = HIGH;
byte Wheel_1_6 = HIGH;
byte Wheel_1_7 = HIGH;

// Thumbwheel 2
byte Wheel_2_0 = HIGH;
byte Wheel_2_1 = LOW;
byte Wheel_2_2 = HIGH;
byte Wheel_2_3 = HIGH;

// Thumbwheel 3
byte Wheel_3_0 = HIGH;
byte Wheel_3_1 = HIGH;
byte Wheel_3_2 = LOW;
byte Wheel_3_3 = HIGH;
byte Wheel_3_4 = HIGH;
byte Wheel_3_5 = HIGH;
byte Wheel_3_6 = HIGH;
byte Wheel_3_7 = HIGH;

// Thumbwheel 4
byte Wheel_4_0 = HIGH;
byte Wheel_4_1 = HIGH;
byte Wheel_4_2 = HIGH;
byte Wheel_4_3 = LOW;
byte Wheel_4_4 = HIGH;
byte Wheel_4_5 = HIGH;
byte Wheel_4_6 = HIGH;
byte Wheel_4_7 = HIGH;

// Thumbwheel 5
byte Wheel_5_0 = HIGH;
byte Wheel_5_1 = HIGH;
byte Wheel_5_2 = HIGH;
byte Wheel_5_3 = HIGH;
byte Wheel_5_4 = LOW;
byte Wheel_5_5 = HIGH;
byte Wheel_5_6 = HIGH;
byte Wheel_5_7 = HIGH;

// Thumbwheel 6
byte Wheel_6_0 = HIGH;
byte Wheel_6_1 = HIGH;
byte Wheel_6_2 = HIGH;
byte Wheel_6_3 = HIGH;
byte Wheel_6_4 = HIGH;
byte Wheel_6_5 = LOW;
byte Wheel_6_6 = HIGH;
byte Wheel_6_7 = HIGH;

void setup() {
 DcsBios::setup();
 pinMode (42, INPUT);  // BCD 1  WHEEL 1
 pinMode (43, INPUT);  // BCD 2  WHEEL 1
 pinMode (44, INPUT);  // BCD 4  WHEEL 1
 pinMode (45, INPUT);  // BCD 8  WHEEL 1
 pinMode (46, INPUT);  // BCD 1  WHEEL 2
 pinMode (47, INPUT);  // BCD 2  WHEEL 2
 pinMode (48, INPUT);  // BCD 4  WHEEL 2
 pinMode (49, INPUT);  // BCD 8  WHEEL 2
 pinMode (50, INPUT);  // BCD 1  WHEEL 3
 pinMode (51, INPUT);  // BCD 2  WHEEL 3
 pinMode (52, INPUT);  // BCD 4  WHEEL 3
 pinMode (53, INPUT);  // BCD 8  WHEEL 3
 pinMode (2, INPUT);   // BCD 1  WHEEL 4
 pinMode (3, INPUT);   // BCD 2  WHEEL 4
 pinMode (4, INPUT);   // BCD 4  WHEEL 4
 pinMode (5, INPUT);   // BCD 8  WHEEL 4
 pinMode (6, INPUT);   // BCD 1  WHEEL 5
 pinMode (7, INPUT);   // BCD 2  WHEEL 5
 pinMode (8, INPUT);   // BCD 4  WHEEL 5
 pinMode (9, INPUT);   // BCD 8  WHEEL 5
 pinMode (10, INPUT);  // BCD 1  WHEEL 6
 pinMode (11, INPUT);  // BCD 2  WHEEL 6
 pinMode (12, INPUT);  // BCD 4  WHEEL 6
 pinMode (13, INPUT);  // BCD 8  WHEEL 6
 digitalWrite(42, HIGH);  // Turn on pullup resistor
 digitalWrite(43, HIGH);  // Turn on pullup resistor
 digitalWrite(44, HIGH);  // Turn on pullup resistor
 digitalWrite(45, HIGH);  // Turn on pullup resistor
 digitalWrite(46, HIGH);  // Turn on pullup resistor
 digitalWrite(47, HIGH);  // Turn on pullup resistor
 digitalWrite(48, HIGH);  // Turn on pullup resistor
 digitalWrite(49, HIGH);  // Turn on pullup resistor  
 digitalWrite(50, HIGH);  // Turn on pullup resistor
 digitalWrite(51, HIGH);  // Turn on pullup resistor
 digitalWrite(52, HIGH);  // Turn on pullup resistor
 digitalWrite(53, HIGH);  // Turn on pullup resistor
 digitalWrite(2, HIGH);   // Turn on pullup resistor
 digitalWrite(3, HIGH);   // Turn on pullup resistor
 digitalWrite(4, HIGH);   // Turn on pullup resistor
 digitalWrite(5, HIGH);   // Turn on pullup resistor
 digitalWrite(6, HIGH);   // Turn on pullup resistor
 digitalWrite(7, HIGH);   // Turn on pullup resistor
 digitalWrite(8, HIGH);   // Turn on pullup resistor
 digitalWrite(9, HIGH);   // Turn on pullup resistor
 digitalWrite(10, HIGH);  // Turn on pullup resistor
 digitalWrite(11, HIGH);  // Turn on pullup resistor        
 digitalWrite(12, HIGH);  // Turn on pullup resistor  
 digitalWrite(13, HIGH);  // Turn on pullup resistor  
}


// IFF Code: ZERO - B - A - (HOLD)
// Need to find the right Grayhill mechanical encoder
// No code for regular rotary switch

// IFF Master: OFF - STBY - LOW - NORM - EMER
const byte iffMasterPins[5] = {22, 23, 24, 25, 26};
DcsBios::SwitchMultiPos iffMaster("IFF_MASTER", iffMasterPins, 5);

// IFF Out: LIGHT - OFF - AUDIO
DcsBios::Switch3Pos iffOutAudioLight("IFF_OUT_AUDIO_LIGHT", 27, 28);

// Test M-1
DcsBios::Switch3Pos iffTestM1("IFF_TEST_M1", 29, 30);

// Test M-2
DcsBios::Switch3Pos iffTestM2("IFF_TEST_M2", 31, 32);

// Test M-3
DcsBios::Switch3Pos iffTestM3("IFF_TEST_M3", 33, 34);

// Test M-4
DcsBios::Switch3Pos iffTestM4("IFF_TEST_M4", 35, 36);

// RAD Test/Mon
DcsBios::Switch3Pos iffRadtest("IFF_RADTEST", 37, 38);

// IFF On/Out
DcsBios::Switch2Pos iffOnOut("IFF_ON_OUT", 39);

// IFF MIC/IDENT (typo in Referecnce DOC, says RAD Test/Mon in bold on left side of page, but correct name on right side)
DcsBios::Switch3Pos iffMicIdent("IFF_MIC_IDENT", 40, 41);

// Mode-1 Wheel 1
// BCD in on pins 42, 43, 44, 45
const byte iffMode1Wheel1Pins[8] = {Wheel_1_0, Wheel_1_1, Wheel_1_2, Wheel_1_3, Wheel_1_4, Wheel_1_5, Wheel_1_6, Wheel_1_7};
DcsBios::SwitchMultiPos iffMode1Wheel1("IFF_MODE1_WHEEL1", iffMode1Wheel1Pins, 8);

// Mode-1 Wheel 2
// BCD in on pins 46, 47, 48, 49
const byte iffMode1Wheel2Pins[4] = {Wheel_2_0, Wheel_2_1, Wheel_2_2, Wheel_2_3};
DcsBios::SwitchMultiPos iffMode1Wheel2("IFF_MODE1_WHEEL2", iffMode1Wheel2Pins, 4);

// Mode-3A Wheel 1
// BCD in on pins 50, 51, 52, 53
const byte iffMode3aWheel1Pins[8] = {Wheel_3_0, Wheel_3_1, Wheel_3_2, Wheel_3_3, Wheel_3_4, Wheel_3_5, Wheel_3_6, Wheel_3_7};
DcsBios::SwitchMultiPos iffMode3aWheel1("IFF_MODE3A_WHEEL1", iffMode3aWheel1Pins, 8);

// Mode-3A Wheel 2
// BCD in on pins 2, 3, 4, 5
const byte iffMode3aWheel2Pins[8] = {Wheel_4_0, Wheel_4_1, Wheel_4_2, Wheel_4_3, Wheel_4_4, Wheel_4_5, Wheel_4_6, Wheel_4_7};
DcsBios::SwitchMultiPos iffMode3aWheel2("IFF_MODE3A_WHEEL2", iffMode3aWheel2Pins, 8);

// Mode-3A Wheel 3
// BCD in on pins 6, 7, 8, 9
const byte iffMode3aWheel3Pins[8] = {Wheel_5_0, Wheel_5_1, Wheel_5_2, Wheel_5_3, Wheel_5_4, Wheel_5_5, Wheel_5_6, Wheel_5_7};
DcsBios::SwitchMultiPos iffMode3aWheel3("IFF_MODE3A_WHEEL3", iffMode3aWheel3Pins, 8);

// Mode-3A Wheel 4
// BCD in on pins 10, 11, 12, 13
const byte iffMode3aWheel4Pins[8] = {Wheel_6_0, Wheel_6_1, Wheel_6_2, Wheel_6_3, Wheel_6_4, Wheel_6_5, Wheel_6_6, Wheel_6_7};
DcsBios::SwitchMultiPos iffMode3aWheel4("IFF_MODE3A_WHEEL4", iffMode3aWheel4Pins, 8);

/*
// REPLY Push to Test
DcsBios::Switch2Pos iffReplyTest("IFF_REPLY_TEST", PIN);
DcsBios::LED iffReplyTest(0x1128, 0x8000, PIN);

// TEST Push to Test
DcsBios::Switch2Pos iffTestTest("IFF_TEST_TEST", PIN);
DcsBios::LED iffTestTest(0x112a, 0x0040, PIN);
*/

void loop() {
 DcsBios::loop();
 if (digitalRead(45) == HIGH && digitalRead(44) == HIGH && digitalRead(43) == HIGH && digitalRead(42) == HIGH)
 {   Wheel_1_0 = LOW;   // Display 0
     Wheel_1_1 = HIGH;
     Wheel_1_2 = HIGH;
     Wheel_1_3 = HIGH;
     Wheel_1_4 = HIGH;   
     Wheel_1_5 = HIGH;
     Wheel_1_6 = HIGH;
     Wheel_1_7 = HIGH;
 }
 else if (digitalRead(45) == HIGH && digitalRead(44) == HIGH && digitalRead(43) == HIGH && digitalRead(42) == LOW)
 {   Wheel_1_0 = HIGH;   
     Wheel_1_1 = LOW;   // Display 1
     Wheel_1_2 = HIGH;
     Wheel_1_3 = HIGH;
     Wheel_1_4 = HIGH;   
     Wheel_1_5 = HIGH;
     Wheel_1_6 = HIGH;
     Wheel_1_7 = HIGH;
 }
 else if (digitalRead(45) == HIGH && digitalRead(44) == HIGH && digitalRead(43) == LOW && digitalRead(42) == HIGH)
 {   Wheel_1_0 = HIGH;   
     Wheel_1_1 = HIGH;
     Wheel_1_2 = LOW;   // Display 2
     Wheel_1_3 = HIGH;
     Wheel_1_4 = HIGH;   
     Wheel_1_5 = HIGH;
     Wheel_1_6 = HIGH;
     Wheel_1_7 = HIGH;
 }    
 else if (digitalRead(45) == HIGH && digitalRead(44) == HIGH && digitalRead(43) == LOW && digitalRead(42) == LOW)
 {   Wheel_1_0 = HIGH;   
     Wheel_1_1 = HIGH;
     Wheel_1_2 = HIGH;
     Wheel_1_3 = LOW;   // Display 3
     Wheel_1_4 = HIGH;   
     Wheel_1_5 = HIGH;
     Wheel_1_6 = HIGH;
     Wheel_1_7 = HIGH;
 }
 else if (digitalRead(45) == HIGH && digitalRead(44) == LOW && digitalRead(43) == HIGH && digitalRead(42) == HIGH)
 {   Wheel_1_0 = HIGH;   
     Wheel_1_1 = HIGH;
     Wheel_1_2 = HIGH;
     Wheel_1_3 = HIGH;
     Wheel_1_4 = LOW;   // Display 4   
     Wheel_1_5 = HIGH;
     Wheel_1_6 = HIGH;
     Wheel_1_7 = HIGH;
 }
 else if (digitalRead(45) == HIGH && digitalRead(44) == LOW && digitalRead(43) == HIGH && digitalRead(42) == LOW)
 {   Wheel_1_0 = HIGH;   
     Wheel_1_1 = HIGH;
     Wheel_1_2 = HIGH;
     Wheel_1_3 = HIGH;
     Wheel_1_4 = HIGH;   
     Wheel_1_5 = LOW;   // Display 5
     Wheel_1_6 = HIGH;
     Wheel_1_7 = HIGH;
 }
 else if (digitalRead(45) == HIGH && digitalRead(44) == LOW && digitalRead(43) == LOW && digitalRead(42) == HIGH)
 {   Wheel_1_0 = HIGH;   
     Wheel_1_1 = HIGH;
     Wheel_1_2 = HIGH;
     Wheel_1_3 = HIGH;
     Wheel_1_4 = HIGH;   
     Wheel_1_5 = HIGH;
     Wheel_1_6 = LOW;   // Display 6
     Wheel_1_7 = HIGH;
 }
 else if (digitalRead(45) == HIGH && digitalRead(44) == LOW && digitalRead(43) == LOW && digitalRead(42) == LOW)
 {   Wheel_1_0 = HIGH;   
     Wheel_1_1 = HIGH;
     Wheel_1_2 = HIGH;
     Wheel_1_3 = HIGH;
     Wheel_1_4 = HIGH;   
     Wheel_1_5 = HIGH;
     Wheel_1_6 = HIGH;
     Wheel_1_7 = LOW;   // Display 7
 }
 else if (digitalRead(45) == LOW && digitalRead(44) == HIGH && digitalRead(43) == HIGH && digitalRead(42) == HIGH)
 {   Wheel_1_0 = HIGH;   
     Wheel_1_1 = HIGH;
     Wheel_1_2 = HIGH;
     Wheel_1_3 = HIGH;
     Wheel_1_4 = HIGH;   
     Wheel_1_5 = HIGH;
     Wheel_1_6 = HIGH;
     Wheel_1_7 = LOW;   // Display 7
 }
 else if (digitalRead(45) == LOW && digitalRead(44) == HIGH && digitalRead(43) == HIGH && digitalRead(42) == LOW)
 {   Wheel_1_0 = HIGH;   
     Wheel_1_1 = HIGH;
     Wheel_1_2 = HIGH;
     Wheel_1_3 = HIGH;
     Wheel_1_4 = HIGH;   
     Wheel_1_5 = HIGH;
     Wheel_1_6 = HIGH;
     Wheel_1_7 = LOW;   // Display 7
 }
 else
 {
   // Do nothing
 }
}

Link to comment
Share on other sites

Try the following:

#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);
       }
       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();
}

 

Using the SwitchMultiPos class as a starting point, I wrote a SwitchMultiPosBCD class. All I had to change was the readState() method so it treats the pin numbers it is given as a BCD type input instead of "one pin per position".

 

The code I posted assumes that a BCD input is connected to pins 5, 6, 7 and 8, with 5 being the most significant bit and pin 8 being the least significant bit.

 

If a "1" bit means LOW in your setup instead of HIGH (in case your BCD output is not a digital output but a switch that pulls the Arduino pin to ground), you can change the readState() method so it inverts the input values it reads:

// before: state |= (digitalRead(pins_[i]) << j);
// after:
state |= ((digitalRead(pins_[i]) ^ 1) << j);

 

You can use the SwitchMultiPosBCD class just like SwitchMultiPos. If you copy from the control reference, make sure to get the length of the pin number array right in both locations (the definition of the array and the instantiation of SwitchMultiPosBCD in the line after that).

Link to comment
Share on other sites

That's awesome Ian. I'm not home at the moment but can't wait to try this new feature. When you think about it, that is a lot of devices DCS-BIOS covers. This puts major manufacturer's stuff in play like thumbwheels and Grayhill mechanical encoders. The possibilities are truly stunning.

Link to comment
Share on other sites

I'm not home at the moment but can't wait to try this new feature.

 

Technically, it's not a new feature. I simply defined the new class in the sketch itself without having to modify the DCS-BIOS Arduino Library. This is a great way to experiment with new functionality.

 

If this works for you, I'll consider documenting it and including it in a future release.

 

 

When you think about it, that is a lot of devices DCS-BIOS covers. This puts major manufacturer's stuff in play like thumbwheels and Grayhill mechanical encoders. The possibilities are truly stunning.

 

In general, if something can talk to a 3.3V or 5V Arduino board, you can use it with DCS-BIOS.

 

If it doesn't have a code snippet in the reference docs, you'll have to write a bit of code that reads your input device and translates that into DCS-BIOS commands, or use the generic IntegerBuffer / StringBuffer code snippet to get the data and control your indicator.

 

The great thing about the Arduino ecosystem is that in many cases, some of this work has already been done for you and someone has written an Arduino library to talk to your device. A good example are the dot matrix displays that some poeple use for the A-10C's CMSC and CMSP displays.

 

If something doesn't have a 3.3V or 5V digital interface, design a bit of circuitry to adapt it. In some cases, you can simply buy an existing breakout board.

 

If the ATMega controllers are too slow (e.g. large graphic displays), other Arduino-compatible boards with faster processors are available. Those will only work in DEFAULT_SERIAL mode, but on the other hand, they can mitigate the disadvantages of DEFAULT_SERIAL mode through sheer processing power and/or a bigger receive buffer. You won't be able to use those boards as a RS-485 slave, but I don't think a typical cockpit will need more than one or two of these, so this shouldn't be an issue.


Edited by [FSF]Ian
Link to comment
Share on other sites

Just finished some testing of the BCD code. It works great. Yes I had to use the inverted line. I just like the amount of detail you can do with DCS-BIOS. The simulator is really coming together. I have big plans for my IFF panel. Just wait and see. :-) Take care Ian.

 

Thanks.

Link to comment
Share on other sites

Yes, DCS-BIOS is looking good. There is a bug in DCS World I think. If you press the M-1, M-2, M-3, or M-4 switch up and hold it , the TEST light comes on as it should. But if you then press the push to test feature, the light turns off. In short, if the light is already on, pressing the push to test turns it off where it should just remain on. But that is minor.

 

There were a few minor isssues I saw with DCS-BIOS as well. For example, if I take my mouse and go in the game and press the Push to Test by clicking and hold, DCS-BIOS lights the indicator on the hardware panel which is normal and it matches the simulation. However, if I take the M-1 switch and press it up, the Test light in the game comes on, but the light on my panel does not. DCs-BIOS lights the light only when the Push to Test is active, but it doesn't light the light for the other conditions like the M-1 thru M4 switches and there was one more switch, I think the Auido/Out/Light switch. There was a few more things but when I get home I was going to write up a more detailed report on the IFF panel.

 

 

Say Hans, since you have the real IFF, I was wondering if you had a vernier calipers where you could tell me the dimensions of the rotary knobs. Like diameter of the circle, total knob hieght, and width of the grip part. Also the partnumber of the zero mode switch. I suspect it's a Grayhill mechanical encoder. Maybe 26 PTT series.

 

Thanks Hans.

Link to comment
Share on other sites

GSS Rain I have been unable to find the switches

 

KlssGvPl.jpg

 

put have following marking on them:

 

ZERO-B-A-HOLD:

Pull to get it into ZERO position.

HOLD position is springloaded back into A position

 

DAK261360-AF1

249-3171

36554

 

 

OFF-STBY-LOW-NORM-EMER:

Pull to get into OFF and EMER

 

DAK261361-AF3

249-3171

36555

 

You can see the lock arangement here

czAg1VAl.jpg

 

Knobs:

Base circle ø32x2mm

Total knob height 21mm

Grip part ø19x11mm

 

Just realised that the light is red so may be out of a helo. I'll try and take it apart over the weekend and send Deadman the switch numbers so he can include it in his total list :smilewink:

 

Cheers

Hans

Link to comment
Share on other sites

Thanks Hans. I tried google the part number with no luck. Maybe 36555 is the Cage code but it turns up as LITTELL F J MACHINE CO. Website was no help. I was going to mention this as one of the possible improvements for the IFF. That section of code doesn't list the multi switch type as an option. I'm not at my computer but I think it just listed an encoder type. Seeing that you can add those scripts on the fly like Ian did for the BCD, I was going to try and add it. My problem is I just have a regular rotary switch and was going to forgo the momentary in Hold position and the pull up to get to the zero position. My other option was to find the real switch which I was thinking was some kind of encoder. But it be nice that if you could pick regular multi switch for the zero A B Hold mode switch in DCS-BIOS.

Link to comment
Share on other sites

  • 4 years later...
Am 19.6.2017 um 11:58 schrieb FSFIan:

Try the following:

 

#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);
       }
       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();
}
 

 

 

Using the SwitchMultiPos class as a starting point, I wrote a SwitchMultiPosBCD class. All I had to change was the readState() method so it treats the pin numbers it is given as a BCD type input instead of "one pin per position".

 

The code I posted assumes that a BCD input is connected to pins 5, 6, 7 and 8, with 5 being the most significant bit and pin 8 being the least significant bit.

 

If a "1" bit means LOW in your setup instead of HIGH (in case your BCD output is not a digital output but a switch that pulls the Arduino pin to ground), you can change the readState() method so it inverts the input values it reads:

 

// before: state |= (digitalRead(pins_[i]) << j);
// after:
state |= ((digitalRead(pins_[i]) ^ 1) << j);
 

 

 

You can use the SwitchMultiPosBCD class just like SwitchMultiPos. If you copy from the control reference, make sure to get the length of the pin number array right in both locations (the definition of the array and the instantiation of SwitchMultiPosBCD in the line after that).

Hi,

Is this sketch compatible with the f-16C IFF-Panel and the Digitran thumbwheels?

 

Cheers

Markus

Link to comment
Share on other sites

Hi Markus,

 

If you have a rotary switch with 20 positions each with their individual pins you can use this 

const byte uhfPresetSelPins[21] = {PIN_0, PIN_1, PIN_2, PIN_3, PIN_4, PIN_5, PIN_6, PIN_7, PIN_8, PIN_9, PIN_10, PIN_11, PIN_12, PIN_13, PIN_14, PIN_15, PIN_16, PIN_17, PIN_18, PIN_19, PIN_20};
DcsBios::SwitchMultiPos uhfPresetSel("UHF_PRESET_SEL", uhfPresetSelPins, 21);

If you turn the switch from position 3 to position 4 then on SOCAT you should be able to see 

UHF_PRESET_SEL  4

If you turn it further to position 5 SOCAT should show you following;

UHF_PRESET_SEL  5

 

Note that this is being send a plain text

 

Similar to this example 

 

Now in the AN/ARC-164 example I didn't have a 20 position switch with individual pins for each position. Therefore by using sendDcsBiosMessage I can send the same plain text over SOCAT.

 

In my example I am looking at pin 29-22 for the combination from the preset selector. If pins 29-22 read the following B11111001, the the position is preset 3. If DCS is at another preset then using sendDcsBiosMessage the message to DCS to set preset no 3 with this code;

 if ( Preset() == 3){
   sendDcsBiosMessage("UHF_PRESET_SEL", "3");

 

On SOCAT you will see;

UHF_PRESET_SEL  3

which tells DCS to set preset no 3.

 

Hope this explains it a little bit.

 

Cheers

Hans

Link to comment
Share on other sites

  • 2 months later...

Hi all, Vinc kindly pointed me to this thread as I was working on my own version of it without being aware of this. I started a separate thread about making things like the IFF panel.

At the moment I have moved in to a house, but all my stuff is not due to get here until mid to late December, so I am having to work completely theoretically. This means I can't do the usual and go and physically try something. As a result please bear with me if I ask what appear to be rather stupid questions.

Looking at the above I believe I would repeat the this part of the sketch below for each selector wheel changing the iffModewheel1Pins statement to for example iffModewheel3Pins to reflect each wheel, and the pertinent pins.

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

That being the case, clearly we are looking at a total of 25 pins for the whole IFF set of six wheels, which means that a Nano is not going to be able to work with more than three wheels in practice. Is that correct? I have no issues using more than one Nano, or even an Uno or Mega if that is what it requires, but need to know so I can design the PCB correctly. I also assume that the common connection goes to the 5v pin?

Cheers

Les


Edited by lesthegrngo
Link to comment
Share on other sites

Hi Les,

physically you only need 3 pins per wheel as the signal has only 3 bit (0 to 7 dec).

The second wheel for Mode 1 only needs 2 pins (2 bit, 0 to 3 dec).

As that makes 17 pins in total plus the pins for all the 3 position switches, a Nano is not suitable.

For my wooden mockup of the IFF panel I use a Mega 2650 Pro, and I think that's the best way to go.

 

Here are code snippets for the IFF panel thumb wheels

// BCD decoded IFF Mode Thumb Wheels
// Mode-1 Wheel 1
const byte iffMode1Wheel1Pins[3] = {A14, 32, 34}; // three bit (0 - 7)
DcsBios::SwitchMultiPosBCD iffMode1Wheel1("IFF_MODE1_WHEEL1", iffMode1Wheel1Pins, 3);

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

// Mode-3A Wheel 1
const byte iffMode3aWheel1Pins[3] = {36, 38, 40};
DcsBios::SwitchMultiPosBCD iffMode3aWheel1("IFF_MODE3A_WHEEL1", iffMode3aWheel1Pins, 3);

// Mode-3A Wheel 2
const byte iffMode3aWheel2Pins[3] = {37, 39, 41};
DcsBios::SwitchMultiPosBCD iffMode3aWheel2("IFF_MODE3A_WHEEL2", iffMode3aWheel2Pins, 3);

// Mode-3A Wheel 3
const byte iffMode3aWheel3Pins[3] = {42, 44, 46};
DcsBios::SwitchMultiPosBCD iffMode3aWheel3("IFF_MODE3A_WHEEL3", iffMode3aWheel3Pins, 3);

// Mode-3A Wheel 4
const byte iffMode3aWheel4Pins[3] = {43, 45, 47};
DcsBios::SwitchMultiPosBCD iffMode3aWheel4("IFF_MODE3A_WHEEL4", iffMode3aWheel4Pins, 3);

Regards, Vinc


Edited by Vinc_Vega
typo correction

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Vinc, got it about the 10 position needing only three pins, I was under the understanding that position 9 required ON-OFF-OFF-ON, but I didn't realise it only went up to 7 in game - thanks for that, makes it simpler. I'll have to rig up some limit pins for the selector wheels so they only rotate through the required range, but that's a detail.

As you state, Mega seems the way to go, I have a spare and can combine the IFF and any other device with a selector wheel on it. And thanks for the sketch, that's going to save me a bundle of time and head-banging!

Once I have some working parts I will post the .sldprt and .stl files on grabcad for anyone to get for the selector wheels and housing

Cheers

 

Les
 

Link to comment
Share on other sites

  • 11 months later...
On 6/19/2017 at 5:58 AM, FSFIan said:

Try the following:

 

#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);
       }
       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();
}
 

 

 

Using the SwitchMultiPos class as a starting point, I wrote a SwitchMultiPosBCD class. All I had to change was the readState() method so it treats the pin numbers it is given as a BCD type input instead of "one pin per position".

 

The code I posted assumes that a BCD input is connected to pins 5, 6, 7 and 8, with 5 being the most significant bit and pin 8 being the least significant bit.

 

If a "1" bit means LOW in your setup instead of HIGH (in case your BCD output is not a digital output but a switch that pulls the Arduino pin to ground), you can change the readState() method so it inverts the input values it reads:

 

// before: state |= (digitalRead(pins_[i]) << j);
// after:
state |= ((digitalRead(pins_[i]) ^ 1) << j);
 

 

 

You can use the SwitchMultiPosBCD class just like SwitchMultiPos. If you copy from the control reference, make sure to get the length of the pin number array right in both locations (the definition of the array and the instantiation of SwitchMultiPosBCD in the line after that).

I keep getting an error message when running this code. Have tried the latest DCS-BIOS Libraies for both hub and fork.

Keep getting error "no matching function for call to "DcsBios::pollingInput::PollingInput()"

Not sure what I'm missing, any ideas?

Thanks

Bob

 


Edited by byteman59
Link to comment
Share on other sites

  • Recently Browsing   0 members

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