Jump to content

F18 LTD DCS-BIOS Issue


Lowlyslows

Recommended Posts

All,

I posted here as well: DCS-BIOS Discussion Thread 

 

How does DCS-BIOS work? The LTD/R and the LST/NFLR are not functioning properly. I wonder if there is something written wrong somewhere that I can possibly change and fix but I have no clue how this DCS BIOS works. Does the LUA file from DCS BIOS communicate with the F18 lua to action in the game? Even if I toggle them from the control reference page it still moves the wrong switch. The 2 codes below are loaded separately.

LTD/R code pushed to the arduino: DcsBios::Switch2Pos ltdRArm("LTD_R_ARM", 10); //this code moves the LST/NFLR

LST/NFLR code pushed to the arduino: DcsBios::Switch2Pos lstNflrSw("LST_NFLR_SW", 10); //this code moves the FLIR

I have tried as much as my ability is able to at this moment. I ended up messing up DCS so bad it won't load anymore and now I gotta figure that out. Currently have a repair going, if that doesn't work, I will reinstall. Still determined to figure out why I can't get the correct switch to move. 

Is anyone else seeing the same issue?

Link to comment
Share on other sites

18 minutes ago, No1sonuk said:

Hub is the version of DCS-BIOS.

The other version a lot of people use is called the Flightpanels fork. 

I just found all of the flight panel stuff. I’m gonna try following the open hornet guide: https://github.com/DCSFlightpanels/dcs-bios/blob/master/Scripts/DCS-BIOS/doc/DCS-BIOS-FLIGHTPANELS_Install Guide.pdf

 

I don’t know if this will work or not but it’s something different I guess. Had to reinstall DCS, wouldn’t load anymore after messing around in LUAs

Link to comment
Share on other sites

7 hours ago, No1sonuk said:

Hub is the version of DCS-BIOS.

The other version a lot of people use is called the Flightpanels fork. 

flightpanels bios worked! I am now having issues figuring out the coding that I need. How are you at coding? I am trying to get a SPST switch when turned off turns the LTD in the F18 to safe. Currently I have to move it twice to do so.

Link to comment
Share on other sites

On 12/22/2022 at 8:11 PM, No1sonuk said:

It should be Switch2Pos. Is that what the "simple" view on the control reference says?

I put this code in the library F18 LUA on line 1112 (replace the code that's there with it): 

defineToggleSwitchToggleOnly2("LTD_R_SW", 62, 3002, 441, "Sensor Panel", "LTD/R Switch, ARM/SAFE") 

This solved the toggling issue, now I need to get the physical switch to de-energize the electromagnet with the FLIR is set to STBY or when an Auto Bombing run is finished.

I have been working with these guys as well: F18 LTD/R 2position Switch Bugged · Issue #134 · DCSFlightpanels/dcs-bios (github.com)

Link to comment
Share on other sites

The way I'd do it is to use the switch to send a one-off siganl to DCS when you turn it on.
Then, as separate code running in parallel, I'd have the switch position READ from DCS turn the magnet on or off.

e.g.  Assuming the switch is sprung to the off position:

Read the physical switch position.
If the switch is off, but was on, send OFF to DCS.
If the switch is on, but was off, send ON to DCS.

Read the switch position in DCS.
If it's on, turn on the hold magnet.
If it's off, turn off the hold magnet.

The main issue, though, is that you need to make sure your magnet is strong enough to hold against the spring, but not so strong you can't overpower it to turn off the switch.
You don't turn off the magnet to turn off the switch.  You basically force it off and the electronics catches up.

SendDcsBiosMessage could be used to send the switch position.
If you use the standard Switch2Pos code line, the code gets read and switch position sent every loop, meaning DCS can't override it.  This isn't normally a problem, but if you need feedback from DCS to affect the physical switch, you need to "disconnect" the switch from the game.

The magnet part might be as simple as driving it from the LED code (switch the control reference view to "advanced" to get the other code lines):
DcsBios::LED ltdRSw(0x74c8, 0x4000, PIN);

Link to comment
Share on other sites

On 12/24/2022 at 12:18 PM, No1sonuk said:

The way I'd do it is to use the switch to send a one-off siganl to DCS when you turn it on.
Then, as separate code running in parallel, I'd have the switch position READ from DCS turn the magnet on or off.

e.g.  Assuming the switch is sprung to the off position:

Read the physical switch position.
If the switch is off, but was on, send OFF to DCS.
If the switch is on, but was off, send ON to DCS.

Read the switch position in DCS.
If it's on, turn on the hold magnet.
If it's off, turn off the hold magnet.

The main issue, though, is that you need to make sure your magnet is strong enough to hold against the spring, but not so strong you can't overpower it to turn off the switch.
You don't turn off the magnet to turn off the switch.  You basically force it off and the electronics catches up.

SendDcsBiosMessage could be used to send the switch position.
If you use the standard Switch2Pos code line, the code gets read and switch position sent every loop, meaning DCS can't override it.  This isn't normally a problem, but if you need feedback from DCS to affect the physical switch, you need to "disconnect" the switch from the game.

The magnet part might be as simple as driving it from the LED code (switch the control reference view to "advanced" to get the other code lines):
DcsBios::LED ltdRSw(0x74c8, 0x4000, PIN);

The electromagnet switch works as you suggest. It’s pretty cool. Yes it springs back to SAFE(off). I am using the Switch2pos code.

I learned by accident that the switch will function properly (electromagnet de-energizes) if I first set the LTD game switch to ARM (this also energizes the physical electromagnet) and then set my physical switch to ARM. Then, if I set the FLIR to STBY (in the game) the physical electromagnet will turn off and release the physical switch back to SAFE.

 

What would that one off code look like so I can test it? Sorry to ask but I’m still learning how to do basic code like turn on an LED.

 

Thanks for the help! Hope you had a great Christmas!

Link to comment
Share on other sites

27 minutes ago, No1sonuk said:

sendDcsBiosMessage(msg, argument);

So:

sendDcsBiosMessage("LTD_R_SW", "0")  //  This would send 0 to turn the switch off.
sendDcsBiosMessage("LTD_R_SW", "1")   //  This would send 1 to turn the switch on.

Where does this live in the code? Above void setup(), in void setup(), or in void loop()??

 

Also, how do I tie that to a switch (physical switch)?

 

 

#define DCSBIOS_IRQ_SERIAL
 
#include "DcsBios.h"
 
int Coil = 6;    // Magnetic coil on


 
DcsBios::Switch2Pos ltdRSw("LTD_R_SW", 2); //LTD ARM/SAFE


 
// LTD
void onLtdRSwChange(unsigned int newCoilValue) { //Controls the output of pin 6 and turns on electromagnet
    switch (newCoilValue){
      case 0:
      digitalWrite(Coil, LOW);
      break;
      case 1:
      digitalWrite(Coil, HIGH);
      break;
    }  
}
 
DcsBios::IntegerBuffer ltdRSwBuffer(0x74c8, 0x4000, 14, onLtdRSwChange);
 
void setup() {
  DcsBios::setup();
  pinMode (Coil, OUTPUT);
 
}
 
void loop() {
  DcsBios::loop();
   
}

Edited by Lowlyslows
Link to comment
Share on other sites

It goes in the loop.
It's the basic command that all the other switch, pot, etc. library routines run to send the info to DCS, so you have to use it manually.
i.e.

//  You should define constants that don't need to be changed by the code, such as pin numbers, like this so they don't consume program memory in the Arduino
#define SWITCHPIN 3   

// Use variables if the code needs to change the value.  These use memory space in the device.
int switchPrevState = 0;

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

  readLTD_R_SW();

}

void readLTD_R_SW(){
   int swState = digitalRead,SWITCHPIN;  // Read the switch
      if (swState != switchPrevState) {  // Check if the value is different
         if (swState == 0) {             
            sendDcsBiosMessage("LTD_R_SW", "0");}     // If it's different and low, send "0"
         else {sendDcsBiosMessage("LTD_R_SW", "1");}  // If it's different and high, send "1"
      switchPrevState = swState;  // Change the previous state to the current value
     }
}

Now this particular example is a long way to do 
DcsBios::Switch2Pos ltdRSw("LTD_R_SW", SWITCHPIN);

However, you might need to add conditions, or use multi-pin coded switches that the standard DCS-BIOS library doesn't account for.
AND, in the case of the code I wrote, it won't send the message every time the loop is run unless the position has changed.

Oh, and instead of this part:

void onLtdRSwChange(unsigned int newCoilValue) { //Controls the output of pin 6 and turns on electromagnet
    switch (newCoilValue){
      case 0:
      digitalWrite(Coil, LOW);
      break;
      case 1:
      digitalWrite(Coil, HIGH);
      break;
    }  
}
 
DcsBios::IntegerBuffer ltdRSwBuffer(0x74c8, 0x4000, 14, onLtdRSwChange);

Try this:

DcsBios::LED ltdRSw(0x74c8, 0x4000, Coil);

The long-hand way you used would be useful if you were going to reduce the magnet power to hold after the initial pull, but the LED code could probably be used for simple on/off.


So to rewrite your original:

#define DCSBIOS_IRQ_SERIAL
 
#include "DcsBios.h"
 
#define Coil  6    // Magnetic coil on pin
 
DcsBios::Switch2Pos ltdRSw("LTD_R_SW", 2); //LTD ARM/SAFE
 
// LTD hold magnet trigger
DcsBios::LED ltdRSw(0x74c8, 0x4000, Coil);
 
void setup() {
  DcsBios::setup();
  pinMode (Coil, OUTPUT);
 
}
 
void loop() {
  DcsBios::loop();
   
}


Also bear in mind that the "long-hand" way may use less program memory in the Arduino than the shorter DCS-BIOS commands.  However, if this is a problem, it might be your device has too much to do anyway. 🤣

Link to comment
Share on other sites

5 hours ago, Lowlyslows said:

I learned by accident that the switch will function properly (electromagnet de-energizes) if I first set the LTD game switch to ARM (this also energizes the physical electromagnet) and then set my physical switch to ARM. Then, if I set the FLIR to STBY (in the game) the physical electromagnet will turn off and release the physical switch back to SAFE.

There's sometimes some synching needed.  e.g. if I do cold/dark in the A-10C, I need to cycle the engine cutoff switches on the throttle before they'll work properly.
IIRC, there is a way to use DCS-BIOS to specifically read memory locations (not just the normal on-change), but I don't remember how.

Link to comment
Share on other sites

27 minutes ago, No1sonuk said:

So to rewrite your original:

#define DCSBIOS_IRQ_SERIAL
 
#include "DcsBios.h"
 
#define Coil  6    // Magnetic coil on pin
 
DcsBios::Switch2Pos ltdRSw("LTD_R_SW", 2); //LTD ARM/SAFE
 
// LTD hold magnet trigger
DcsBios::LED ltdRSw(0x74c8, 0x4000, Coil);
 
void setup() {
  DcsBios::setup();
  pinMode (Coil, OUTPUT);
 
}
 
void loop() {
  DcsBios::loop();
   
}


Also bear in mind that the "long-hand" way may use less program memory in the Arduino than the shorter DCS-BIOS commands.  However, if this is a problem, it might be your device has too much to do anyway. 🤣

When I run this code I get the attached error. Compilation error: conflicting declaration 'DcsBios::LED ltdRSw'

 

What would cause this?

 

Thanks for the help!

null

image.png

Link to comment
Share on other sites

With the other suggested code, I am not sure how to implement it. I assume I still need a line to define the switch so line #7 needs to be there. I am not sure what to do with line 25,26, and 30 as no matter what I try I get errors.

 

Sorry for my noobness. I am trying to learn this stuff.

 

null

image.png

Link to comment
Share on other sites

40 minutes ago, Lowlyslows said:

With the other suggested code, I am not sure how to implement it. I assume I still need a line to define the switch so line #7 needs to be there. I am not sure what to do with line 25,26, and 30 as no matter what I try I get errors.

No. You don't need line 7.

You missed that there were parts at the top of the code I gave you that had those definitions. There wasn't just comments there:

2 hours ago, No1sonuk said:
//  You should define constants that don't need to be changed by the code, such as pin numbers, like this so they don't consume program memory in the Arduino
#define SWITCHPIN 3   

// Use variables if the code needs to change the value.  These use memory space in the device.
int switchPrevState = 0;

I copied and underscored the bits you missed. They were on separate lines from the // comments. 

Link to comment
Share on other sites

6 hours ago, No1sonuk said:

I forgot the names can't be the same.

Change the LED one to ltdRSwCoil

Ok, didn't realize I could change the name like that, and it makes sense that the error would pop because of it. Learning!

The code works but I get exactly the same behavior using the LED code as the prior code. The game won't logically turn the physical electromagnet off if I set the physical LTD switch to ARM first. If I "trick" it by first setting the game LTD switch to ARM first and then setting the physical LTD switch to ARM, the game will logically de-energize the physical electromagnet.

Going to attempt to get the other suggested code to function next!

Link to comment
Share on other sites

Ok, tried the other code. I think I am running into the same naming issue as before. 

Questions:

1) Is everything above line 17 correct to use this code (See image)?

2) Line 19: the switch is wired to digital pin 2 on the board and the switch completes the circuit by going to GND. Is this correct per the suggested code? Line 19 has #define SWITCHPIN 3, not 2.

3) Line 33: has the same name in it as line 19, SWITCHPIN. It's not passing the "test" if the names are the same. If I change the name on either line (19 or 33) then it passes the test but the switch doesn't move in the game.

 

null

image.png

Link to comment
Share on other sites

WRT the magnet part:
The LED code just simplifies what you wanted to do fornomal operation.
There's possibly a way to use arduino code to synch everything, but I don't know what the bhaviouris supposed to be, so I can't write it for you.

WRT the "other code":

Change the number in line 19 to where your switch is.

I messed up the digitalRead code...
Change line 33 to 

int swState = digitalRead(SWITCHPIN);  // Read the switch

 

To tidy it up, move the constant and variable definitions (Lines 18-23) up to the beginning above line 8.

You also might need to add this to the setup routine:

pinMode (SWITCHPIN,INPUT_PULLUP);
Link to comment
Share on other sites

1 hour ago, No1sonuk said:

WRT the magnet part:
The LED code just simplifies what you wanted to do fornomal operation.
There's possibly a way to use arduino code to synch everything, but I don't know what the bhaviouris supposed to be, so I can't write it for you.

WRT the "other code":

Change the number in line 19 to where your switch is.

I messed up the digitalRead code...
Change line 33 to 

int swState = digitalRead(SWITCHPIN);  // Read the switch

 

To tidy it up, move the constant and variable definitions (Lines 18-23) up to the beginning above line 8.

You also might need to add this to the setup routine:

pinMode (SWITCHPIN,INPUT_PULLUP);

I’ll try out your suggestions tonight!

 

I was able to do some stuff this morning, see below.

 

I was able to get the code to function with the modifications in the image. 
#1 I created a standard switch circuit with 10 being the input which tells the code that the switch has moved
 
#2 I still can't figure this one out so I "removed" it from the code. #define SWITCHPIN 3 always fails
 
#3 I had to change the code from  
 
int swState = digitalRead,SWITCHPIN; 
to
int swState = digitalRead(10);
 
otherwise I couldn't get the switch to function due to it failing test.
 
Behavior: The switch in the game moves correctly as it relates to switch position when I move the physical switch. However, the "trick" no longer works and when I set the FLIR to STBY the LTD remains on ARM due to the electromagnet staying energized.
 
 
 

Edited by Lowlyslows
Link to comment
Share on other sites

10 hours ago, No1sonuk said:

WRT the magnet part:
The LED code just simplifies what you wanted to do fornomal operation.
There's possibly a way to use arduino code to synch everything, but I don't know what the bhaviouris supposed to be, so I can't write it for you.

WRT the "other code":

Change the number in line 19 to where your switch is.

I messed up the digitalRead code...
Change line 33 to 

int swState = digitalRead(SWITCHPIN);  // Read the switch

 

To tidy it up, move the constant and variable definitions (Lines 18-23) up to the beginning above line 8.

You also might need to add this to the setup routine:

pinMode (SWITCHPIN,INPUT_PULLUP);

Got the INPUT_PULLUP code to work which is awesome!

I'm thinking that maybe the code should see the status of all the things that effect the switch. Question is, how do I pull the status of a switch to use within an if, if else, and else statement?

For example, what is the status of the FLIR switch. If it's in the correct position (ON) then allow the electromagnet to energize when the physical LTD/R is moved to ARM. If the FLIR is in STBY or OFF then the electromagnet can't energize.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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