Jump to content

Recommended Posts

Posted

1: "Due" is one of the types of Arduino, like "Nano", "Uno", etc.

2: FASTLED is an Arduino library used for driving serial addressable LED strips like Neopixels and their clones.  You could use a string of LEDs for backlighting and change the brightness and colour using only a coupl of IO pins.  Likewise, it's theoretically possible to run an entire A-10 CWP from 2 IO pins with addressable LEDs.

As for mag switch code, I wrote this just now to use SPST mag switches with hold-on.
The checkSW function is written so it can be used like a DCS-BIOS function.  Just feed it the DCS-BIOS label for the switch and the pin number - see code for examples:

/*
  This code is designed to run a single-throw magnetic switch.  The A-10C's Left Yaw SAS switch was used
  in this example as it's easy to get it operational in-game for testing.

  The right switch is checked too, but no hold function is tested.

  The way it works is very simple:
  If DCS thinks the switch is on, it turns on the holding coil using the LED function.
  If DCS thinks the switch is off, it turns off the holding coil.

  If the switch is moved it sends a one-off signal to DCS ONLY when its state changes.

  This means that DCS will ignore the actual switch position if it thinks it should be opposite.
  i.e. DCS will turn off a magnetic held switch if the physical switch is in the ON position, and if 
  that switch then goes to "OFF", DCS will already be in the "OFF" condition, so it will ignore the change.

  Your switch should be rigged to hold only when the coil is energised.

  The checkSW function is written so it can be used like a DCS-BIOS function.
  Feed it the DCS-BIOS label for the switch and the pin number - see code for examples
 */
#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

#define Sw1Pin 2
#define Sw2Pin 3
#define Sw1HoldPin 13  // Output to hold coil - Use built-in LED for testing

int SwStates[16];  //  Array for holding pin previous states.  Set the number to the highest pin number you're using

/* paste code snippets from the reference documentation here */
DcsBios::LED saspYawSasL(0x1108, 0x0400, Sw1HoldPin);


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

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

  checkSW("SASP_YAW_SAS_L", Sw1Pin);  // Use the DCS-BIOS names
  checkSW("SASP_YAW_SAS_R", Sw2Pin);
}

void checkSW(const char* switchMessage, char pin){  
  
  //  This is written so it can be used like a DCS-BIOS function
  
  pinMode (pin, INPUT_PULLUP);  // included here to make the setup code simpler
  
  int SwPos = digitalRead(pin);

    // compare the switch tate to its previous state
  if (SwPos != SwStates[pin]) {
    // if the state has changed, increment the counter
    if (SwPos == HIGH) {
      // if the current state is HIGH then the switch went from on to off:
      sendDcsBiosMessage(switchMessage, "0");  //  Always switch off if switch moved to off by player
    } else {
      // if the current state is LOW then the switch went from off to on:
      sendDcsBiosMessage(switchMessage, "1");  //  Always switch on if switch moved to on by player
    }
    // Delay a little bit to avoid bouncing - may not be required.
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  SwStates[pin] = SwPos;

}

I've not tested that with an actual mag-hold switch, but the testing I could do indicates it will work as intended.

  • Like 1
  • Thanks 1
Posted (edited)
2 hours ago, No1sonuk said:

1: "Due" is one of the types of Arduino, like "Nano", "Uno", etc.

2: FASTLED is an Arduino library used for driving serial addressable LED strips like Neopixels and their clones.  You could use a string of LEDs for backlighting and change the brightness and colour using only a coupl of IO pins.  Likewise, it's theoretically possible to run an entire A-10 CWP from 2 IO pins with addressable LEDs.

As for mag switch code, I wrote this just now to use SPST mag switches with hold-on.
The checkSW function is written so it can be used like a DCS-BIOS function.  Just feed it the DCS-BIOS label for the switch and the pin number - see code for examples:

/*
  This code is designed to run a single-throw magnetic switch.  The A-10C's Left Yaw SAS switch was used
  in this example as it's easy to get it operational in-game for testing.

  The right switch is checked too, but no hold function is tested.

  The way it works is very simple:
  If DCS thinks the switch is on, it turns on the holding coil using the LED function.
  If DCS thinks the switch is off, it turns off the holding coil.

  If the switch is moved it sends a one-off signal to DCS ONLY when its state changes.

  This means that DCS will ignore the actual switch position if it thinks it should be opposite.
  i.e. DCS will turn off a magnetic held switch if the physical switch is in the ON position, and if 
  that switch then goes to "OFF", DCS will already be in the "OFF" condition, so it will ignore the change.

  Your switch should be rigged to hold only when the coil is energised.

  The checkSW function is written so it can be used like a DCS-BIOS function.
  Feed it the DCS-BIOS label for the switch and the pin number - see code for examples
 */
#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

#define Sw1Pin 2
#define Sw2Pin 3
#define Sw1HoldPin 13  // Output to hold coil - Use built-in LED for testing

int SwStates[16];  //  Array for holding pin previous states.  Set the number to the highest pin number you're using

/* paste code snippets from the reference documentation here */
DcsBios::LED saspYawSasL(0x1108, 0x0400, Sw1HoldPin);


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

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

  checkSW("SASP_YAW_SAS_L", Sw1Pin);  // Use the DCS-BIOS names
  checkSW("SASP_YAW_SAS_R", Sw2Pin);
}

void checkSW(const char* switchMessage, char pin){  
  
  //  This is written so it can be used like a DCS-BIOS function
  
  pinMode (pin, INPUT_PULLUP);  // included here to make the setup code simpler
  
  int SwPos = digitalRead(pin);

    // compare the switch tate to its previous state
  if (SwPos != SwStates[pin]) {
    // if the state has changed, increment the counter
    if (SwPos == HIGH) {
      // if the current state is HIGH then the switch went from on to off:
      sendDcsBiosMessage(switchMessage, "0");  //  Always switch off if switch moved to off by player
    } else {
      // if the current state is LOW then the switch went from off to on:
      sendDcsBiosMessage(switchMessage, "1");  //  Always switch on if switch moved to on by player
    }
    // Delay a little bit to avoid bouncing - may not be required.
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  SwStates[pin] = SwPos;

}

I've not tested that with an actual mag-hold switch, but the testing I could do indicates it will work as intended.  

That is great and I will give it a go…. I’ll report back here idc

Would I be right in saying we can define an LED output for any switch.  So we could have a DcsBios::LED LTDR(?x???, ?x????, pin?)  ???

Edited by Gosling
  • 2 months later...
Posted
On 3/21/2023 at 11:28 PM, Gosling said:

Would I be right in saying we can define an LED output for any switch.  So we could have a DcsBios::LED LTDR(?x???, ?x????, pin?)  ???

Sorry - only just seen this.
Not every switch.  You need to know the address of the switch (the ?x???? part), IF it has one.

  • Recently Browsing   0 members

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