Skip to content

Commit

Permalink
Throttle Added
Browse files Browse the repository at this point in the history
Throttle PWM added. T16000.M Support added. Limitation found
  • Loading branch information
zeplintwo committed Jul 18, 2021
1 parent 0038736 commit ac8ebbe
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 72 deletions.
29 changes: 17 additions & 12 deletions Analog_WSAD_Keymapings.ttm
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@
// KEYBIND SHOULD NOT BE CHANGED UNLESS YOU RUN A NON-STANDARD LAYOUT. IE YOU CHANGE THE DEFAULT KEYBOARD BINDS
//
//---------------------------------------------------------------------------
define ThrottleUp USB[0x15] //r throttle step up
define ThrottleDown USB[0x17] //t throttle step down
define PitchDown USB[0x16] //s pitch down, nose down
define PitchUp USB[0x1A] //w pitch up, nose up
define RollRight USB[0x07] //d roll right, roll clockwise
define RollLeft USB[0x04] //a roll left, roll anti-clockwise
define YawRight USB[0x08] //e yaw right, nose right
define YawLeft USB[0x14] //q yaw left, nose left
define ThrustUp USB[0x2c] //space accend, thrust upward
define ThrustDown USB[0x07] //c decend, thrust DOWN
define Brakes USB[0xE0] //left control/ctrl brakes, stoping thrust, aero brakes, retro thrust
define Vector USB[0x1B] //x toggle though vector trajectorys
define ThrottleUp USB[0x57] //numpad + throttle step up
define AltThrottleUp USB[0x55] //numpad * alternate throttle step up
define ThrottleDown USB[0x56] //numpad - throttle step down
define AltThrottleDown USB[0x54] //numpad / alternate throttle step down
define TrimInc USB[0x59] //numpad 1 trim increase step up
define TrimDecr USB[0x5A] //numpad 2 trim decrease step down
define PitchDown USB[0x16] //s pitch down, nose down
define PitchUp USB[0x1A] //w pitch up, nose up
define RollRight USB[0x07] //d roll right, roll clockwise
define RollLeft USB[0x04] //a roll left, roll anti-clockwise
define YawRight USB[0x08] //e yaw right, nose right
define YawLeft USB[0x14] //q yaw left, nose left
define ThrustUp USB[0x52] //up arrow translate, accend, stafe thrust up
define ThrustDown USB[0x51] //down arrow translate, decend, thrust down
define ThrustRight USB[0x4F] //right arrow translate, strafe,thrust right
define ThrustLeft USB[0x50] //left arrow translate, strafe,thrust left
define Brakes USB[0xE0] //left control/ctrl brakes, stoping thrust, aero brakes, retro thrust

//--------------------------------------------------------------------------------------------------------------------------------------------------------------//
// REFERENCE: USB KEY DEFINITIONS // //
Expand Down
12 changes: 6 additions & 6 deletions Analog_WSAD_Macros.ttm
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,16 @@ int SettingError(char side){
printf("Once done save and re-run the script.\xa");
printf("\xa");
printf("--------------------------- End Error ---------------------------\xa");
Abort();
}

int WarthogJoyBinds(){//Keybindings for the Warthog Joysick key assignments.
MapKeyIOUMD(&Joystick,TG1,0,0,0,0,0,0);
MapKeyIOUMD(&Joystick,TG2,0,0,0,0,0,0);
MapKeyIOUMD(&Joystick,S1,Vector,Vector,Vector,Vector,Vector,Vector);
MapKeyIOUMD(&Joystick,S2,L_CTL+'l',L_CTL+'l',L_CTL+'l',L_CTL+'l',L_CTL+'l',L_CTL+'l');
//MapKeyIOUMD(&Joystick,S3,0,0,0,0,0,0);
MapKey(&Joystick,S3,CHAIN(PULSE+'a',D(4000),PULSE+'b'));
//MapKeyIOUMD(&Joystick,S4,0,0,0,0,0,0);
MapKey(&Joystick,S4,EXEC("AxisToKey(100,1);"));
MapKeyIOUMD(&Joystick,S1,0,0,0,0,0,0);
MapKeyIOUMD(&Joystick,S2,0,0,0,0,0,0);
MapKeyIOUMD(&Joystick,S3,0,0,0,0,0,0);
MapKeyIOUMD(&Joystick,S4,0,0,0,0,0,0);
MapKeyIOUMD(&Joystick,H1U,0,0,0,0,0,0);
MapKeyIOUMD(&Joystick,H1D,0,0,0,0,0,0);
MapKeyIOUMD(&Joystick,H1L,0,0,0,0,0,0);
Expand All @@ -154,6 +153,7 @@ int WarthogThrottleBinds(){//Keybindings for the Warthog Throttle key assignment
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);

printf("---Warthog Throttle Binds Loaded.\xa \xa");
}

Expand Down
101 changes: 69 additions & 32 deletions Analog_WSAD_Pre-Axis_Macros.ttm
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
// MACRO VARIABLE INITALISATION
//---------------------------------------------------------------------------

int OnDutyTime = 0;

//----------
// Arrays
//----------

int LastJoy1[] = {-1,0,-1,0,-1,0}; //pos 0 joy1y negative,pos 1 joy1y positve, pos 2 Joy1x negative, pos 3 joy1x positive, pos 4 joy1z negative, pos 5 joy1z positve

int LastJoy2[] = {-1,0,-1,0,-1,0}; //pos 0 joy1y negative,pos 1 joy1y positve, pos 2 Joy1x negative, pos 3 joy1x positive, pos 4 joy1z negative, pos 5 joy1z positve
//---------------------------------------------------------------------------
// CUSTOM FUNCTIONS
//---------------------------------------------------------------------------
Expand All @@ -20,7 +18,7 @@ int AxisToKeySet(){
Joy1YValue = Joystick[JOYY];// Pitch
Joy1XValue = Joystick[JOYX];// Roll
Joy1HalfRange = A10JoyHalfRange;
MinRange1 = A10JoyAxisRange*DeadZoneCalPerc;
MinRange1 = A10JoyAxisRange*DeadZoneCalPerc1;
}
if (WarthogThrottle == 1){
//Mouse2XValue = Throttle[SCX];// Mouse up/down
Expand All @@ -29,7 +27,7 @@ int AxisToKeySet(){
Joy2XValue = Throttle[THR_LEFT];
Joy2ZValue = Throttle[THR_FC];
Joy2HalfRange = A10JoyAxisRange;
MinRange2 = A10JoyAxisRange*DeadZoneCalPerc;
MinRange2 = A10JoyAxisRange*DeadZoneCalPerc2;
}
if (T16000Right == 1){
Joy1YValue = T16000[JOYY]; // Pitch
Expand All @@ -50,48 +48,87 @@ int AxisToKeySet(){
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 \xa",DC);
//DeferCall(PWMTimeLenght,&ActKey,LOCK);
//printf("Duty Cycle : %i ,%c \xa",DC,PKey);
DeferCall(PWMTimeLenght,&ActKey,LOCK);
}

int PWMPress (int mag,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 array,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)/Joy1HalfRange)*PWMTimeLenght;
fduty = (abs(mag)/range)*PWMTimeLenght;
duty = fduty-fduty%1;
if (mag > 0){
//printf("PW Mag Cal Y+: %i, %i \xa",mag,duty);
return(DutyGreater(duty,pos1));
//printf("PW Mag Cal Axis+: %i, %i \xa",mag,duty);
return(DutyGreater(duty,array,pos1));
}
if (mag < 0){
//printf("PW Mag Cal Y-: %i, %i \xa",mag,duty);
return(DutyLess(duty,pos2));
//printf("PW Mag Cal Axis-: %i, %i \xa",mag,duty);
return(DutyLess(duty,array,pos2));
}
}

int DutyLess (int duty,int pos){// Math to dampen return to zero values
if (LastJoy1[pos] <= duty){
LastJoy1[pos] = duty;
//printf("Duty Less Ret: %i \xa",duty);
return duty;
int DutyLess (int duty,int array,int pos){// Math to dampen return to zero values
if (array == 0){
if (LastJoy1[pos] <= duty){
LastJoy1[pos] = duty;
//printf("Duty Less Ret: %i \xa",duty);
return duty;
}
else {
LastJoy1[pos] = duty;
//printf("Duty Less Disc: %i \xa",duty);
return 0;
}
}
else {
LastJoy1[pos] = duty;
//printf("Duty Less Disc: %i \xa",duty);
return 0;
if (array == 1){
if (LastJoy2[pos] <= duty){
LastJoy2[pos] = duty;
//printf("Duty Less Ret: %i \xa",duty);
return duty;
}
else {
LastJoy2[pos] = duty;
//printf("Duty Less Disc: %i \xa",duty);
return 0;
}
}

}

int DutyGreater (int duty,int pos){// Math to dampen return to zero values
if (LastJoy1[pos] >= duty){
LastJoy1[pos] = duty;
//printf("Duty Greater Ret: %i \xa",duty);
return duty;
int DutyGreater (int duty,int array,int pos){// Math to dampen return to zero values
if (array == 0){
if (LastJoy1[pos] >= duty){
LastJoy1[pos] = duty;
//printf("Duty Greater Ret: %i \xa",duty);
return duty;
}
else{
LastJoy1[pos] = duty;
//printf("Duty Greater Disc: %i \xa",duty);
return 0;
}
}
else{
LastJoy1[pos] = duty;
//printf("Duty Greater Disc: %i \xa",duty);
return 0;
if (array == 1){
if (LastJoy2[pos] >= duty){
LastJoy2[pos] = duty;
//printf("Duty Greater Ret: %i \xa",duty);
return duty;
}
else{
LastJoy2[pos] = duty;
//printf("Duty Greater Disc: %i \xa",duty);
return 0;
}
}
}

int PulseFormer(int axis_value,int range,int array,int pos1,int pos2,word key1,word key2){
int onDutyTime = PWMPress(axis_value,range,array,pos1,pos2);
if (axis_value > 0){
AxisToKey (onDutyTime, key1);
//printf("Point 1+ > %i, %i, %x \xa",axis_value,onDutyTime,key1);
}
if (axis_value < 0){
AxisToKey (abs(onDutyTime), key2);
//printf("Point 1- > %i, %i, %x \xa",axis_value,abs(onDutyTime),key2);
}
}
35 changes: 15 additions & 20 deletions Analog_WSAD_Profile.tmc
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,24 @@ int EventHandle(int type, alias o, int x)

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 (Joy1YValue < (-MinRange1) | Joy1YValue > MinRange1){PulseFormer(Joy1YValue,Joy1HalfRange,0,0,1,PitchUp,PitchDown);}//Joystick Y axis
if (Joy1XValue < (-MinRange1) | Joy1XValue > MinRange1){PulseFormer(Joy1XValue,Joy1HalfRange,0,2,3,RollRight,RollLeft);}//Joystick X axis

if (Joy1YValue < (-MinRange1) | Joy1YValue > MinRange1){//Joystick Y axis
OnDutyTime = PWMPress(Joy1YValue,0,1);
if (OnDutyTime > 0){
AxisToKey (OnDutyTime, PitchUp);
//printf("Point 1 > %i, %i \xa",Joy1YValue,OnDutyTime);
}
if (OnDutyTime < 0){
AxisToKey (abs(OnDutyTime), PitchDown);
//printf("Point 1 > %i, %i \xa",Joy1YValue,abs(OnDutyTime));
}
if (T16000Right == 1) {
if (Joy1ZValue < (-MinRange1) | Joy1ZValue > MinRange1){PulseFormer(Joy1ZValue,Joy1HalfRange,0,4,5,YawRight,YawLeft);}//Joystick Z axis
}

if (WarthogThrottle == 1){
if (Joy2YValue < (-MinRange2) | Joy2YValue > MinRange2){PulseFormer(Joy2YValue,Joy2HalfRange,1,0,1,ThrottleUp,ThrottleDown);}//A10 Throttle Y axis
if (Joy2XValue < (-MinRange2) | Joy2XValue > MinRange2){PulseFormer(Joy2XValue,Joy2HalfRange,1,2,3,AltThrottleUp,AltThrottleDown);}//A10 Throttle X Axis
if (Joy2ZValue < (-MinRange2) | Joy2ZValue > MinRange2){PulseFormer(Joy2ZValue,Joy2HalfRange,1,2,3,TrimInc,TrimDecr);}//A10 Throttle Z Axis
}

if (Joy1XValue < (-MinRange1) | Joy1XValue > MinRange1){//Joystick X axis
OnDutyTime = PWMPress(Joy1XValue,3,4);
if (OnDutyTime > 0){
AxisToKey (OnDutyTime, RollRight);
//printf("Point 1 > %i, %i \xa",Joy1XValue,OnDutyTime);
}
if (OnDutyTime < 0){
AxisToKey (abs(OnDutyTime), RollLeft);
//printf("Point 1 > %i, %i \xa",Joy1XValue,OnDutyTime);
}
if (T16000Left == 1){
if (Joy2YValue < (-MinRange2) | Joy2YValue > MinRange2){PulseFormer(Joy2YValue,Joy2HalfRange,0,0,1,ThrottleUp,ThrottleDown);}//Joystick Y axis
if (Joy2XValue < (-MinRange2) | Joy2XValue > MinRange2){PulseFormer(Joy2XValue,Joy2HalfRange,0,2,3,TranslateRight,TranslateLeft);}//Joystick X axis
if (Joy2ZValue < (-MinRange2) | Joy2ZValue > MinRange2){PulseFormer(Joy2ZValue,Joy2HalfRange,0,4,5,ThrustUp,ThrustDown);}//Joystick Z axis
}
}
}
4 changes: 2 additions & 2 deletions Analog_WSAD_User_Settings.ttm
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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 DeadZoneCalPerc = 0.05; //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.10; //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; //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.
//---------------------------------------------------------------------------

0 comments on commit ac8ebbe

Please sign in to comment.