Jump to content

Magnetic Switch


Sting57

Recommended Posts

Hi all I am attempting to set up a Mag switch for the teh LAser Arm switch in the Hornet.  I have been following the Warthog Projects Video on Mag switches

 

Here is the code i ended up with based on that vid and files provided


#define DCSBIOS_IRQ_SERIAL

#include <DcsBios.h>
#include <SPI.h>
#include <Wire.h>
//comm port 18

int onLtdRSw_Coil = 4;    // Magnetic coil CH4

 // Sensor Panel
DcsBios::Switch2Pos ltdRSw("LTD_R_SW", 5);

// LASER Switch Arm
void onLtdRSwChange(unsigned int newCoilValue) {
   switch (newCoilValue){
      case 0:
      digitalWrite(onLtdRSw_Coil, LOW);
      break;
      case 1:
      digitalWrite(onLtdRSw_Coil, HIGH);
      break;
    }
}
DcsBios::IntegerBuffer ltdRSwBuffer(0x74c8, 0x4000, 14, onLtdRSwChange);

void setup() {

DcsBios::setup();
 
pinMode (onLtdRSw_Coil, OUTPUT);
}

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

 

Outcome:

The Switch only parital works.   Once i turn the switch to arm, it does magnetize, however it will not automatically demagnatise, ie by switching the FLIR switch to stby or after a bomb has passed its time to impact  (this is when the switch should return to safe).  It does however work /demagnatise if i click the actual switch in the 3d cockpit back to safe.

Its like once the switch has been put in the arm position, the automatic process for returning to safe don't work but the manual clicking the button does.

 

Would love to see if any one has any ideas i might try.

thanks

 

Mike

 

 

 

  • Like 2

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 my magnetic switch I have set the conditions where it is OFF in the code.
I have it on the start switch in the AJS37 and have a bunch of if-statements like if RPM is higher than 42% and/or that switch is set Off then magswitch is off too.

  • Like 2
Link to comment
Share on other sites

//SAS Yaw Right
DcsBios::Switch2Pos saspYawSasR("SASP_YAW_SAS_R", 4);
void onSaspYawSasRChange(unsigned int YawSasR) {
   if (YawSasR==0) {
    digitalWrite(A2, LOW   );
   }
   else if (YawSasR==1){
    digitalWrite(A2, HIGH);
    }
   }

DcsBios::IntegerBuffer saspYawSasRBuffer(0x1108, 0x0800, 11, onSaspYawSasRChange);

pin 4 is input from the switch
pin A2 is output energizing the magnetic hold coil (via Darlington cascade)


Edited by agrasyuk

Anton.

 

My pit build thread .

Simple and cheap UFC project

Link to comment
Share on other sites

  • 2 weeks later...

@No1sonuk

The issue we found with the F18 - and its documented, is unlike the A10, the Mag switch function is not fully supoorted in DCS-BIOS for the F18, there is no single line of code for the MAG SW, however, we used ethernet sheilds and a Arduino Due to use "Keypresess" to overcome this and have all Mag switches working correclty in the F18

 

@Dead Meat also has codes and a youtube (I am re looking for it), has this at all changed in any BIOS upupdate ?

@bnepethomas

 

 Codes and documents on our githubs

Link to comment
Share on other sites

7 minutes ago, Ben-111 said:

@No1sonuk

The issue we found with the F18 - and its documented, is unlike the A10, the Mag switch function is not fully supoorted in DCS-BIOS for the F18, there is no single line of code for the MAG SW, however, we used ethernet sheilds and a Arduino Due to use "Keypresess" to overcome this and have all Mag switches working correclty in the F18

Not 100% sure what you mean by "ethernet shields and a Arduino Due", but I know a Leonardo can take status data from DCS and send "keypresses" in one device:

That sends joystick button presses, but it could easily be changed for keypresses.

Link to comment
Share on other sites

I use the code Pete wrote, but do not fully understand how it works, but essuntally instead of sending the DCS BIOS Command, we send a keystroke to DCS (that is also Mapped in the control options) to "switch the Switch" we then also send a command via the eithernet shield to the Due to trigger the Mag Switch

 

My codes are here for the entire pit

https://github.com/Ben-F111/Ben-F18-Sim-Pit/tree/main/1- Final Codes/AS UPLOADED - CURRENT ONLY

 

DUE Code is LIP_UDP_TO_KEYBOARD

the MAG SW output code is inside this one LIP_SERVO_STEPPER_DIGITAL_OUT

Extract from the code RIGHT_CONSOLE_INPUT_CONTROLLER.ino

our switches are Matrix via a CASE Statment to allow for inputs (180 i think per Arduino)

case 22:
          sendDcsBiosMessage("LTD_R_SW", "1");        

case 22:
          // Special Case for Magnetic Switches LTD/R
          if (Ethernet_In_Use == 1) {
            SendIPString("LCTRL LSHIFT F3");
          } else {
            sendDcsBiosMessage("LTD_R_SW", "2");
          }
          break;

as the mag switch is not supported by DCS BIOS what you find is you cant turn them off as the physical switch is still holding the same command to BIOS to to turn Mag switch on 

Link to comment
Share on other sites

On 8/16/2022 at 9:20 PM, Ben-111 said:

as the mag switch is not supported by DCS BIOS what you find is you cant turn them off as the physical switch is still holding the same command to BIOS to to turn Mag switch on 

I think it's FAR easier than you've made it.
I just did a test with these two lines:

DcsBios::ActionButton gen("GEN", "1", 8);
DcsBios::LED genHold(0x5000, 0x0001, 13);

Those two lines could run a mag switch...
ActionButton only fires the command once, on the falling edge of the switch input.
In my example, the switch turns on the P51 generator switch, and the LED responds to the in-game switch position.
I triggered the switch and left it in place.  The light came on.
I then moved the switch in DCS (with the physical switch still on), and it turned off, and stayed off, and the LED went out.
Then moving the physical switch to off did nothing.
For the mag switch, the hold solenoid could be driven in place of the LED to hold the switch on.

Test sketch for P51:

#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

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

DcsBios::ActionButton gen("GEN", "1", 8); // Sends switch position "1" to the "GEN" switch on the pin 8 falling edge 
DcsBios::LED genHold(0x5000, 0x0001, 13);

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

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

EDIT:
This is flawed and I didn't notice - there's no way to turn off the control with the physical switch... 🤦‍♂️


Edited by No1sonuk
A flaw came to light
Link to comment
Share on other sites

Ok tried your idea with this

DcsBios::ActionButton ltdRSwToggle("LTD_R_SW", "TOGGLE", 5);
DcsBios::LED ltdRSw(0x74c8, 0x4000, 4); // my magnet is on this through a MOSFET

It almost works.   I have to put the ltd switch in to ARM position (the magnet comes on holding the switch in place).  I then have to move the switch back to SAFE and then back into ARM.  If i do that, ie switch it to ARM twice.  The switch then acts as expected,  ie, if I go to NAV mode or master arm to safe or FLIR to stby, the switch then snaps back to the SAFE position as expected.

If  I don't do it twice then its the same problem i started with, ie it never releases the switch.

 

 

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

8 hours ago, Sting57 said:

yeah,  "1" does not work either though the result it different (read: worse)  it only releases the switch if you click the switch in the 3d pit.

OK.  ActionButton won't work then.  UNLESS, you rig a second one to turn off using the other contact on a SPDT switch.
So maybe this:

DcsBios::ActionButton ltdRSwToggleOn("LTD_R_SW", "1", 5);
DcsBios::ActionButton ltdRSwToggleOff("LTD_R_SW", "0", 6); // Second contact on same switch. Note different names before parenthesis
DcsBios::LED ltdRSw(0x74c8, 0x4000, 4);

That trades code simplicity for using extra IO pins.
Otherwise, you'll need to do it with polling the switch and sendDcsBiosMessage or the DCS-BIOS/HID hybrid idea mentioned earlier.

Link to comment
Share on other sites

  • 2 weeks later...

@No1sonuk yes agree our solution could be easier, however we use the shields to sperate Inputs and outputs on the Arduinos, also as we use FASTLED for the back lighting there is a interrupt issue with the DCS BIOS and FASTLED, so we run the FASTLED and the KEYSTROKES via the DUE without DCS BIOS on that Arduino, so to confirm, yes the ethernet is there for a primary purpose, not the MAG SW, we just use it in this case, but it’s not needed if the DUE has the main MAG switch code on it 

Link to comment
Share on other sites

  • 6 months later...

I have read all this and have a little lack of knowledge.  That may also apply to others, so I will use the aviation excuse that “there are no dumb questions” and “never assume, check” and ask…

1. DUE?

2. FASTLED

3. I did work out what a Darlington Cascade is - An electronic circuit using two or more transistors to multiply current gain enough to power the magnetic coils.  
 

@No1sonuk - As I am in VR, I have no interest in cockpit lighting, so I like your solution.  I can redesign my switches to have SPDT so would like to use your solution.  Would you expand on your information for me please, maybe via PM, or here if it helps everyone..


Edited by Gosling
Link to comment
Share on other sites

  • Recently Browsing   0 members

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