Lowlyslows Posted December 30, 2022 Author Posted December 30, 2022 Ok, so I went back to the basics. I don't fully understand why we were doing the code the way you suggested and that's because I am so new to coding. But I did learn a ton! I have figured out how to make the switch state of the FLIR switch drive when the LTD/R switch can power up the electromagnet. When the FLIR is ON and the LTD/R switch is moved to ARM the electromagnet energizes. When I moved either the FLIR to STBY or the LTD/R switch to SAFE the electromagnet de-energizes. Two Things: 1) I still have no idea how to get the logic from the F18 module to drive this. The A10 with the same code I started with works just fine but the F18 doesn't for some reason. I am not any closer to figuring out how to get the LTD/R switch to move to SAFE after an auto lasing bombing run. 2) How do I get the code to read the status of something. Example would be Right Generator Control Switch set to NORM (output integer 1) which would allow the LTD/R switch to energize the electromagnet. 3) How would I tie that code into what I have that's working except for #1 above? Code below: #define DCSBIOS_IRQ_SERIAL #include "DcsBios.h" #define Coil 6 // Magnetic coil #define ltdsw 2 #define flrsw1 4 DcsBios::Switch2Pos ltdRSw("LTD_R_SW", 2); //LTD ARM/SAFE DcsBios::Switch2Pos lstNflrSw("LST_NFLR_SW", 3); //LST ON/OFF DcsBios::Switch3Pos flirSw("FLIR_SW", 4, 5); //FLIR ON/STBY/OFF void setup() { DcsBios::setup(); pinMode (Coil, OUTPUT); } void loop() { DcsBios::loop(); } //LTD Electromagnet Control void onFlirSwChange(unsigned int altCoilValue) { switch (altCoilValue){ case 0: digitalWrite(Coil, LOW); break; case 1: digitalWrite(Coil, LOW); break; case 2: int swState = digitalRead(ltdsw); if (swState == HIGH){ digitalWrite(Coil, LOW);} else {digitalWrite(Coil, HIGH);} break; } } DcsBios::IntegerBuffer flirSwBuffer(0x74c8, 0x3000, 12, onFlirSwChange);
No1sonuk Posted December 30, 2022 Posted December 30, 2022 (edited) I don't remember the code for interrogating a specific DCS parameter on demand without waiting for it to update. You could use the "onChange" code to set a global variable, then use that anywhere else in your code. e.g. Put this at the top under the defines: int rGenSwState = 0; // Right Generator Switch state for use in other routines That creates a global variable and defaults its value to 0. Then add this: void onRGenSwChange(unsigned int newValue) { rGenSwState = newValue; } DcsBios::IntegerBuffer rGenSwBuffer(0x74c4, 0x4000, 14, onRGenSwChange); That will change the rGenSwState variable's value to match the switch when it changes in DCS, and you can then use that in your other code routines to compare using if functions. You can access those "onChange" function descriptions in the control ref by switching to "advanced" view. Edited December 30, 2022 by No1sonuk
Lowlyslows Posted December 30, 2022 Author Posted December 30, 2022 2 hours ago, No1sonuk said: I don't remember the code for interrogating a specific DCS parameter on demand without waiting for it to update. You could use the "onChange" code to set a global variable, then use that anywhere else in your code. e.g. Put this at the top under the defines: int rGenSwState = 0; // Right Generator Switch state for use in other routines That creates a global variable and defaults its value to 0. Then add this: void onRGenSwChange(unsigned int newValue) { rGenSwState = newValue; } DcsBios::IntegerBuffer rGenSwBuffer(0x74c4, 0x4000, 14, onRGenSwChange); That will change the rGenSwState variable's value to match the switch when it changes in DCS, and you can then use that in your other code routines to compare using if functions. You can access those "onChange" function descriptions in the control ref by switching to "advanced" view. Awesome! I’ll give it a shot tonight. cheers
Lowlyslows Posted December 31, 2022 Author Posted December 31, 2022 (edited) 20 hours ago, No1sonuk said: I don't remember the code for interrogating a specific DCS parameter on demand without waiting for it to update. You could use the "onChange" code to set a global variable, then use that anywhere else in your code. e.g. Put this at the top under the defines: int rGenSwState = 0; // Right Generator Switch state for use in other routines That creates a global variable and defaults its value to 0. Then add this: void onRGenSwChange(unsigned int newValue) { rGenSwState = newValue; } DcsBios::IntegerBuffer rGenSwBuffer(0x74c4, 0x4000, 14, onRGenSwChange); That will change the rGenSwState variable's value to match the switch when it changes in DCS, and you can then use that in your other code routines to compare using if functions. You can access those "onChange" function descriptions in the control ref by switching to "advanced" view. ok, I added the code. If the right gen is OFF then the electromagnet doesn't energize. If the right gen is NORM (ON) then the electromagnet energizes when the LTD/R switch is moved up to ARM. The issue I am having now which is odd in 2 ways. 1) When I turn the right gen off the electromagnet stays energized. 2) If I shut the Main Battery OFF now with the below code, the electromagnet de-energizes. It doesn't do that with the original code, just since I added the above new code. Update 31DEC22: I swapped the generator code over to the LST switch. Works correctly. Why would the R Gen code work differently than the LST code? #define DCSBIOS_IRQ_SERIAL #include "DcsBios.h" #define Coil 6 // Magnetic coil #define ltdsw 2 #define flrsw1 5 int rGenSwState = 0; // Right Generator Switch state for use in other routines DcsBios::Switch2Pos ltdRSw("LTD_R_SW", 2); //LTD ARM/SAFE DcsBios::Switch2Pos lstNflrSw("LST_NFLR_SW", 3); //LST ON/OFF DcsBios::Switch3Pos flirSw("FLIR_SW", 4, 5); //FLIR ON/STBY/OFF void setup() { DcsBios::setup(); pinMode (Coil, OUTPUT); } void loop() { DcsBios::loop(); } //LTD Electromagnet Control void onLtdRSwChange(unsigned int altCoilValue) { switch (altCoilValue){ case 0: digitalWrite(Coil, LOW); break; case 1: int swState = digitalRead(flrsw1); if (swState == HIGH){ digitalWrite(Coil, LOW);} else if (rGenSwState == 0) { digitalWrite(Coil, LOW); } else {digitalWrite(Coil, HIGH);} break; } } DcsBios::IntegerBuffer ltdRSwBuffer(0x74c8, 0x4000, 14, onLtdRSwChange); void onRGenSwChange(unsigned int newValue) { rGenSwState = newValue; } DcsBios::IntegerBuffer rGenSwBuffer(0x74c4, 0x4000, 14, onRGenSwChange); Edited December 31, 2022 by Lowlyslows
Lowlyslows Posted January 4, 2023 Author Posted January 4, 2023 @No1sonuk Got the pro micro working. I thought it would help but not in this case and I think I figured out what is going on. BLUF: I need code that makes the switch act like a button press and release instead of a button press and hold. Issue is: I can only get the LTD switch to move to ARM. When I move the physical switch back from ARM to Safe, it stays at ARM. Also, I noticed something. When I use the physical switch to move the LTD game switch to ARM and then move the FLIR to STBY, the LTD electromagnet doesn't de-energize. If I use the keyboard and bind the ARM position to the S key, press the S key which moves the LTD game switch to ARM and release the S key, moving the FLIR switch to STBY will de-energize the LTD electromagnet. However, if I hold the S key down and then move the FLIR switch to STBY, the electromagnet stays energized. This leads me to believe that my physical switch is HOLDING the bind active and not allowing the logic to de-energize the electromagnet.
Lowlyslows Posted January 4, 2023 Author Posted January 4, 2023 (edited) added this to the Mods\aircraft\FA-18C\Input\FA-18C\joystick\default.lua just below line 840 Now the switch turns on and off with a single command on/off toggle switch (single pole). Now I need to figure out how to make the command to be momentary and not hold the bind. --added 1 line below 03JAN23 { down = tgp_commands.LtdrArm, up = tgp_commands.LtdrArm, cockpit_device_id = devices.TGP_INTERFACE, value_down = 1.0, value_up = 0.0, name = _('LTD/R Switch (special) - ON/OFF'), category = {_('Special For Joystick'), _('Right Console'), _('Sensor Panel')}}, Edited January 4, 2023 by Lowlyslows
No1sonuk Posted January 4, 2023 Posted January 4, 2023 2 hours ago, Lowlyslows said: @No1sonuk Got the pro micro working. I thought it would help but not in this case and I think I figured out what is going on. BLUF: I need code that makes the switch act like a button press and release instead of a button press and hold. Have a look at the "ActionButton " command in DCS-BIOS.
Recommended Posts