Jump to content

DCS-BIOS Init State Support Files


Recommended Posts

Hi,

 

I posted this within another thread but I wanted to create a new thread that I'll update as I add polling support to new controls.

 

So far the switches.h and potentiometers.h functions have a new function call pollInputCurrent(). With regular polling the initial state of your switch boxes will be force pushed to DCS. This is useful as the current control state is synced with the sim control state.

 

Unzip/Copy this file to your Arduino DCSBIOS library location, backup up the old one first.

Location: C:\Users\<username>\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src\internal

 

DCS-BIOS with Polling Funcs.zip

 

 

Sample Code.

 

//ECS Panel

#define DCSBIOS_RS485_SLAVE 18
#define TXENABLE_PIN 2

#include <DcsBios.h>
#define DCSBIOS_IRQ_SERIAL

DcsBios::Potentiometer cabinTemp("CABIN_TEMP", 0);
DcsBios::Switch3Pos engAntiiceSw("ENG_ANTIICE_SW", 10, 11);

unsigned int g_iInitIntervalCounter = 0;

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

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

  if ( ++g_iInitIntervalCounter == 0 ) 
   {  
        PollAllControls(); 
   }

}

void PollAllControls()
{
    engAntiiceSw.pollInputCurrent();
    cabinTemp.pollInputCurrent();
    //...  
}

Link to post
Share on other sites

Thanks again for this.

 

I would like to avoid sending all my button states every x cycles, so was looking at a way of doing it just once when first entering the cockpit.

 

Based on some googling I came up with the following code that is triggered when the active aircraft changes

 

void onAcftNameBufferChange(char* newValue) {

 // Change of Aircraft
 if(( strcmp( newValue, "FA-18C_hornet" ) == 0 ))
 {
   PollAllControls();
 }
}

DcsBios::StringBuffer<16> AcftNameBuffer(0x0000, onAcftNameBufferChange);

 

And it works perfectly, all of my switches synch as soon as I hit "Fly" on the briefing window. The first time I load up the F/A-18. Any time I start another hornet mission after that, even exiting DCS and starting again, the name change is not triggered.

 

The only time it gets triggered again is if I launch a mission with a different aircraft and then go back to the hornet.

 

So does anyone have any ideas of another event to capture that always fires at the start of a mission?

Intel i7 10700K @ 4.5 GHz / ASUS ROG STRIX Z490-F Gaming / 32 Gb G.Skill DDR4 / Inno3d RTX 3090 / 512 Gb Samsung 850 EVO System SSD / 512 Gb Samsung 850 EVO DCS SSD / Win 10 x64 Pro / WINWING F/A-18 HOTAS

 

A-10C, AV-8B, F-5E, F-86F, FC3, FW190D-9, Hawk, Ka50 2, P-51D, Spitfire, UH-1H, F/A-18C, F-14, F-16, Supercarrier, Christen Eagle 2

 

Nevada, Normandy, Persian Gulf, The Channel

Link to post
Share on other sites

Thanks Andrew, I did try this technique but I couldn't reliably get all my buttons to sync. I've noticed when you have allot of buttons some messages are missed but caught on the next poll. I could trigger maybe a 30 second period of this from the AC change event.

Link to post
Share on other sites

Hi Blue73, I'd like to thank you too.

Have used your code within my panels and they are working fine.

I'm also interested in a solution that pulling is not initiated regularily.

I think the idea to give a command by the BATT PWR switch is worth to try it.

But my coding skills are still to poor to do it myself.

Do you have an idea how to initiate pulling by a dedicated switch?


Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Link to post
Share on other sites

My pleasure Vinc :) Sorry for the late reply, been busy lately.

 

I've implemented the battery switch trigger, code below for my SNSR panel. It detects a battery switch change then kicks off 10 rounds of switch synchronisation.

 

 

//SNSR Panel

#define DCSBIOS_RS485_SLAVE 20
#define TXENABLE_PIN 2

#include <DcsBios.h>
#define DCSBIOS_IRQ_SERIAL

DcsBios::Switch3Pos flirSw("FLIR_SW", 11, 12);
DcsBios::Switch2Pos lstNflrSw("LST_NFLR_SW", 15);
DcsBios::Switch3Pos ltdRSw("LTD_R_SW", 13, 14);

#define FORCEPOLLCYCLES 10
unsigned int g_iInitIntervalCounter = 0;
unsigned int g_iForcePollCycles = 0;

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

}

void loop() {
 
  DcsBios::loop();
  
  if ( g_iForcePollCycles > 0 )
   { 
       //repeat poll for this many cycles
       if ( ++g_iInitIntervalCounter == 0 ) 
       {  PollAllControls();     //main loop 1->65535->0 then polls
          g_iForcePollCycles--;
       }
      
   }
   
}

void onBatterySwChange(unsigned int newValue) 
{
     //Battery Switch change, start polling controls FORCEPOLLCYCLES times
     g_iForcePollCycles = FORCEPOLLCYCLES;
}
DcsBios::IntegerBuffer batterySwBuffer(0x54b6, 0x0600, 9, onBatterySwChange);

void PollAllControls()
{
   flirSw.pollInputCurrent();
   lstNflrSw.pollInputCurrent();
   ltdRSw.pollInputCurrent();
}



Hi Blue73, I'd like to thank you too.

Have used your code within my panels and they are working fine.

I'm also interested in a solution that pulling is not initiated regularily.

I think the idea to give a command by the BATT PWR switch is worth to try it.

But my coding skills are still to poor to do it myself.

Do you have an idea how to initiate pulling by a dedicated switch?

 

 

cheers

 

John


Edited by Blue73
Link to post
Share on other sites

For information:

 

the code for the A-10C battery switch trigger reads as follows

 

void onEppBatteryPwrChange(unsigned int newValue) {

//Battery Switch change, start polling controls FORCEPOLLCYCLES times

g_iForcePollCycles = FORCEPOLLCYCLES;

}

 

DcsBios::IntegerBuffer eppBatteryPwrBuffer(0x1110, 0x0002, 1, onEppBatteryPwrChange);

and the Battery PWR Switch itselfs (eppBatteryPwr) must not be polled within the PollAllControls() function, otherwise an infinite poll cycle is created.

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Link to post
Share on other sites

Hi Vinc, I cant reproduce on the F-18, it must be unique to certain control behaviors. It does makes sense to skip polling of the trigger control.

 

Thanks.

 

cheers

 

John

 

For information:

 

the code for the A-10C battery switch trigger reads as follows

 

and the Battery PWR Switch itselfs (eppBatteryPwr) must not be polled within the PollAllControls() function, otherwise an infinite poll cycle is created.

Link to post
Share on other sites
Hi Vinc, I cant reproduce on the F-18, it must be unique to certain control behaviors. It does makes sense to skip polling of the trigger control.

 

Thanks.

 

cheers

 

John

 

 

Sorry my mistake, I din't count it right.

So indeed force polling the trigger switch does not initiate a new counter cycle.

But nevertheless, I think skipping the trigger poll is the better solution.

 

 

Thank you again John for showing the coding way.

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Link to post
Share on other sites
  • 1 month later...

Hi, you just need to apply the code as shown in the example on the first post. Notably the PollAllControls() function and the calling code within loop().

 

cheers

 

John

 

 

i copied the two .h files to the src\internal folder. nothing happened. what else do i have to do? toggles, switches in game not in sync with real ones.
Link to post
Share on other sites

Anytime mate!

 

True I noticed it needs to send it repeatedly, eventually all controls are sync'd. Yes it makes no sense to sync encoders as it doesn't define absolute position, POTs are used for that.

 

cheers

 

John

 

Roger. I tried it. It works! holy cow. This is so cool!

 

I randomly flipped toggles and turned pots and rotary switches. If not initially in sync they sync after like 10 seconds. Noticed encoders can't be done.

 

Thank you so much Blu73! :thumbup:

Link to post
Share on other sites

When we start off cold it doesn't matter the positions of the switches since we'd be changing them anyway. But when i start off at the runway, it changes the default settings for that mission to the position of my physical switches, which may be at the wrong positions! I don't know what has changed and how many. How do I know what are the original/correct settings, then go and change all of them? Now this sync seems to introduce a big load of work at the start of a mission, instead of the original plan to sync and reduce the manual flipping of switches to sync with the game.

 

How do you guys deal with this?

Link to post
Share on other sites

Hi rocketeer, to prevent syncing you can trigger the sync only when a certain condition is met. For example another switch is toggled, or add a seperate momentary push button that when held runs the PollnputCurrent() routine.

 

When we start off cold it doesn't matter the positions of the switches since we'd be changing them anyway. But when i start off at the runway, it changes the default settings for that mission to the position of my physical switches, which may be at the wrong positions! I don't know what has changed and how many. How do I know what are the original/correct settings, then go and change all of them? Now this sync seems to introduce a big load of work at the start of a mission, instead of the original plan to sync and reduce the manual flipping of switches to sync with the game.

 

How do you guys deal with this?

Link to post
Share on other sites

Hi, not sure about a keyboard encoder but with a push button it would be.

 

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

      if ( digitalRead(4) )      
      {            PollAllControls();      
       }  

}  

void PollAllControls() 
{      
         engAntiiceSw.pollInputCurrent();      
         cabinTemp.pollInputCurrent();      //...   
}

 

 

 

ok so say i use a push button using a keyboard encoder, how do i code if this button is pressed? assuming if pressed the value is 1? something like this below?

 

void PollAllControls()

{

if 2Joy6 == 1

{

engAntiiceSw.pollInputCurrent();

cabinTemp.pollInputCurrent();

//...

}

}

Link to post
Share on other sites

Hi Blue,

I used example of 2Joy6 as second joystick detected by game controller control panel, be it a keyboard encoder or what not. Your digitalRead(4) i assume is a button #4. But what is it connected to? Arduino? I know certain arduino boards like the mega or nano can't be used as keyboard encoder. I could use megas for dcs bios. but not directly without dcs bios for function keys and other dcs keyboard commands that are not directly controlling switches.

Link to post
Share on other sites

Hi rocketeer, This is a DCS-BIOS mod, interfacing with the sim as a HID isn't applicable here. The Arduino function digitalRead(4) means read the state of pin D4 on the Arduino. The pin is internally pulled high and a switch or push button connected pulls it low. So active on pin4 is zero, inactive is one. My code snippet would need to have a '!' in front of digitalRead().

 

cheers

 

John

 

Hi Blue,

I used example of 2Joy6 as second joystick detected by game controller control panel, be it a keyboard encoder or what not. Your digitalRead(4) i assume is a button #4. But what is it connected to? Arduino? I know certain arduino boards like the mega or nano can't be used as keyboard encoder. I could use megas for dcs bios. but not directly without dcs bios for function keys and other dcs keyboard commands that are not directly controlling switches.

Link to post
Share on other sites

Thanks Blue for all these info. I'm learning quite a bit from this. So you say it's dcs bios, is this an unused button? ie. it has not been assigned to any of the switches on any of the a10c panels? for dcs bios i just use Ian's code. I don't know how to use arduino outside dcs bios.

 

What if you have many arduino mega boards connected? how do you tell it to use the D4 on a specific one?

Link to post
Share on other sites

Not a problem rocketeer. You can either monitor the state of a DCS-BIOS control then trigger a sync or use the digitalRead() function to read the raw state from a spare Arduino pin.

 

Every time a switch state changes DCS-BIOS generates an event that you can do things with. If you want a separate button to trigger sync then research how to connect a button to an Arduino pin: it's just two functions, pin setup and then the pin read.

 

The code runs local to the Arduino, so D4 is always D4 for that board. If you go the Master-Slave route then it's still the same, the code on the master or slave only refers to it's own hardware.

 

cheers

 

John

 

 

 

Thanks Blue for all these info. I'm learning quite a bit from this. So you say it's dcs bios, is this an unused button? ie. it has not been assigned to any of the switches on any of the a10c panels? for dcs bios i just use Ian's code. I don't know how to use arduino outside dcs bios.

 

What if you have many arduino mega boards connected? how do you tell it to use the D4 on a specific one?

Link to post
Share on other sites

const int switchPin = 52;     // the number of the toggle switch pin
int switchState = 0;         // variable for reading the toggle switch status

void setup() {
 DcsBios::setup();
 
 pinMode(switchPin, INPUT_PULLUP);  // initialize the toggle switch pin as an input
}

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

 switchState = digitalRead(switchPin);  // read the state of the toggle switch value

 if ( ++g_iInitIntervalCounter == 0 ) 
 {  

// check if the toggle switch is flipped up. If not, it remains LOW, then poll the controls
// If it's not LOW, then it won't poll control therefore the syncing will not happen!
   if (switchState == LOW) 
   {         
        PollAllControls(); 
   }
 }
}

 

I learned to code a push button, then realized I have to keep pressing it to remain high, so i changed it to a toggle switch.

 

The above works. If I don't flip the switch, it polls the controls, finds the difference and syncs the switches.

If I flip the toggle up, it does not poll and therefore does not sync.

So for missions that I don't want to sync, like those starting from the ramp, then I flip the switch up.

 

 

This is great. However, this works only for those panels that are in the same sketch as this new toggle switch. My entire A10C cockpit is covered by 6 Megas. Is there a way to check the status on this new toggle switch on a particular mega, then make it a global value so that all Megas know its status and then decide whether or not to poll the switches on those megas?

Link to post
Share on other sites
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...