WhoMadeWho Posted December 29, 2018 Share Posted December 29, 2018 Hello, I'm wondering if anyone has found a way to sync **current** switch positions into DCS-BIOS. Problem is I need to cycle switches back and forth before DCS-BIOS knows where my switch is set. I recall reading something would be added into DCS-BIOS v2 but I know the author is busy with school. Any ideas? Thanks all! :) /* Tell DCS-BIOS to use a serial connection and use interrupt-driven communication. The main program will be interrupted to prioritize processing incoming data. This should work on any Arduino that has an ATMega328 controller (Uno, Pro Mini, many others). */ #define DCSBIOS_IRQ_SERIAL #include "DcsBios.h" // GUN/PAC GUNARM - SAFE - ARM DcsBios::Switch3Pos ahcpGunpac("AHCP_GUNPAC", 2, 3); // GND = Gray, 2 = White, 3 = Blue // Master Arm TRAIN - SAFE - ARM DcsBios::Switch3Pos ahcpMasterArm("AHCP_MASTER_ARM", 4, 5); // GND = Green + Purple, 4 = White, 5 = Orange // Laser Arm TRAIN - SAFE - ARM DcsBios::Switch3Pos ahcpLaserArm("AHCP_LASER_ARM", 6, 7); // GND = Purple + White, 6 = Blue, 7 = Orange // TGP OFF - ON DcsBios::Switch2Pos ahcpTgp("AHCP_TGP", 8); // GND = Brown, 8 = Yellow // Altimeter Source RADAR - DELTA - BARO DcsBios::Switch3Pos ahcpAltSce("AHCP_ALT_SCE", 9, 10); void setup() { DcsBios::setup(); } void loop() { DcsBios::loop(); } Link to comment Share on other sites More sharing options...
Blue73 Posted December 29, 2018 Share Posted December 29, 2018 (edited) I had resolved this issue by adding a member function "pollInputCurrent " to switches.h. Unfortunately it's been overwritten, but from memory it was just the same as pollInput except it doesn't check for a state change. I called the function for each control during Setup(), something like this, Edit: I also called it within onAcftNameChange() and called it every 40000 cycles in case it was missed during init. class Switch2Pos : PollingInput { private: const char* msg_; char pin_; char lastState_; bool reverse_; void init_(const char* msg, char pin, bool reverse) { msg_ = msg; pin_ = pin; pinMode(pin_, INPUT_PULLUP); lastState_ = digitalRead(pin_); reverse_ = reverse; } void pollInput() { char state = digitalRead(pin_); if (reverse_) state = !state; if (state != lastState_) { if (tryToSendDcsBiosMessage(msg_, state == HIGH ? "0" : "1")) { lastState_ = state; } } } public: Switch2Pos(const char* msg, char pin, bool reverse) { init_(msg, pin, reverse); } Switch2Pos(const char* msg, char pin) { init_(msg, pin, false); } void pollInputCurrent() { char state = digitalRead(pin_); if (tryToSendDcsBiosMessage(msg_, state == HIGH ? "0" : "1")) { lastState_ = state; } } }; For your code void setup() { DcsBios::setup(); ahcpTgp.pollInputCurrent(); //... do for all control types, add member function to all classes. } Hello, I'm wondering if anyone has found a way to sync **current** switch positions into DCS-BIOS. Problem is I need to cycle switches back and forth before DCS-BIOS knows where my switch is set. I recall reading something would be added into DCS-BIOS v2 but I know the author is busy with school. Any ideas? Thanks all! :) /* Tell DCS-BIOS to use a serial connection and use interrupt-driven communication. The main program will be interrupted to prioritize processing incoming data. This should work on any Arduino that has an ATMega328 controller (Uno, Pro Mini, many others). */ #define DCSBIOS_IRQ_SERIAL #include "DcsBios.h" // GUN/PAC GUNARM - SAFE - ARM DcsBios::Switch3Pos ahcpGunpac("AHCP_GUNPAC", 2, 3); // GND = Gray, 2 = White, 3 = Blue // Master Arm TRAIN - SAFE - ARM DcsBios::Switch3Pos ahcpMasterArm("AHCP_MASTER_ARM", 4, 5); // GND = Green + Purple, 4 = White, 5 = Orange // Laser Arm TRAIN - SAFE - ARM DcsBios::Switch3Pos ahcpLaserArm("AHCP_LASER_ARM", 6, 7); // GND = Purple + White, 6 = Blue, 7 = Orange // TGP OFF - ON DcsBios::Switch2Pos ahcpTgp("AHCP_TGP", 8); // GND = Brown, 8 = Yellow // Altimeter Source RADAR - DELTA - BARO DcsBios::Switch3Pos ahcpAltSce("AHCP_ALT_SCE", 9, 10); void setup() { DcsBios::setup(); } void loop() { DcsBios::loop(); } Edited December 29, 2018 by Blue73 Link to comment Share on other sites More sharing options...
WhoMadeWho Posted December 29, 2018 Author Share Posted December 29, 2018 Thanks Blue73 for the reply! I tried inserting your code but get an error at compile time - "Expected class-name before '{' token".. Can you tell me where I went wrong? Sorry, I'm probably missing something really obvious..:helpsmilie: #define DCSBIOS_IRQ_SERIAL #include "DcsBios.h" // Start class from Blue73 class Switch2Pos : PollingInput { private: const char* msg_; char pin_; char lastState_; bool reverse_; void init_(const char* msg, char pin, bool reverse) { msg_ = msg; pin_ = pin; pinMode(pin_, INPUT_PULLUP); lastState_ = digitalRead(pin_); reverse_ = reverse; } void pollInput() { char state = digitalRead(pin_); if (reverse_) state = !state; if (state != lastState_) { if (tryToSendDcsBiosMessage(msg_, state == HIGH ? "0" : "1")) { lastState_ = state; } } } public: Switch2Pos(const char* msg, char pin, bool reverse) { init_(msg, pin, reverse); } Switch2Pos(const char* msg, char pin) { init_(msg, pin, false); } void pollInputCurrent() { char state = digitalRead(pin_); if (tryToSendDcsBiosMessage(msg_, state == HIGH ? "0" : "1")) { lastState_ = state; } } }; // End class from Blue73 // TGP OFF - ON DcsBios::Switch2Pos ahcpTgp("AHCP_TGP", 8); // GND = Brown, 8 = Yellow void setup() { DcsBios::setup(); ahcpTgp.pollInputCurrent(); } void loop() { DcsBios::loop(); } Link to comment Share on other sites More sharing options...
Blue73 Posted December 30, 2018 Share Posted December 30, 2018 (edited) The new function needs to be inserted into the DCSBIOS library rather than your code. Once done all you do is call the new function within your setup. My libraries are in the following folder, C:\Users\<username>\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src\internal Can you PM me your email address so I can send you the updated switches.h file? The functions are slightly different for switch3pos and switchmultipos. I could be more elegant and rewrite his function to accommodate this variation but instead left it as is and repeated much of his code leaving out the delta check. Edit: I could post here but not sure of the T&C's. cheers John Edited December 30, 2018 by Blue73 Link to comment Share on other sites More sharing options...
Bullant Posted December 31, 2018 Share Posted December 31, 2018 Edit: I could post here but not sure of the T&C's. Could you please post here? This is something that is sort after by a lot of people, myself included :) Intel i7 13700K @ 5.3 GHz / ASUS TUF Gaming Z490-Plus / 64 Gb G.Skill DDR4-3600 / RTX 4090 / 2TB Kingston KC3000 NVME / Win 10 x64 Pro / Pimax Crystal / WINWING F/A-18 HOTAS A-10C, AJS-37, AV-8B, F-4E, F-5E, F-14, F-15E, F-16, F/A-18C, F-86F, FC3, Christen Eagle 2, FW190D-9, Mosquito, P-47D, P-51D, Spitfire, AH-64D, KA-50, UH-1H Combined Arms, WWII Asset Pack, China Assets Pack, Super Carrier, Falklands Assets Nevada, Normandy, Persian Gulf, The Channel, Syria, Mariana Islands, South Atlantic, Sinai Link to comment Share on other sites More sharing options...
Blue73 Posted December 31, 2018 Share Posted December 31, 2018 (edited) Hi Andrew, Here are my additions/changes made to switches.h. For your main code I've found regular polling is the best way to update the controls. 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 Switches.h.zip Sample Code DcsBios::Switch3Pos flapSw("FLAP_SW", 9, 10); unsigned int g_iCounter = 0; void PollAllControls() { flapSw.pollInputCurrent(); } void loop() { DcsBios::loop(); if (++g_iCounter > 60000) { g_iCounter = 0; PollAllControls(); } } Note: Doesn't work for toggle type controls as sending a repeated '1' to the sim tells it to toggle the control. Luckily these are rare. cheers John Edited December 31, 2018 by Blue73 Link to comment Share on other sites More sharing options...
WhoMadeWho Posted December 31, 2018 Author Share Posted December 31, 2018 Thanks again to Blue73 for the code! After adding his custom Switches.h and modifying my sketch, I was finally able to get DCS-BIOS to reflect the state of my switches at startup. Code from my sketch (Master Arm panel from the A10) /* Tell DCS-BIOS to use a serial connection and use interrupt-driven communication. The main program will be interrupted to prioritize processing incoming data. This should work on any Arduino that has an ATMega328 controller (Uno, Pro Mini, many others). */ #define DCSBIOS_IRQ_SERIAL #include "DcsBios.h" //// WARNING //// WARNING - using custom Switches.h so switch init reflects current switch positons at init //// WARNING // GUN/PAC GUNARM - SAFE - ARM DcsBios::Switch3Pos ahcpGunpac("AHCP_GUNPAC", 2, 3); // GND = Gray, 2 = White, 3 = Blue // Master Arm TRAIN - SAFE - ARM DcsBios::Switch3Pos ahcpMasterArm("AHCP_MASTER_ARM", 4, 5); // GND = Green + Purple, 4 = White, 5 = Orange // Laser Arm TRAIN - SAFE - ARM DcsBios::Switch3Pos ahcpLaserArm("AHCP_LASER_ARM", 6, 7); // GND = Purple + White, 6 = Blue, 7 = Orange // TGP OFF - ON DcsBios::Switch2Pos ahcpTgp("AHCP_TGP", 8); // GND = Brown, 8 = Yellow // Altimeter Source RADAR - DELTA - BARO DcsBios::Switch3Pos ahcpAltSce("AHCP_ALT_SCE", 9, 10); // GND = Gray, 9 = Blue, 10 = Purple // Hud Mode NIGHT - DAY DcsBios::Switch2Pos ahcpHudDaynight("AHCP_HUD_DAYNIGHT", 11); // GND = Green, 11 = Orange // Hud Mode STBY - NORM DcsBios::Switch2Pos ahcpHudMode("AHCP_HUD_MODE", 12); // GND = White, 12 = Yellow // CICU OFF - ON DcsBios::Switch2Pos ahcpCicu("AHCP_CICU", 14); // GND = White, 14 = Purple // JTRS OFF - ON DcsBios::Switch2Pos ahcpJtrs("AHCP_JTRS", 15); // GND = Orange, 15 = White // IFFCC OFF - TEST - ON DcsBios::Switch3Pos ahcpIffcc("AHCP_IFFCC", 16, 17); // GND = Brown + Green, 16 = Yellow, 17 = Blue unsigned int g_iCounter = 0; void PollAllControls() { ahcpGunpac.pollInputCurrent(); ahcpMasterArm.pollInputCurrent(); ahcpLaserArm.pollInputCurrent(); ahcpTgp.pollInputCurrent(); ahcpAltSce.pollInputCurrent(); ahcpHudDaynight.pollInputCurrent(); ahcpHudMode.pollInputCurrent(); ahcpCicu.pollInputCurrent(); ahcpJtrs.pollInputCurrent(); ahcpIffcc.pollInputCurrent(); } void setup() { DcsBios::setup(); } void loop() { DcsBios::loop(); if (++g_iCounter > 60000) { g_iCounter = 0; PollAllControls(); } } Link to comment Share on other sites More sharing options...
Bullant Posted December 31, 2018 Share Posted December 31, 2018 Thanks Blue, that works a treat. Intel i7 13700K @ 5.3 GHz / ASUS TUF Gaming Z490-Plus / 64 Gb G.Skill DDR4-3600 / RTX 4090 / 2TB Kingston KC3000 NVME / Win 10 x64 Pro / Pimax Crystal / WINWING F/A-18 HOTAS A-10C, AJS-37, AV-8B, F-4E, F-5E, F-14, F-15E, F-16, F/A-18C, F-86F, FC3, Christen Eagle 2, FW190D-9, Mosquito, P-47D, P-51D, Spitfire, AH-64D, KA-50, UH-1H Combined Arms, WWII Asset Pack, China Assets Pack, Super Carrier, Falklands Assets Nevada, Normandy, Persian Gulf, The Channel, Syria, Mariana Islands, South Atlantic, Sinai Link to comment Share on other sites More sharing options...
Blue73 Posted December 31, 2018 Share Posted December 31, 2018 Nice :) Thanks Blue, that works a treat. Link to comment Share on other sites More sharing options...
Hansolo Posted January 1, 2019 Share Posted January 1, 2019 Blue73, that is a very sweet solution sir. Thanks a lot for sharing. Happy New Year sir. Cheers Solo 132nd Virtual Wing homepage & 132nd Virtual Wing YouTube channel My DCS-BIOS sketches & Cockpit Album Link to comment Share on other sites More sharing options...
Blue73 Posted January 1, 2019 Share Posted January 1, 2019 Happy to help my fellow cockpit builders :) If anyone wants to reduce the delay to the minimum I had to use, I've found 4 ms to be the bottom end before outgoing messages are dropped. Another technique is you can assign a cockpit button state to force sync all your buttons, e.g. the battery switch. A change with the battery state causes all Arduino's to run the init cycle for 30 seconds. cheers John Blue73, that is a very sweet solution sir. Thanks a lot for sharing. Happy New Year sir. Cheers Solo Link to comment Share on other sites More sharing options...
Recommended Posts