Skip to content

Commit

Permalink
Polling solved
Browse files Browse the repository at this point in the history
  • Loading branch information
zeplintwo committed Jul 19, 2021
1 parent befb7b1 commit 7d0bd1e
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 103 deletions.
63 changes: 61 additions & 2 deletions Analog_WSAD_Macros.ttm
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,60 @@ int WarthogJoyBinds(){//Keybindings for the Warthog Joysick key assignments.
}

int WarthogThrottleBinds(){//Keybindings for the Warthog Throttle key assignments.
MapKeyIOUMD(&Throttle,SPDF,Brakes,Brakes,Brakes,Brakes,Brakes,Brakes);
MapKeyIOUMD(&Throttle,SPDM,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle,SPDB,Brakes,Brakes,Brakes,Brakes,Brakes,Brakes);
MapKeyIOUMD(&Throttle, MSP,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, MSU,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, MSR,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, MSD,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, MSL,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle,SPDF,Brakes,Brakes,Brakes,Brakes,Brakes,Brakes);
MapKeyIOUMD(&Throttle,SPDM,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle,SPDB,Brakes,Brakes,Brakes,Brakes,Brakes,Brakes);

MapKeyIOUMD(&Throttle, BSF,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, BSB,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, CHF,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, CHB,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, PSF,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, PSB,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, LTB,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, EFLNORM,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, EFRNORM,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, EOLMOTOR,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, EORMOTOR,0,0,0,0,0,0);
//MapKeyIOUMD(&Throttle, APUON,0,0,0,0,0,0); // Reserved for Analog WASD functaionality
MapKeyIOUMD(&Throttle, LDGH,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, FLAPU,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, FLAPD,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, EACON,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, RDRNRM,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, APENG,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, APPAT,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, APALT,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, IDLERON,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, IDLELON,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, EOLIGN,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, EORIGN,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, CSU,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, CSR,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, CSD,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, CSL,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, EFLOVER,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, EFROVER,0,0,0,0,0,0);
//MapKeyIOUMD(&Throttle, APUOFF,0,0,0,0,0,0); // Reserved for Analog WASD functaionality
MapKeyIOUMD(&Throttle, EACOFF,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, RDRDIS,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, APDIS,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, IDLEROFF,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, IDLELOFF,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, EOLNORM,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, EORNORM,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, FLAPM,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, BSM,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, CHM,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, PSM,0,0,0,0,0,0);
MapKeyIOUMD(&Throttle, APAH,0,0,0,0,0,0);
printf("---Warthog Throttle Binds Loaded.\xa \xa");
}

Expand All @@ -164,4 +214,13 @@ int T16LeftBinds(){
int T16RightBinds(){
printf("---T16000.m Right Binds Loaded.\xa \xa");
}


int initLEDController(){
ActKey(PULSE+KEYON+LED(&Throttle, LED_INTENSITY, 255)); // Initiate LED status below
ActKey(PULSE+KEYON+LED(&Throttle, LED_INTENSITY, 129)); // Set backlight for Throttle
ActKey(KEYON+PULSE+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED1)); // Analog WASD Function
ActKey(KEYON+PULSE+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED2));
ActKey(KEYON+PULSE+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED3));
ActKey(KEYON+PULSE+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED4));
ActKey(KEYON+PULSE+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED5));
}
77 changes: 55 additions & 22 deletions Analog_WSAD_Pre-Axis_Macros.ttm
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ JoyDevice LeftDev;

int AxisToKeySet(){
if (WarthogStick == 1){
RightDev.YValue = Joystick[JOYY];// Pitch
RightDev.XValue = Joystick[JOYX];// Roll
RightDev.YValue = Joystick[JOYY]; // Pitch
RightDev.XValue = Joystick[JOYX]; // Roll
RightDev.HalfRangeY = A10JoyHalfRange;
RightDev.HalfRangeX = A10JoyHalfRange;
RightDev.MinRangeY = A10JoyAxisRange*DeadZoneCalPerc1;
Expand All @@ -49,8 +49,8 @@ int AxisToKeySet(){
}

if (WarthogThrottle == 1){
//Mouse2XValue = Throttle[SCX];// Mouse up/down
//Mouse2YValue = Throttle[SCY];// Mouse left/right
//Mouse2XValue = Throttle[SCX]; // Mouse up/down
//Mouse2YValue = Throttle[SCY]; // Mouse left/right
LeftDev.YValue = Throttle[THR_RIGHT]; // Main Forward Thrust
LeftDev.XValue = Throttle[THR_LEFT];
LeftDev.ZValue = Throttle[THR_FC];
Expand Down Expand Up @@ -103,30 +103,16 @@ int AxisToKeySet(){
LeftDev.KeyNegZ = TrimInc;
LeftDev.KeyPosZ = TrimDecr;
}

RightDev.LastNegY = -1;
RightDev.LastPosY = 1;
RightDev.LastNegX = -1;
RightDev.LastPosX = 1;
RightDev.LastNegZ = -1;
RightDev.LastPosZ = 1;

LeftDev.LastNegY = -1;
LeftDev.LastPosY = 1;
LeftDev.LastNegX = -1;
LeftDev.LastPosX = 1;
LeftDev.LastNegZ = -1;
LeftDev.LastPosZ = 1;
}

int AxisToKey(int DC,short PKey){// Application of Dutycycle call to keypress
int AxisToKey(int DC,short PKey){ // Application of Dutycycle call to keypress
ActKey(LOCK+KEYON+PKey);
DeferCall((DC+TouchDelay),&ActKey,PKey);
//printf("Duty Cycle : %i ,%c \xa",DC,PKey);
DeferCall(PWMTimeLenght,&ActKey,LOCK);
}

int PWMPress (int mag,int range,int pos1,int pos2){// Math to convert Joystick Value to duty cycle in ms of a keypress. Dutycycle time is 100ms
int PWMPress (int mag,int range,int pos1,int pos2){ // Math to convert Joystick Value to duty cycle in ms of a keypress. Dutycycle time is 100ms
float fduty = 0.0;
int duty = 0;
fduty = (abs(mag)/range)*PWMTimeLenght;
Expand All @@ -141,7 +127,7 @@ int PWMPress (int mag,int range,int pos1,int pos2){// Math to convert Joystick V
}
}

int DutyLess (int duty,int pos){// Math to dampen return to zero values
int DutyLess (int duty,int pos){ // Math to dampen return to zero values
if (pos <= duty){
pos = duty;
//printf("Duty Less Ret: %i \xa",duty);
Expand All @@ -154,7 +140,7 @@ int DutyLess (int duty,int pos){// Math to dampen return to zero values
}
}

int DutyGreater (int duty,int pos){// Math to dampen return to zero values
int DutyGreater (int duty,int pos){ // Math to dampen return to zero values
if (pos >= duty){
pos = duty;
//printf("Duty Greater Ret: %i \xa",duty);
Expand All @@ -177,4 +163,51 @@ int PulseFormer(int axis_value,int range,int pos1,int pos2,word key1,word key2){
AxisToKey (abs(onDutyTime), key2);
//printf("Point 1- > %i, %i, %x \xa",axis_value,abs(onDutyTime),key2);
}
}

int MainPWMStart(){
AxisToKeySet(); // Set Device to variable calls
MapKey(&Throttle,APUON,CHAIN(REXEC(0,100,"PWMLogic();"),PULSE+LED(&Throttle, LED_ONOFF, LED_CURRENT+LED1))); // 100ms calls for the devices and turn on LED 1 for visual cue of activity
MapKey(&Throttle,APUOFF,CHAIN(EXEC("StopAutoRepeat(0);"),PULSE+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED1))); // kills 100ms calls to devices and turns off LED 1
}


int PWMLogic(){
AxisToKeySet();
if (RightDev.YValue < (-RightDev.MinRangeY) | RightDev.YValue > RightDev.MinRangeY){ //Joystick Y axis
PulseFormer(RightDev.YValue,RightDev.HalfRangeY,RightDev.LastNegY,RightDev.LastPosY,RightDev.KeyNegY,RightDev.KeyPosY);
}
if (RightDev.XValue < (-RightDev.MinRangeX) | RightDev.XValue > RightDev.MinRangeX){ //Joystick X axis
PulseFormer(RightDev.XValue,RightDev.HalfRangeX,RightDev.LastNegX,RightDev.LastPosX,RightDev.KeyNegX,RightDev.KeyPosX);
}

if (T16000Right == 1) { //T16000.m Extra axis for Yaw controle
if (RightDev.ZValue < (-RightDev.MinRangeZ) | RightDev.ZValue > RightDev.MinRangeZ){ //Joystick Z axis
PulseFormer(RightDev.ZValue,RightDev.HalfRangeZ,RightDev.LastNegZ,RightDev.LastPosZ,RightDev.KeyNegZ,RightDev.KeyPosZ);
}
}

if (WarthogThrottle == 1){
if (LeftDev.YValue < (-LeftDev.MinRangeY) | LeftDev.YValue > LeftDev.MinRangeY){ //A10 Throttle Y axis
PulseFormer(LeftDev.YValue,LeftDev.HalfRangeY,LeftDev.LastNegY,LeftDev.LastPosY,LeftDev.KeyNegY,LeftDev.KeyPosY);
}
if (LeftDev.XValue < (-LeftDev.MinRangeX) | LeftDev.XValue > LeftDev.MinRangeX){ //A10 Throttle X Axis
PulseFormer(LeftDev.XValue,LeftDev.HalfRangeX,LeftDev.LastNegX,LeftDev.LastPosX,LeftDev.KeyNegX,LeftDev.KeyPosX);
}
if (LeftDev.ZValue < (-LeftDev.MinRangeZ) | LeftDev.ZValue > LeftDev.MinRangeZ){ //A10 Throttle Z Axis
PulseFormer(LeftDev.ZValue,LeftDev.HalfRangeZ,LeftDev.LastNegZ,LeftDev.LastPosZ,LeftDev.KeyNegZ,LeftDev.KeyPosZ);
}
}

if (T16000Left == 1){
if (LeftDev.YValue < (-LeftDev.MinRangeY) | LeftDev.YValue > LeftDev.MinRangeY){ //Joystick Y axis
PulseFormer(LeftDev.YValue,LeftDev.HalfRangeY,LeftDev.LastNegY,LeftDev.LastPosY,LeftDev.KeyNegY,LeftDev.KeyPosY);
}
if (LeftDev.XValue < (-LeftDev.MinRangeX) | LeftDev.XValue > LeftDev.MinRangeX){ //Joystick X axis
PulseFormer(LeftDev.XValue,LeftDev.HalfRangeX,LeftDev.LastNegX,LeftDev.LastPosX,LeftDev.KeyNegX,LeftDev.KeyPosX);
}
if (LeftDev.ZValue < (-LeftDev.MinRangeZ) | LeftDev.ZValue > LeftDev.MinRangeZ){ //Joystick Z axis
PulseFormer(LeftDev.ZValue,LeftDev.HalfRangeZ,LeftDev.LastNegZ,LeftDev.LastPosZ,LeftDev.KeyNegZ,LeftDev.KeyPosZ);
}
}
}
59 changes: 12 additions & 47 deletions Analog_WSAD_Profile.tmc
Original file line number Diff line number Diff line change
Expand Up @@ -28,68 +28,33 @@ include "Analog_WSAD_User_Settings.ttm" //User editable setting for
include "Analog_WSAD_Pre-Axis_Macros.ttm" //macros for the Axis to Key with a dutycycle logic

//program startup
int main()
{
int main(){
//following lines turn off other thrustmaster stick
Configure(&HCougar, MODE_EXCLUDED);
Configure(&JoystickF18, MODE_EXCLUDED);
Configure(&LMFD, MODE_EXCLUDED);
Configure(&RMFD, MODE_EXCLUDED);
Configure(&TFRPRudder, MODE_EXCLUDED);
Configure(&TWCSThrottle, MODE_EXCLUDED);
Configure(&TFRPHARudder, MODE_EXCLUDED);
Configure(&TFRPHARudder, MODE_EXCLUDED);

//end of exclustions

if(Init(&EventHandle)) return 1; // declare the event handler, return on error
SetKBRate(PulseLength, DelayLength);
SetKBLayout(KB_ENG);

ControlAxisCurveSetup();
}
initLEDController();

if (AnalogWASD_Pre_axis == 1){ //Coding needed to make Joystick Axis control a key with a dutycycle
MainPWMStart();
}
}

//event handler
int EventHandle(int type, alias o, int x){
DefaultMapping(&o, x);
//add event handling code here

if (AnalogWASD_Pre_axis == 1){ //Coding needed to make Joystick Axis control a key with a dutycycle
AxisToKeySet(); //Call to set Vars for Axis->Key

if (RightDev.YValue < (-RightDev.MinRangeY) | RightDev.YValue > RightDev.MinRangeY){ //Joystick Y axis
PulseFormer(RightDev.YValue,RightDev.HalfRangeY,RightDev.LastNegY,RightDev.LastPosY,RightDev.KeyNegY,RightDev.KeyPosY);
}
if (RightDev.XValue < (-RightDev.MinRangeX) | RightDev.XValue > RightDev.MinRangeX){ //Joystick X axis
PulseFormer(RightDev.XValue,RightDev.HalfRangeX,RightDev.LastNegX,RightDev.LastPosX,RightDev.KeyNegX,RightDev.KeyPosX);
}

if (T16000Right == 1) { //T16000.m Extra axis for Yaw controle
if (RightDev.ZValue < (-RightDev.MinRangeZ) | RightDev.ZValue > RightDev.MinRangeZ){ //Joystick Z axis
PulseFormer(RightDev.ZValue,RightDev.HalfRangeZ,RightDev.LastNegZ,RightDev.LastPosZ,RightDev.KeyNegZ,RightDev.KeyPosZ);
}
}

if (WarthogThrottle == 1){
if (LeftDev.YValue < (-LeftDev.MinRangeY) | LeftDev.YValue > LeftDev.MinRangeY){ //A10 Throttle Y axis
PulseFormer(LeftDev.YValue,LeftDev.HalfRangeY,LeftDev.LastNegY,LeftDev.LastPosY,LeftDev.KeyNegY,LeftDev.KeyPosY);
}
if (LeftDev.XValue < (-LeftDev.MinRangeX) | LeftDev.XValue > LeftDev.MinRangeX){ //A10 Throttle X Axis
PulseFormer(LeftDev.XValue,LeftDev.HalfRangeX,LeftDev.LastNegX,LeftDev.LastPosX,LeftDev.KeyNegX,LeftDev.KeyPosX);
}
if (LeftDev.ZValue < (-LeftDev.MinRangeZ) | LeftDev.ZValue > LeftDev.MinRangeZ){ //A10 Throttle Z Axis
PulseFormer(LeftDev.ZValue,LeftDev.HalfRangeZ,LeftDev.LastNegZ,LeftDev.LastPosZ,LeftDev.KeyNegZ,LeftDev.KeyPosZ);
}
}

if (T16000Left == 1){
if (LeftDev.YValue < (-LeftDev.MinRangeY) | LeftDev.YValue > LeftDev.MinRangeY){ //Joystick Y axis
PulseFormer(LeftDev.YValue,LeftDev.HalfRangeY,LeftDev.LastNegY,LeftDev.LastPosY,LeftDev.KeyNegY,LeftDev.KeyPosY);
}
if (LeftDev.XValue < (-LeftDev.MinRangeX) | LeftDev.XValue > LeftDev.MinRangeX){ //Joystick X axis
PulseFormer(LeftDev.XValue,LeftDev.HalfRangeX,LeftDev.LastNegX,LeftDev.LastPosX,LeftDev.KeyNegX,LeftDev.KeyPosX);
}
if (LeftDev.ZValue < (-LeftDev.MinRangeZ) | LeftDev.ZValue > LeftDev.MinRangeZ){ //Joystick Z axis
PulseFormer(LeftDev.ZValue,LeftDev.HalfRangeZ,LeftDev.LastNegZ,LeftDev.LastPosZ,LeftDev.KeyNegZ,LeftDev.KeyPosZ);
}
}
}
}
//add event handling code here
}

27 changes: 6 additions & 21 deletions Analog_WSAD_User_Settings.ttm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Part of Analog_WSAD_Profile#.# keybinds packages
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Settings Storage for Script Values
//---------------------------------------------------------------------------
Expand All @@ -13,7 +12,7 @@ define LongPressDelay 300 //Normal lenght delay sugest
// Default Vars for Scripting
//---------------------------------------------------------------------------

int JSDeadZone = 5; //is a percentage 0 to 100 this is a future proofing var use above 'DeadzoneCalPrec' to control Axis->Key dead zone.
int JSDeadZone = 5; //is a percentage 0 to 100 this is a future proofing var use below 'DeadzoneCalPrec#' to control Axis->Key dead zone.

//---------------------------------------------------------------------------
// Joystick Axis Curves
Expand All @@ -22,15 +21,17 @@ int JSDeadZone = 5; //is a percentage 0 to 100 t
short JSCurve[] = {7,0,20}; //{Progresive,Flat,Percision} must be between -32 and 32 as a whole number
short JSZoom[] = {0,0,-2}; //{Progresive,Flat,Percision} is a percentage 0 to 100. Negative increase accuracy at expence of range. Postive reduce accurace but compresses map to reduce throw on device axis.



//---------------------------------------------------------------------------
// User Configuration Settings
//---------------------------------------------------------------------------

// Ingame axis toggle profile
//
// set JSProfile to 0 for Zeplin's default profile or 1 for flat curvse ie strait lines or 2 for percision mode
// set ZepProfile to 0 for Zeplin's default profile or 1 for flat curvse ie strait lines or 2 for percision mode

int JSProfile = 0; //Default 0
int ZepProfile = 0; //Default 0

// Warthog Thrustmaster as right stick
//
Expand All @@ -56,22 +57,6 @@ short JSZoom[] = {0,0,-2}; //{Progresive,Flat,Percision

int AnalogWASD_Pre_axis = 1; //Default 1

//---------------------------------------------------------------------------
// Default Vars for Axis->Key DutyCycle
//---------------------------------------------------------------------------

int Joy1YValue = 0; //Var to hold and switch joysticks for Axis->Key DutyCycles
int Joy1XValue = 0; //Var to hold and switch joysticks for Axis->Key DutyCycles
int Joy1ZValue = 0; //Var to hold and switch joysticks for Axis->Key DutyCycles
int Joy1HalfRange = 1; //Var to hold and switch joysticks for Axis->Key DutyCycles
float MinRange1 = 0; //Calculated Deadzone for Axis->Key Dutycycle scripting.

int Joy2YValue = 0; //Var to hold and switch joysticks for Axis->Key DutyCycles
int Joy2XValue = 0; //Var to hold and switch joysticks for Axis->Key DutyCycles
int Joy2ZValue = 0; //Var to hold and switch joysticks for Axis->Key DutyCycles
int Joy2HalfRange = 1; //Var to hold and switch joysticks for Axis->Key DutyCycles
float MinRange2 = 0; //Calculated Deadzone for Axis->Key Dutycycle scripting.

//---------------------------------------------------------------------------
// Settings Storage for Axis->Key Values
//---------------------------------------------------------------------------
Expand All @@ -82,6 +67,6 @@ int TouchDelay = 25; //Release timer for the duty
int PWMTimeLenght = 100; //timing for full pulse to occure the total lenght of time for it duty in milliseconds (default is 100)
int A10JoyAxisRange = 65535; //full sweep values for joystick axis (default is 65535)
int A10JoyHalfRange = 32767; //half of the above full sweep value (default is 32767)
float DeadZoneCalPerc1 = 0.10; //(For Joystick) the percentage of values from axis to be ignored around center this is for axis to key dutycycle (default is 0.05) approxamatly 1600 on each side or 3200 total.
float DeadZoneCalPerc1 = 0.025; //(For Joystick) the percentage of values from axis to be ignored around center this is for axis to key dutycycle (default is 0.05) approxamatly 1600 on each side or 3200 total.
float DeadZoneCalPerc2 = 0.15; //(For Throttle) the percentage of values from axis to be ignored around center this is for axis to key dutycycle (default is 0.10) approxamatly 3200 on each side or 6400 total.
//---------------------------------------------------------------------------
Loading

0 comments on commit 7d0bd1e

Please sign in to comment.