bavella1 Posted May 30, 2021 Share Posted May 30, 2021 (edited) Hello! I'm trying to write a small program fragment that programs the Pinkey switch on the throttle in such a way that the A / A and A / G modes or dogfight and missile override modes for the F-16 Viper in two layers always resets correctly. I would like to save the setting / resetting in DCS via DirectX buttons. The Shift key is the Pinkey Switch S3 on the joystick. First try Primary mode (no S3): PSB = A / G mode = DX20 PSF = A / A mode = DX21 -> PSM = reset = DX22 Secondary mode (S3in): PSB = DGF mode = DX23 PSF = MRM mode = DX24 -> PSM = reset = DX25 Unfortunately, my "else" condition doesn't seem to work. It is also possible that setting the flags does not work at all. A simple solution would of course be to set up the reset in the correct mode via S3in as well. However, this harbors the source of error that the user starts e.g. the DGF mode using S3in, but then sets the Pinkey back to the middle position without S3in - which would then start the A / A or A / G mode, for example. I would love to receive a tip on how to reset the middle Pinkey button depending on when the mode is triggered! Thanks in advance! bavella include "target.tmh" //here we link this file to the file that contains function code int DGF_Mode = 0; int MRM_Mode =0 ; int AA_Mode = 0; int AG_Mode = 0; int main() { Configure(&LMFD, MODE_EXCLUDED); Configure(&RMFD, MODE_EXCLUDED); Configure(&HCougar, MODE_EXCLUDED); Configure(&T16000, MODE_EXCLUDED); Configure(&TWCSThrottle, MODE_EXCLUDED); Configure(&TFRPRudder, MODE_EXCLUDED); Configure(&T16000L, MODE_EXCLUDED); Configure(&TFRPHARudder, MODE_EXCLUDED); if(Init(&EventHandle)) return 1; // declare the event handler, return on error //script and function functions go here SetKBRate(32, 50); SetKBLayout(KB_ENG); SetShiftButton(&Joystick, S3); ////////////////// AXIS CONTROLS ////////////////////////////// MapAxis(&Joystick, JOYX, DX_X_AXIS); SetSCurve(&Joystick, JOYX, 0, 2, 0, 0, 0); //a small center deadzone for the joystick; feel free to rem out this line MapAxis(&Joystick, JOYY, DX_Y_AXIS); SetSCurve(&Joystick, JOYY, 0, 2, 0, 0, 0); //a small center deadzone for the joystick; feel free to rem out this line MapAxis(&Throttle, THR_LEFT, DX_ZROT_AXIS); SetCustomCurve(&Throttle, THR_LEFT, LIST(0,1, 65,70, 65,70, 100,100)); //start at 1% for idle cuttoff & create a deadzone between 65% and 75% for AB MapAxis(&Throttle, THR_RIGHT, DX_Z_AXIS); SetCustomCurve(&Throttle, THR_RIGHT, LIST(0,1, 65,70, 65,70, 100,100)); //start at 1% for idle cuttoff & create a deadzone between 65% and 75% for AB MapAxis(&Throttle, SCX, DX_XROT_AXIS); SetSCurve(&Throttle, SCX, 0, 10, 0, 0, -1); //Negative number at the end reduces the sensitivity of the cursor X-axis MapAxis(&Throttle, SCY, DX_YROT_AXIS); SetSCurve(&Throttle, SCY, 0, 10, 0, 0, -1); //Negative number at the end reduces the sensitivity of the cursor Y-axis MapAxis(&Throttle, THR_FC, DX_SLIDER_AXIS); SetSCurve(&Throttle, THR_FC, 0, 0, 0, 5, -1); //Reduce sensitivity in the center //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////// THROTTLE KEY MAPPING ////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ----- PS -- Pinky Switch / Throttle leftside ----- MapKeyIO(&Throttle, PSB, CHAIN(EXEC("DGF_Mode = 1;"), PULSE+DX23), CHAIN(EXEC("AG_Mode = 1;"), PULSE+DX20)); MapKeyIO(&Throttle, PSF, CHAIN(EXEC("MRM_Mode = 1;"), PULSE+DX24), CHAIN(EXEC("AA_Mode = 1;"), PULSE+DX21)); if("DGF_Mode = 1;" | "MRM_Mode = 1;") { MapKey(&Throttle, PSM, CHAIN(PULSE+DX25, EXEC("DGF_Mode = 0;"), EXEC("MRM_Mode = 0;"))); } else { MapKey(&Throttle, PSM, CHAIN(PULSE+DX22, EXEC("AG_Mode = 0;"), EXEC("AA_Mode = 0;"))); } } int EventHandle(int type, alias o, int x) { DefaultMapping(&o, x); } Edited May 30, 2021 by bavella1 Link to comment Share on other sites More sharing options...
speed-of-heat Posted May 30, 2021 Share Posted May 30, 2021 i'm a bit bank holiday sunday... but ... isn't either DGF or MRM always going to be true, so you will never get to else? SYSTEM SPECS: Hardware Intel Corei7-12700KF @ 5.1/5.3p & 3.8e GHz, 64Gb RAM, 4090 FE, Dell S2716DG, Virpil T50CM3 Throttle, WinWIng Orion 2 & F-16EX + MFG Crosswinds V2, Varjo Aero SOFTWARE: Microsoft Windows 11, VoiceAttack & VAICOM PRO Link to comment Share on other sites More sharing options...
bavella1 Posted May 30, 2021 Author Share Posted May 30, 2021 (edited) Should work, I think! - But doesn´t... In the picture red marked is the shifted Mode (Shift-Button =S3IN) and it should call - the DGF-Mode when Pinkey Switch Back is pressed - OR the MRM-Mode when Pinkey Switch Forward is pressed. Same for AG- or AA-Mode when S3 (Shift-Button =S3OUT) is not pressed (green). So there must be only one flag at time (DGF-Mode/MRM-Mode) OR (AG-Mode/AA-Mode) be "1". - I think... All flags are set to "0" at the beginning of the programm. I guess there is something wrong with setting the flags... Edited May 30, 2021 by bavella1 Link to comment Share on other sites More sharing options...
Lange_666 Posted May 31, 2021 Share Posted May 31, 2021 Just an idea... Can't you integrate the printf function to check the state of a flag while the script is running? Might be easier to debug that way (never used it myself). Win11 Pro 64-bit, Ryzen 5800X3D, Corsair H115i, Gigabyte X570S UD, EVGA 3080Ti XC3 Ultra 12GB, 64 GB DDR4 G.Skill 3600. Monitors: LG 27GL850-B27 2560x1440 + Samsung SyncMaster 2443 1920x1200, HOTAS: Warthog with Virpil WarBRD base, MFG Crosswind combat pedals, TrackIR4, Rift-S. Personal Wish List: A6 Intruder, Vietnam theater, decent ATC module, better VR performance! Link to comment Share on other sites More sharing options...
Svend_Dellepude Posted June 1, 2021 Share Posted June 1, 2021 (edited) I think that this line: if("DGF_Mode = 1;" | "MRM_Mode = 1;") should be: if("DGF_Mode == 1;" | "MRM_Mode == 1;") or simply: if("DGF_Mode;" | "MRM_Mode;") But the thing is that you are not using flags. Flags are char and just written like this char flag; you could try renaming the int to: int DGF_Mode; int MRM_Mode; int AA_Mode; int AG_Mode; But normally you use int as this: declare: int some_name; and the define it: some_name = EXEC(" if (flag) ActKey( KEYON+ PULSE+ DX25);"); And then you program some_name directly on your button. MapKey(Joystick, H3U, some_name); On a side note, if you use else if instead of else you can more precisely define the conditions of which you what the event to happen, leaving no other options to trigger the action than the ones you have defined. But you need to rewrite your script a bit. In your case there is no reason to use the AA and AG flags since they will be reset if mrm og dgf are not true, regardless. Edited June 1, 2021 by Svend_Dellepude [sIGPIC][/sIGPIC] Win10 64, Asus Maximus VIII Formula, i5 6600K, Geforce 980 GTX Ti, 32 GB Ram, Samsung EVO SSD. Link to comment Share on other sites More sharing options...
bavella1 Posted June 1, 2021 Author Share Posted June 1, 2021 (edited) It is really very difficult for me because I have a few but very little experience with programming languages. Maybe we should make it easier for now: I would like the Pinkey switch - Push it forward once and trigger e.g. DX25 - If it then comes back to the middle position, e.g. DX26 should be triggered - if it is pushed backwards, e.g. DX40 should be triggered - and if he !! well !! comes back to the middle position, DX41 should be triggered The middle position should trigger a different DX as a function of the previously operated forward or reverse position. I am familiar with the MapKeyR command, in the above example (without Shift) it would work. However, it no longer works if the operator can trigger shifted and non-shifted commands for the front and rearposition of this 3-way-switch, but in a stressful situation it should always be ensured that the center position always resets each of the 4 different modes. Hence my thought (not written down in syntax): (1) front / normal = flag MRM_Mode and PULSE + DX21 (2) front / shifted = flag AA_Mode and PULSE + DX22 (3) rear / normal = flag DGF_Mode and PULSE + DX23 (4) rear / shifted = flag AG_Mode and PULSE + DX24 ---> middle (a) IF flag = MRM_Mode THEN MRM_Mode = 0 and PULSE + DX25 (b) IF flag = DGF_Mode THEN DGF_Mode = 0 and PULSE + DX26 (c) IF flag = AA_Mode THEN AA_Mode = 0 and PULSE + DX27 (d) IF flag = AG_Mode THEN AG_Mode = 0 and PULSE + DX28 My thought is that the flags should control the reaction of the switch in the middle position. I don't seem to be able to send a DX button and set the flag at the same time with one switch position. It's probably not very difficult and I keep getting tangled up in my own spaghetti code ... Edited June 1, 2021 by bavella1 Link to comment Share on other sites More sharing options...
Svend_Dellepude Posted June 2, 2021 Share Posted June 2, 2021 (edited) Yes in your example the mapkeyR would do the trick. Just use a flag for two of the modes because the last two would be given if the flag is not on. But if I understand it correct then you might end up in a situation where you have the pinky lever in the back (A-G) and need to go in DGF mode Where you have to move to the center and back, which doesn't make much sense since MRM and DGF are override modes anyway. You probably have the boatswitch mapped to something else, but that's where I would place the MRM and DGF modes. Anyway, here is my solution: Declare the two flags: char MRM; char DGF; declare the function: int MRM_mode_ON; int MRM_mode_OFF; int DGF_mode_ON; int DGF_mode_OFF; define the function: MRM_mode_ON = EXEC(" MRM=1; ActKey( KEYON+ PULSE+ DX21);"); MRM_mode_OFF = EXEC(" MRM=0; ActKey( KEYON+ PULSE+ DX25);"); map your keys: MapKey(&Throttle, PSF, EXEC(" if (Joystick[S3]) ActKey( KEYON+ PULSE+ DX22 ); else ActKey( KEYON+ MRM_mode_ON);")); MapKeyR(&Throttle, PSF, EXEC(" if (MRM) ActKey( KEYON+ MRM_mode_OFF ); else ActKey( KEYON+PULSE+ DX27 );")); MapKey(&Joystick, S3, TEMPO( DXxx, 0, 400)); This way you can still use the S3 for a momentary function with a short press and release, but if you hold it, it will work as a modifier. Just wrote the lines for the pinky forward position, you just need to copy and do the same for the pinky back position and define the DGF mode. You can write this as purescript of course, I just never got around to learn it. This is written from memory, so it might not be copy/paste, but I hope you get the idea. Edited June 2, 2021 by Svend_Dellepude [sIGPIC][/sIGPIC] Win10 64, Asus Maximus VIII Formula, i5 6600K, Geforce 980 GTX Ti, 32 GB Ram, Samsung EVO SSD. Link to comment Share on other sites More sharing options...
bavella1 Posted June 2, 2021 Author Share Posted June 2, 2021 It works! - Many thanks to @Svend_Dellepude and @Lange_666 for the support, I learned a lot! include "target.tmh" char MRM; char DGF; char AA; char AG; int MRM_mode_ON; int MRM_mode_OFF; int DGF_mode_ON; int DGF_mode_OFF; int AA_mode_ON; int AA_mode_OFF; int AG_mode_ON; int AG_mode_OFF; //program startup int main() { Configure(&LMFD, MODE_EXCLUDED); Configure(&RMFD, MODE_EXCLUDED); Configure(&HCougar, MODE_EXCLUDED); Configure(&T16000, MODE_EXCLUDED); Configure(&TWCSThrottle, MODE_EXCLUDED); Configure(&TFRPRudder, MODE_EXCLUDED); Configure(&T16000L, MODE_EXCLUDED); Configure(&TFRPHARudder, MODE_EXCLUDED); if(Init(&EventHandle)) return 1; // declare the event handler, return on error SetKBRate(32, 50); SetKBLayout(KB_ENG); SetShiftButton(&Joystick, S3); MRM_mode_ON = EXEC(" MRM=1; ActKey( KEYON+ PULSE+ DX21);"); MRM_mode_OFF = EXEC(" MRM=0; ActKey( KEYON+ PULSE+ DX22);"); DGF_mode_ON = EXEC(" DGF=1; ActKey( KEYON+ PULSE+ DX23);"); DGF_mode_OFF = EXEC(" DGF=0; ActKey( KEYON+ PULSE+ DX24);"); AA_mode_ON = EXEC(" AA=1; ActKey( KEYON+ PULSE+ DX25);"); AA_mode_OFF = EXEC(" AA=0; ActKey( KEYON+ PULSE+ DX26);"); AG_mode_ON = EXEC(" AG=1; ActKey( KEYON+ PULSE+ DX27);"); AG_mode_OFF = EXEC(" AG=0; ActKey( KEYON+ PULSE+ DX28);"); MapKeyIO(&Throttle, PSF, AA_mode_ON, MRM_mode_ON); MapKeyIO(&Throttle, PSB, AG_mode_ON, DGF_mode_ON); MapKey(&Throttle, PSM, EXEC(" if (MRM) ActKey( KEYON+ MRM_mode_OFF ); else if (DGF) ActKey( KEYON+ DGF_mode_OFF ); else if (AA) ActKey( KEYON+ AA_mode_OFF ); else ActKey( KEYON+ AG_mode_OFF );")); } //event handler int EventHandle(int type, alias o, int x) { DefaultMapping(&o, x); //add event handling code here } Link to comment Share on other sites More sharing options...
Svend_Dellepude Posted June 2, 2021 Share Posted June 2, 2021 [sIGPIC][/sIGPIC] Win10 64, Asus Maximus VIII Formula, i5 6600K, Geforce 980 GTX Ti, 32 GB Ram, Samsung EVO SSD. Link to comment Share on other sites More sharing options...
Recommended Posts