Wiimote with Potinter Calibration

Wiimote tutorials, configurations and GPC scripts (FPS like in Nintendo Wii/WiiU).

Moderator: OFC-Giorgio

Wiimote with Potinter Calibration

Postby teddy18 » Fri Oct 22, 2021 7:55 pm

Settings

Titan two

Output Polling Rate 250 Hz
Input Poling Rate 1000 Hz

Bluetooth Two Conectiontable

Gtuner Air on

FFB UsbA on Check FFB Usbb off FFB Usbc off FFB Usbd off FFB Bta off FFB Btb off


How to Use Controls

With Controler inputs

Sensetivity Goes form 0 to 6 You can this Value form 1 to 7
Hold R3/RS/SR Press Dpad Up Sensetivity Up Press
Hold R3/RS/SR Press Dpad Down Sensetivity Down Press

Activate Wii Pointer
Hold R3/RS/SR Press Dpad Left Sensetivity Up Press
Hold R3/RS/SR Press Dpad Right Sensetivity Down Press

Activate Wii Pointer Wiimote Calibration
Hold PS/Xbox/Home/Guide + R3/RS/SR + L3/LS/SR

With Controler inputs Altaniative (with Keyboard) you need a Usb otg cabe plug Your Keyboard in Usb Porg

Sensetivity Goes form 0 to 6 You can this Value form 1 to 7 /Titan Two Changing the Light
Hold Key F and Press Key 1 or ! Sensetivity Up Press
Hold Key F and Press Key 2 or " Sensetivity Down Press

Activate Wii Pointer
Hold Key F and Press Key 3 or § Sensetivity Up Press
Hold Key F and Press Key 4 or $ Sensetivity Down Press

Activate Wii Pointer Wiimote Calibration
Press Key F4 If you are in Calibration Mode Titan Two Changing the Light if is Calibration done goes back to Blue Light

How to do

First Conect you wiimote to Titan two you need Bluetooth moudel
You have to have a Wii Sensorbar After you Conect your wiimote to Titan two you can Turn your Wii or Wii U on if you dont have a Sensorbar that works without Console
Recomend You have so Calibrat you sensobar an your Wii/Wii You
To place the Sensor Buttom up or Buttom Down
And the Sensetivity Sensorbar

Look on The Tv how the Pointer a showing and Flashing the pointer have to be the same same size

Controlls

Wii Nunchuk Left Stick
Wii Nunchuk Tap one Button C L1/LB/L
Wiimote Tap one + Or Tap Twice Wii Nunchuk Button C R1/RB/R
Wiimote + Tap Twice L1/LB/L+R1/RB/R For Cod Wiimote - - Square/X/Y
Wiimote Dpad Right R3/RS/SR
Wiimote Dpad Down Circle/B/A
Wiimote Home Triangle/Y/X
Wiimote Dpad Up Touch Click/View /Minus/Select/Back
For Ps4 and Ps5 Hold Wiimote Dpad Up move Wii Nunchuk Stick for Touch mimic

Wiimote Dpad Left L3/LS/SR
Wiimote A Cross/A/B
Wiimote 1 Options/Menu/Plus/Start
Wiimote 2 PS/Xbox/Home/Guide
Wiimote B R2/RT/ZR
wii nunchuk C L2/LT/ZL


Wiimote Hod + and Move wii nunchuk Stick in Direction like a dpad
1 DPad Up
2 DPad Right
3 DPad Down
4 DPad Left

Wii Mote Controlle Controlle ver 1.09
Remape Controle

Code: Select all
GIVRMP:030D10292A0600042602010E0805280F0727112A2A2A1516171825232A2A2A2A2A2A2A2A2A2A2A2A2A2A2A

Keybaord map

Code: Select all
GIVKMAP:09051E091F0A200B210C3D003D083D05


Wiimote.GPH

Code: Select all
#ifndef Wiimote
#define Wiimote
#define init                      init
#define main                      main
 
 init {
    const uint8 cmap[] = { 0x03, 0x0D, 0x10, 0x29, 0x2A, 0x06, 0x00, 0x04, 0x26, 0x02, 0x01, 0x0E, 0x08, 0x05, 0x28, 0x0F, 0x07, 0x27, 0x11, 0x2A, 0x2A, 0x2A, 0x15, 0x16, 0x17, 0x18, 0x25, 0x23, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A };remapper(cmap);
    const uint8 kmap[] = { 0x09, 0x05, 0x1E, 0x09, 0x1F, 0x0A, 0x20, 0x0B, 0x21, 0x0C, 0x3D, 0x00, 0x3D, 0x08, 0x3D, 0x05 };keymapping(kmap);
}
 
main
{
    if(get_val(STICK_2_X) >= 50.0 && get_actual(PADDLE_4) > 0.0) {
        set_val(BUTTON_13, 100.0);
    }
    if(get_val(STICK_2_X) <= -50.0 && get_actual(PADDLE_4) > 0.0) {
        set_val(BUTTON_12, 100.0);
    }
    if(get_val(STICK_2_Y) >= 50.0 && get_actual(PADDLE_4) > 0.0) {
        set_val(BUTTON_11, 100.0);
    }
    if(get_val(STICK_2_Y) <= -50.0 && get_actual(PADDLE_4) > 0.0) {
        set_val(BUTTON_10, 100.0);
    }
}
#endif


Code: Select all
#pragma METAINFO("Wiimote with Potinter Calibration", 1,9, "mss1988 & teddy18")
#include <switch.gph>
#include "Wiimote.gph"
 
/*
<cfgdesc>
 
[Gyro Aiming Activation]
byteoffset = 0
bitsize    = 8
control    = checkbox
default    = 0
item       = On L1/LB
 
[Gyro Aiming Activation2]
group      = true
groupcol = true
byteoffset = 1
bitsize    = 8
control    = checkbox
default    = 1
item       = On L2/LT
 
[Gyro Aiming Activation3]
group      = true
groupcol = true
byteoffset = 2
bitsize    = 8
control    = checkbox
default    = 0
item       = On R1/RB
 
[Gyro Aiming Activation4]
group      = true
groupcol = true
byteoffset = 3
bitsize    = 8
control    = checkbox
default    = 1
item       = On R2/RT
 
[Gyro Aiming Activation5]
group      = true
groupcol = true
byteoffset = 4
bitsize    = 8
control    = checkbox
default    = 0
item       = Always On
 
[Sensitivity]
group      = false
shortdesc  = Base sensitivity X
byteoffset = 5
bitsize    = 32
control    = spinboxf
default    = 200
minimum    = 10
maximum    = 20000
step       = 1
decimals   = 2
 
[SensitivityY]
group      = true
groupcol = true
shortdesc  = Base sensitivity Y
byteoffset = 9
bitsize    = 32
control    = spinboxf
default    = 200
minimum    = 10
maximum    = 20000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers]
group      = false
groupcol = false
shortdesc  = Active Sensitivity Multiplier:
byteoffset = 13
bitsize    = 8
control    = slider
default    = 3
minimum    = 1
maximum    = 7
step       = 1
 
[Sensitivity Multipliers1]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 1:
byteoffset = 14
bitsize    = 32
control    = spinboxf
default    = 50
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers2]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 2:
byteoffset = 18
bitsize    = 32
control    = spinboxf
default    = 75
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers3]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 3:
byteoffset = 22
bitsize    = 32
control    = spinboxf
default    = 100
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers4]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 4:
byteoffset = 26
bitsize    = 32
control    = spinboxf
default    = 125
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers5]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 5:
byteoffset = 30
bitsize    = 32
control    = spinboxf
default    = 150
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers6]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 6:
byteoffset = 34
bitsize    = 32
control    = spinboxf
default    = 175
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers7]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 7:
byteoffset = 38
bitsize    = 32
control    = spinboxf
default    = 200
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Deadzones]
group      = false
shortdesc  = Ignore Gyro if Right Stick X is greater than:
byteoffset = 42
bitsize    = 32
control    = spinboxf
default    = 300
minimum    = 0
maximum    = 1000
step       = 1
decimals   = 1
 
[DeadzonesY]
group      = true
groupcol = false
shortdesc  = Ignore Gyro if Right Stick Y is greater than:
byteoffset = 46
bitsize    = 32
control    = spinboxf
default    = 300
minimum    = 0
maximum    = 1000
step       = 1
decimals   = 1
 
[DeadzonesD]
group      = true
groupcol = false
shortdesc  = Right Stick Diagonal Deadzone:
byteoffset = 50
bitsize    = 32
control    = spinboxf
default    = 13
minimum    = 0
maximum    = 200
step       = 1
decimals   = 2
 
[DeadzonesO]
group      = true
groupcol = false
shortdesc  = Right Stick Outer Deadzone:
byteoffset = 54
bitsize    = 32
control    = spinboxf
default    = 9200
minimum    = 0
maximum    = 10000
step       = 1
decimals   = 2
 
[DeadzonesI]
group      = true
groupcol = false
shortdesc  = Right Stick Inner Deadzone:
byteoffset = 58
bitsize    = 32
control    = spinboxf
default    = 3350
minimum    = 0
maximum    = 10000
step       = 1
decimals   = 2
 
[Calibration]
group      = false
groupcol = false
shortdesc  = Delay (ms):
byteoffset = 62
bitsize    = 32
control    = slider
default    = 3000
minimum    = 500
maximum    = 10000
step       = 500
 
[CalibrationS]
group      = true
groupcol = false
shortdesc  = Samples:
byteoffset = 66
bitsize    = 32
control    = slider
default    = 300
minimum    = 100
maximum    = 10000
step       = 100
 
</cfgdesc>
*/

 
//Constants
#define PAD_OTHER  0
uint8 PAD_IDS[5] = { 6, 5, 4, 2, 1 };
uint8 PAD_IDS_LENGHT = 5;
 
//Persistent memory addereses
#define ADDR_ACTIVATE_L1                     0
#define ADDR_ACTIVATE_L2                     1
#define ADDR_ACTIVATE_R1                     2
#define ADDR_ACTIVATE_R2                     3
#define ADDR_ACTIVATE_ALWAYS_ON             4
 
#define ADDR_BASE_SENSITIVITY_X             5
#define ADDR_BASE_SENSITIVITY_Y             9
#define ADDR_SENSITIVITY_MULTIPLIER_INDEX     13
#define ADDR_SENSITIVITY_MULTIPLIER_0         14
#define ADDR_SENSITIVITY_MULTIPLIER_1         18
#define ADDR_SENSITIVITY_MULTIPLIER_2         22
#define ADDR_SENSITIVITY_MULTIPLIER_3         26
#define ADDR_SENSITIVITY_MULTIPLIER_4         30
#define ADDR_SENSITIVITY_MULTIPLIER_5         34
#define ADDR_SENSITIVITY_MULTIPLIER_6         38
 
#define ADDR_DEADZONE_X                        42
#define ADDR_DEADZONE_Y                        46
#define ADDR_DEADZONE_D                        50
 
#define ADDR_OUTER_DEADZONE                    54
#define ADDR_INNER_DEADZONE                    58
 
#define ADDR_CALIBRATION_DELAY                62
#define ADDR_CALIBRATION_SAMPLES            66
 
#define ADDR_CALIB_OTHER_X                     116
#define ADDR_CALIB_OTHER_Y                     120
#define ADDR_CALIB_OTHER_Z                     124
#define BUTTON PADDLE_1
#define BUTTON2 PADDLE_4
 
uint8 btn_timer, tap;
uint8 btn2_timer2, tap2;
 
#define LED_DELAY                            2000
 
//Variables
fix32 mCalibOffsetX = 0.0;
fix32 mCalibOffsetY = 0.0;
fix32 mCalibOffsetZ = 0.0;
 
bool mIsActivatedCalibrating = FALSE;
bool mIsActivatedIncreaseSensitivity = FALSE;
bool mIsActivatedDecreaseSensitivity = FALSE;
bool mIsActivatedLeds = FALSE;
 
fix32 mBaseSensitivityX = 35.0;
fix32 mBaseSensitivityY = 35.0;
uint8 mSensitivityMultiplierIndex = 2;
fix32 mSensitivityMultipliersArray[7] = { 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0 };
 
uint32 mCalibrationDelay = 3000;
uint32 mCalibrationSamples = 300;
uint32 mCalibrationCycleIndex = 0;
 
fix32 mDeadzoneX = 30.0// Deadzone GYRO_1_YZ Input
fix32 mDeadzoneY = 30.0// Deadzone GYRO_1_YX Input
fix32 mDeadzoneD = 0.13// Deadzone Diagonal input
 
fix32 mOuterDeadzone = 92.00;
fix32 mInnerDeadzone = 33.5;
 
bool mIsActivateL1 = FALSE;
bool mIsActivateL2 = TRUE;
bool mIsActivateR1 = FALSE;
bool mIsActivateR2 = TRUE;
bool mIsAlwaysOn = FALSE;
bool mIsMotionAimingOn = TRUE;
 
uint32 mTimeCounter = 0;
 
bool mIsActivatedDebugging = FALSE;
 
init
{
    pmem_load();
 
    printf("Values loaded:");
 
    pmem_read(ADDR_ACTIVATE_L1, &mIsActivateL1);
    printf("Activate L1: %d", mIsActivateL1);
    pmem_read(ADDR_ACTIVATE_L2, &mIsActivateL2);
    printf("Activate L2: %d", mIsActivateL2);
    pmem_read(ADDR_ACTIVATE_R1, &mIsActivateR1);
    printf("Activate R1: %d", mIsActivateR1);
    pmem_read(ADDR_ACTIVATE_R2, &mIsActivateR2);
    printf("Activate R2: %d", mIsActivateR2);
    pmem_read(ADDR_ACTIVATE_ALWAYS_ON, &mIsAlwaysOn);
    printf("Activate AlwaysOn: %d", mIsAlwaysOn);
 
    pmem_read(ADDR_BASE_SENSITIVITY_X, &mBaseSensitivityX);
    printf("Base sensitivity X: %f", mBaseSensitivityX);
    pmem_read(ADDR_BASE_SENSITIVITY_Y, &mBaseSensitivityY);
    printf("Base sensitivity Y: %f", mBaseSensitivityY);
 
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_INDEX, &mSensitivityMultiplierIndex);
    mSensitivityMultiplierIndex--;
    printf("Sensitivity multiplier index: %d", mSensitivityMultiplierIndex);
 
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_0, &mSensitivityMultipliersArray[0]);
    printf("Sensitivity multiplier [0]: %f", mSensitivityMultipliersArray[0]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_1, &mSensitivityMultipliersArray[1]);
    printf("Sensitivity multiplier [1]: %f", mSensitivityMultipliersArray[1]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_2, &mSensitivityMultipliersArray[2]);
    printf("Sensitivity multiplier [2]: %f", mSensitivityMultipliersArray[2]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_3, &mSensitivityMultipliersArray[3]);
    printf("Sensitivity multiplier [3]: %f", mSensitivityMultipliersArray[3]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_4, &mSensitivityMultipliersArray[4]);
    printf("Sensitivity multiplier [4]: %f", mSensitivityMultipliersArray[4]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_5, &mSensitivityMultipliersArray[5]);
    printf("Sensitivity multiplier [5]: %f", mSensitivityMultipliersArray[5]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_6, &mSensitivityMultipliersArray[6]);
    printf("Sensitivity multiplier [6]: %f", mSensitivityMultipliersArray[6]);
 
    pmem_read(ADDR_DEADZONE_X, &mDeadzoneX);
    printf("Deadzone X: %f", mDeadzoneX);
    pmem_read(ADDR_DEADZONE_Y, &mDeadzoneY);
    printf("Deadzone Y: %f", mDeadzoneY);
    pmem_read(ADDR_DEADZONE_D, &mDeadzoneD);
    printf("Deadzone D: %f", mDeadzoneD);
 
    pmem_read(ADDR_OUTER_DEADZONE, &mOuterDeadzone);
    printf("Outer Deadzone: %f", mOuterDeadzone);
    pmem_read(ADDR_INNER_DEADZONE, &mInnerDeadzone);
    printf("Inner Deadzone: %f", mInnerDeadzone);
 
    pmem_read(ADDR_CALIBRATION_DELAY, &mCalibrationDelay);
    printf("Calibration Delay: %d", mCalibrationDelay);
    pmem_read(ADDR_CALIBRATION_SAMPLES, &mCalibrationSamples);
    printf("Calibration Samples: %d", mCalibrationSamples);
 
    FetchCalibration();
}
 
main
{
    ResetLeds();
 
    ActivateIncreaseSensitivity(get_val(BUTTON_6) > 0.0 && get_prev(BUTTON_10) == 0.0 && get_actual(BUTTON_10) > 0.0);
    IncreaseSensitivity();
    ActivateDecreaseSensitivity(get_val(BUTTON_6) > 0.0 && get_prev(BUTTON_11) == 0.0 && get_actual(BUTTON_11) > 0.0);
    DecreaseSensitivity();
 
    ActivateCalibration(get_val(BUTTON_1) > 0.0 && get_val(BUTTON_6) > 0.0 && get_val(BUTTON_9) > 0.0);
    Calibrate();
 
    Debug();
 
    ToggleAlwaysOn(get_val(BUTTON_6) > 0.0 && get_prev(BUTTON_13) == 0.0 && get_actual(BUTTON_13) > 0.0);
    ToggleMotionAiming(get_val(BUTTON_6) > 0.0 && get_prev(BUTTON_12) == 0.0 && get_actual(BUTTON_12) > 0.0);
 
    MotionAiming(mIsMotionAimingOn && !mIsActivatedCalibrating && !mIsActivatedDebugging &&
                 (abs(get_val(STICK_1_X)) <= mDeadzoneX && (abs(get_val(STICK_1_Y)) <= mDeadzoneY)) &&
                    (mIsAlwaysOn ||
                    (mIsActivateL1 && (get_val(BUTTON_7) > 98.0)) ||
                    (mIsActivateL2 && (get_val(BUTTON_8) > 98.0)) ||
                    (mIsActivateR1 && (get_val(BUTTON_4) > 98.0)) ||
                    (mIsActivateR2 && (get_val(BUTTON_5) > 98.0))));
 
    AddInnerDeadzone();
    AddOuterDeadzone();
 
    MimicTouch(get_val(BUTTON_2) > 90.0 && GetPadType() != PAD_OTHER);
    if(btn_timer ) {
        btn_timer-=elapsed_time();
        if(!btn_timer){
            if(1==tap) combo_run(one);
            else if(2==tap) combo_run(two);
            tap=0;
        }
    }
    if(event_active(BUTTON)){
        if((++tap)) btn_timer = -1;
    }
    set_val(BUTTON, check_active(BUTTON, 120) ? (combo_stop(one), 100) : 0);
 
    if(btn2_timer2) {
        btn2_timer2-=elapsed_time();
        if(!btn2_timer2){
            if(1==tap2) combo_run(one);
            else if(2==tap2) combo_run(Button4and7);
            tap2=0;
        }
    }
    if(event_active(BUTTON2)){
        if((++tap2)) btn2_timer2 = -1;
    }
    set_val(BUTTON2, check_active(BUTTON2, 120) ? (combo_stop(R1), 100) : 0);
}
 
void ResetLeds()
{
    if(mIsActivatedLeds)
    {
        if(mTimeCounter > LED_DELAY)
        {
            led_reset();
            mTimeCounter = 0;
        }
        else
        {
            mTimeCounter += elapsed_time();
        }
    }
}
 
void ActivateIncreaseSensitivity(bool aIsActivated)
{
    if(aIsActivated)
    {
        if(mSensitivityMultiplierIndex < 6) //increase sensivity multiplier
            mIsActivatedIncreaseSensitivity = TRUE;
        else
        {
            SetLeds(7);
            mIsActivatedLeds = TRUE;
        }
    }
}
 
void IncreaseSensitivity()
{
    if(mIsActivatedIncreaseSensitivity)
    {
        mSensitivityMultiplierIndex = mSensitivityMultiplierIndex + 1;
        SetLeds(mSensitivityMultiplierIndex+1);
        SaveSensitivityIndex();
        mIsActivatedIncreaseSensitivity = FALSE;
        mIsActivatedLeds = TRUE;
    }       
}
 
void ActivateDecreaseSensitivity(bool aIsActivated)
{
    if(aIsActivated)
    {
        if(mSensitivityMultiplierIndex > 0) //decrease sensivity multiplier
            mIsActivatedDecreaseSensitivity = TRUE;
        else
        {
            SetLeds(0);
            mIsActivatedLeds = TRUE;
        }
    }
}
 
void DecreaseSensitivity()
{
    if(mIsActivatedDecreaseSensitivity)
    {
        mSensitivityMultiplierIndex = mSensitivityMultiplierIndex - 1;
        SetLeds(mSensitivityMultiplierIndex+1);
        SaveSensitivityIndex();
        mIsActivatedDecreaseSensitivity = FALSE;
        mIsActivatedLeds = TRUE;
    }
}
 
void ActivateCalibration(bool aIsActivated)
{
    if(aIsActivated && !mIsActivatedCalibrating)
    {
        mCalibOffsetX = 0.0;
        mCalibOffsetY = 0.0;
        mCalibOffsetZ = 0.0;
        mCalibrationCycleIndex = 0;
        mTimeCounter = 0;
        SetLeds(6);
        printf("Calibration started. Delay: %d, Samples: %d", mCalibrationDelay, mCalibrationSamples);
        mIsActivatedCalibrating = TRUE;
    }
}
 
void Calibrate()
{
    if(mIsActivatedCalibrating)
    {
        mTimeCounter += elapsed_time();
        if(mTimeCounter > mCalibrationDelay)
        {
            SetLeds(15);
            if(mCalibrationCycleIndex < mCalibrationSamples)
            {
                mCalibrationCycleIndex += 1;
 
                mCalibOffsetX += get_actual(GYRO_1_X);
                mCalibOffsetY += get_actual(GYRO_1_Y);
                mCalibOffsetZ += get_actual(GYRO_1_Z);
            }
            else
            {
                mCalibOffsetX /= (fix32)mCalibrationSamples;
                mCalibOffsetY /= (fix32)mCalibrationSamples;
                mCalibOffsetZ /= (fix32)mCalibrationSamples;
 
                StoreCalibration();
 
                mTimeCounter = 0;
                led_reset();
                mIsActivatedCalibrating = FALSE;
            }
        }
    }
}
 
void FetchCalibration()
{
    uint8 padType = GetPadType();
    pmem_load();
    switch(padType)
    {
        case PAD_OTHER:
            pmem_read(ADDR_CALIB_OTHER_X, &mCalibOffsetX);
            pmem_read(ADDR_CALIB_OTHER_Y, &mCalibOffsetY);
            pmem_read(ADDR_CALIB_OTHER_Z, &mCalibOffsetZ);
            printf("Other gamepad calibration. X: %f, Y: %f, Z: %f", mCalibOffsetX, mCalibOffsetY, mCalibOffsetZ);
        break;
    }
}
 
void StoreCalibration()
{
    uint8 padType = GetPadType();
    printf("Pad type set: %d", padType);
    switch(padType)
    {
        case PAD_OTHER:
            pmem_write(ADDR_CALIB_OTHER_X, mCalibOffsetX);
            pmem_write(ADDR_CALIB_OTHER_Y, mCalibOffsetY);
            pmem_write(ADDR_CALIB_OTHER_Z, mCalibOffsetZ);
            printf("Stored other gamepad calibration. X: %f, Y: %f, Z: %f", mCalibOffsetX, mCalibOffsetY, mCalibOffsetZ);
        break;
    }
    pmem_save();
}
 
uint8 GetPadType()
{
    uint8 status, protocol, device, i = 0;
    while(i < PAD_IDS_LENGHT)
    {
        status = port_status(PAD_IDS[i], &protocol, &device);
        if(status)
        {
            if(protocol == PROTOCOL_WII)
                return PAD_OTHER;
        }
        i++;
    }
    return(-1);
}
 
void Debug()
{
    if(mIsActivatedCalibrating || !mIsActivatedDebugging)
        return;
 
    set_val(GYRO_1_X, (get_val(GYRO_1_X) - mCalibOffsetX) * 1000.0);
    set_val(GYRO_1_Y, (get_val(GYRO_1_Y) - mCalibOffsetY) * 1000.0);
    set_val(GYRO_1_Z, (get_val(GYRO_1_Z) - mCalibOffsetZ) * 1000.0);
}
 
 
void ToggleAlwaysOn(bool aIsActivated)
{
    if(aIsActivated)
    {
        mIsAlwaysOn = !mIsAlwaysOn;
        pmem_write(ADDR_ACTIVATE_ALWAYS_ON, mIsAlwaysOn);
        pmem_save();
    }
}
 
void ToggleMotionAiming(bool aIsActivated)
{
    if(aIsActivated)
    {
        mIsMotionAimingOn = !mIsMotionAimingOn;
    }
}
 
void MotionAiming(bool aIsActivated)
{
    if(aIsActivated)
    {
        static fix32 accelX, accelY;
        static fix32 stickX, stickY;
        if(accelX != get_actual(GYRO_1_Z) || accelY != get_actual(GYRO_1_X))
        {
            accelX = get_actual(GYRO_1_Z);
            accelY = get_actual(GYRO_1_X);
 
            stickX = (accelX - mCalibOffsetZ) * mBaseSensitivityX * mSensitivityMultipliersArray[mSensitivityMultiplierIndex];
            stickY = (accelY - mCalibOffsetX) * mBaseSensitivityY * mSensitivityMultipliersArray[mSensitivityMultiplierIndex];
 
            fix32 signalX = (stickX < 0.0) ? (stickX = inv(stickX), -1.0) : (stickX > 0.0) ? 1.0 : 0.0;
            fix32 signalY = (stickY < 0.0) ? (stickY = inv(stickY), -1.0) : (stickY > 0.0) ? 1.0 : 0.0;
            fix32 angle = atan2(stickY, stickX);
 
            stickX = clamp(((mDeadzoneX * pow(cos(angle), mDeadzoneD)) + stickX) * signalX, -100.0, 100.0);
            stickY = clamp(((mDeadzoneY * pow(sin(angle), mDeadzoneD)) + stickY) * signalY, -100.0, 100.0);
        }
        set_val(STICK_1_X, stickX);
        set_val(STICK_1_Y, stickY);
        return;
    }
}
 
void AddInnerDeadzone()
{
    if(abs(get_val(STICK_1_Y)) > 5.00 && abs(get_val(STICK_1_Y)) < mInnerDeadzone)
        set_val(STICK_1_Y, 0.0);
 
    if(abs(get_val(STICK_1_X)) > 5.00 && abs(get_val(STICK_1_X)) < mInnerDeadzone)
        set_val(STICK_1_X, 0.0);
}
 
void AddOuterDeadzone()
{
    if(get_val(STICK_1_Y) <= mOuterDeadzone * -1.00)
        set_val(STICK_1_Y, -100);
 
    if(get_val(STICK_1_Y) >= mOuterDeadzone)
        set_val(STICK_1_Y, 100);
 
    if(get_val(STICK_1_X) <= mOuterDeadzone * -1.00)
        set_val(STICK_1_X, -100);
 
    if(get_val(STICK_1_X) >= mOuterDeadzone)
        set_val(STICK_1_X, 100);
}
 
 
void SaveSensitivityIndex()
{
    printf("Sensitivity Index: %d, Sensitivity Multiplier: %f", mSensitivityMultiplierIndex, mSensitivityMultipliersArray[mSensitivityMultiplierIndex]);
    pmem_write(ADDR_SENSITIVITY_MULTIPLIER_INDEX, mSensitivityMultiplierIndex);
    pmem_save();
}
 
void SetLeds(uint8 aLeds)
{
    if(aLeds == 1)
        aLeds = 0;
 
    fix32 bits[4];
    bits[0] = (aLeds & (1 << 0)) == 0 ? 0.0 : 100.0;
    bits[1] = (aLeds & (1 << 1)) == 0 ? 0.0 : 100.0;
    bits[2] = (aLeds & (1 << 2)) == 0 ? 0.0 : 100.0;
    bits[4] = (aLeds & (1 << 3)) == 0 ? 0.0 : 100.0;
 
    led_set(LED_1, bits[0], 800);
    led_set(LED_2, bits[1], 800);
    led_set(LED_3, bits[2], 800);
    led_set(LED_4, bits[3], 800);
}
 
void MimicTouch(bool aIsActivated)
{
    if(aIsActivated)
    {
        set_val(BUTTON_19, 100.0);
        set_val(POINT_1_X, get_actual(STICK_1_X));
        set_val(POINT_1_Y, get_actual(STICK_1_Y));
        set_val(STICK_1_X, 0.0);
        set_val(STICK_1_Y, 0.0);
    }
}
 
combo one {
  printf("1");
    set_val(BUTTON_7,100);
    wait(300);
}
combo two {
  printf("2");
    set_val(BUTTON_4,100);
    wait(300);
}
combo R1 {
  printf("2");
    set_val(BUTTON_4,100);
    wait(300);
}
combo Button4and7 {
  printf("2");
    set_val(BUTTON_4,100);
    set_val(BUTTON_7,100);
    wait(300);
}


Wii Mote Controlle Controlle ver 1.09.gpc
Wii Mote Controlle Controlle ver 1.09
(19.44 KiB) Downloaded 20 times

wii controller.gph
(636 Bytes) Downloaded 21 times
User avatar
teddy18
Lieutenant
Lieutenant
 
Posts: 336
Joined: Sun Jul 19, 2015 4:18 pm

Re: Wiimote with Potinter Calibration

Postby teddy18 » Sun Oct 24, 2021 1:48 am

Controlls

Wii Nunchuk Left Stick
Wii Nunchuk Tap One Button Z L1/LB/L
Wii Nunchuk Tap Twice Button Z R1/RB/R
Wii Nunchuk Hold Button Z L3/LS/SR
Wiimote + Tap One R1/RB/R
Wiimote + Tap Twice L1/LB/L+R1/RB/R For Cod Wiimote - - Square/X/Y
Wiimote Dpad Right R3/RS/SR
Wiimote Dpad Down Circle/B/A
Wiimote Home Triangle/Y/X
Wiimote Dpad Up Touch Click/View /Minus/Select/Back
For Ps4 and Ps5 Hold Wiimote Dpad Up move Wii Nunchuk Stick for Touch mimic
Wiimote Dpad Left L3/LS/SR
Wiimote A Cross/A/B
Wiimote 1 Options/Menu/Plus/Start
Wiimote 2 PS/Xbox/Home/Guide
Wiimote B R2/RT/ZR
Wii Nunchuk C L2/LT/ZL

Wiimote Hold Dpad Up + and Move Wii Nunchuk Stick in Direction like a dpad
1 DPad Up
2 DPad Right
3 DPad Down
4 DPad Left


Code: Select all
#pragma METAINFO("Wiimote with Potinter Calibration", 1,12, "teddy18")
#include <switch.gph>
#include "Wiimote.gph"
 
/*
<cfgdesc>
 
[Gyro Aiming Activation]
byteoffset = 0
bitsize    = 8
control    = checkbox
default    = 0
item       = On L1/LB
 
[Gyro Aiming Activation2]
group      = true
groupcol = true
byteoffset = 1
bitsize    = 8
control    = checkbox
default    = 1
item       = On L2/LT
 
[Gyro Aiming Activation3]
group      = true
groupcol = true
byteoffset = 2
bitsize    = 8
control    = checkbox
default    = 0
item       = On R1/RB
 
[Gyro Aiming Activation4]
group      = true
groupcol = true
byteoffset = 3
bitsize    = 8
control    = checkbox
default    = 1
item       = On R2/RT
 
[Gyro Aiming Activation5]
group      = true
groupcol = true
byteoffset = 4
bitsize    = 8
control    = checkbox
default    = 0
item       = Always On
 
[Sensitivity]
group      = false
shortdesc  = Base sensitivity X
byteoffset = 5
bitsize    = 32
control    = spinboxf
default    = 200
minimum    = 10
maximum    = 20000
step       = 1
decimals   = 2
 
[SensitivityY]
group      = true
groupcol = true
shortdesc  = Base sensitivity Y
byteoffset = 9
bitsize    = 32
control    = spinboxf
default    = 200
minimum    = 10
maximum    = 20000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers]
group      = false
groupcol = false
shortdesc  = Active Sensitivity Multiplier:
byteoffset = 13
bitsize    = 8
control    = slider
default    = 3
minimum    = 1
maximum    = 7
step       = 1
 
[Sensitivity Multipliers1]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 1:
byteoffset = 14
bitsize    = 32
control    = spinboxf
default    = 50
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers2]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 2:
byteoffset = 18
bitsize    = 32
control    = spinboxf
default    = 75
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers3]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 3:
byteoffset = 22
bitsize    = 32
control    = spinboxf
default    = 100
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers4]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 4:
byteoffset = 26
bitsize    = 32
control    = spinboxf
default    = 125
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers5]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 5:
byteoffset = 30
bitsize    = 32
control    = spinboxf
default    = 150
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers6]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 6:
byteoffset = 34
bitsize    = 32
control    = spinboxf
default    = 175
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers7]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 7:
byteoffset = 38
bitsize    = 32
control    = spinboxf
default    = 200
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Deadzones]
group      = false
shortdesc  = Ignore Gyro if Right Stick X is greater than:
byteoffset = 42
bitsize    = 32
control    = spinboxf
default    = 300
minimum    = 0
maximum    = 1000
step       = 1
decimals   = 1
 
[DeadzonesY]
group      = true
groupcol = false
shortdesc  = Ignore Gyro if Right Stick Y is greater than:
byteoffset = 46
bitsize    = 32
control    = spinboxf
default    = 300
minimum    = 0
maximum    = 1000
step       = 1
decimals   = 1
 
[DeadzonesD]
group      = true
groupcol = false
shortdesc  = Right Stick Diagonal Deadzone:
byteoffset = 50
bitsize    = 32
control    = spinboxf
default    = 13
minimum    = 0
maximum    = 200
step       = 1
decimals   = 2
 
[DeadzonesO]
group      = true
groupcol = false
shortdesc  = Right Stick Outer Deadzone:
byteoffset = 54
bitsize    = 32
control    = spinboxf
default    = 9200
minimum    = 0
maximum    = 10000
step       = 1
decimals   = 2
 
[DeadzonesI]
group      = true
groupcol = false
shortdesc  = Right Stick Inner Deadzone:
byteoffset = 58
bitsize    = 32
control    = spinboxf
default    = 3350
minimum    = 0
maximum    = 10000
step       = 1
decimals   = 2
 
[Calibration]
group      = false
groupcol = false
shortdesc  = Delay (ms):
byteoffset = 62
bitsize    = 32
control    = slider
default    = 3000
minimum    = 500
maximum    = 10000
step       = 500
 
[CalibrationS]
group      = true
groupcol = false
shortdesc  = Samples:
byteoffset = 66
bitsize    = 32
control    = slider
default    = 300
minimum    = 100
maximum    = 10000
step       = 100
 
</cfgdesc>
*/

 
//Constants
#define PAD_OTHER  0
uint8 PAD_IDS[5] = { 6, 5, 4, 2, 1 };
uint8 PAD_IDS_LENGHT = 5;
 
//Persistent memory addereses
#define ADDR_ACTIVATE_L1                     0
#define ADDR_ACTIVATE_L2                     1
#define ADDR_ACTIVATE_R1                     2
#define ADDR_ACTIVATE_R2                     3
#define ADDR_ACTIVATE_ALWAYS_ON             4
 
#define ADDR_BASE_SENSITIVITY_X             5
#define ADDR_BASE_SENSITIVITY_Y             9
#define ADDR_SENSITIVITY_MULTIPLIER_INDEX     13
#define ADDR_SENSITIVITY_MULTIPLIER_0         14
#define ADDR_SENSITIVITY_MULTIPLIER_1         18
#define ADDR_SENSITIVITY_MULTIPLIER_2         22
#define ADDR_SENSITIVITY_MULTIPLIER_3         26
#define ADDR_SENSITIVITY_MULTIPLIER_4         30
#define ADDR_SENSITIVITY_MULTIPLIER_5         34
#define ADDR_SENSITIVITY_MULTIPLIER_6         38
 
#define ADDR_DEADZONE_X                        42
#define ADDR_DEADZONE_Y                        46
#define ADDR_DEADZONE_D                        50
 
#define ADDR_OUTER_DEADZONE                    54
#define ADDR_INNER_DEADZONE                    58
 
#define ADDR_CALIBRATION_DELAY                62
#define ADDR_CALIBRATION_SAMPLES            66
 
#define ADDR_CALIB_OTHER_X                     116
#define ADDR_CALIB_OTHER_Y                     120
#define ADDR_CALIB_OTHER_Z                     124
 
#define PADDLE1              PADDLE_1
#define ACTION_NONE         0
#define ACTION_HOLD         1
#define ACTION_SINGLE_TAP   2
#define ACTION_DOUBLE_TAP   3
uint8 triggered_action;
uint8 process_action;
#define PADDLE4              PADDLE_4
#define ACTION_NONE2         0
#define ACTION_HOLD2         1
#define ACTION_SINGLE_TAP2   2
#define ACTION_DOUBLE_TAP2   3
uint8 triggered_action2;
uint8 process_action2;
 
#define LED_DELAY                            2000
 
//Variables
fix32 mCalibOffsetX = 0.0;
fix32 mCalibOffsetY = 0.0;
fix32 mCalibOffsetZ = 0.0;
 
bool mIsActivatedCalibrating = FALSE;
bool mIsActivatedIncreaseSensitivity = FALSE;
bool mIsActivatedDecreaseSensitivity = FALSE;
bool mIsActivatedLeds = FALSE;
 
fix32 mBaseSensitivityX = 35.0;
fix32 mBaseSensitivityY = 35.0;
uint8 mSensitivityMultiplierIndex = 2;
fix32 mSensitivityMultipliersArray[7] = { 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0 };
 
uint32 mCalibrationDelay = 3000;
uint32 mCalibrationSamples = 300;
uint32 mCalibrationCycleIndex = 0;
 
fix32 mDeadzoneX = 30.0// Deadzone GYRO_1_YZ Input
fix32 mDeadzoneY = 30.0// Deadzone GYRO_1_YX Input
fix32 mDeadzoneD = 0.13// Deadzone Diagonal input
 
fix32 mOuterDeadzone = 92.00;
fix32 mInnerDeadzone = 33.5;
 
bool mIsActivateL1 = FALSE;
bool mIsActivateL2 = TRUE;
bool mIsActivateR1 = FALSE;
bool mIsActivateR2 = TRUE;
bool mIsAlwaysOn = FALSE;
bool mIsMotionAimingOn = TRUE;
 
uint32 mTimeCounter = 0;
 
bool mIsActivatedDebugging = FALSE;
 
init
{
    pmem_load();
 
    printf("Values loaded:");
 
    pmem_read(ADDR_ACTIVATE_L1, &mIsActivateL1);
    printf("Activate L1: %d", mIsActivateL1);
    pmem_read(ADDR_ACTIVATE_L2, &mIsActivateL2);
    printf("Activate L2: %d", mIsActivateL2);
    pmem_read(ADDR_ACTIVATE_R1, &mIsActivateR1);
    printf("Activate R1: %d", mIsActivateR1);
    pmem_read(ADDR_ACTIVATE_R2, &mIsActivateR2);
    printf("Activate R2: %d", mIsActivateR2);
    pmem_read(ADDR_ACTIVATE_ALWAYS_ON, &mIsAlwaysOn);
    printf("Activate AlwaysOn: %d", mIsAlwaysOn);
 
    pmem_read(ADDR_BASE_SENSITIVITY_X, &mBaseSensitivityX);
    printf("Base sensitivity X: %f", mBaseSensitivityX);
    pmem_read(ADDR_BASE_SENSITIVITY_Y, &mBaseSensitivityY);
    printf("Base sensitivity Y: %f", mBaseSensitivityY);
 
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_INDEX, &mSensitivityMultiplierIndex);
    mSensitivityMultiplierIndex--;
    printf("Sensitivity multiplier index: %d", mSensitivityMultiplierIndex);
 
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_0, &mSensitivityMultipliersArray[0]);
    printf("Sensitivity multiplier [0]: %f", mSensitivityMultipliersArray[0]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_1, &mSensitivityMultipliersArray[1]);
    printf("Sensitivity multiplier [1]: %f", mSensitivityMultipliersArray[1]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_2, &mSensitivityMultipliersArray[2]);
    printf("Sensitivity multiplier [2]: %f", mSensitivityMultipliersArray[2]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_3, &mSensitivityMultipliersArray[3]);
    printf("Sensitivity multiplier [3]: %f", mSensitivityMultipliersArray[3]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_4, &mSensitivityMultipliersArray[4]);
    printf("Sensitivity multiplier [4]: %f", mSensitivityMultipliersArray[4]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_5, &mSensitivityMultipliersArray[5]);
    printf("Sensitivity multiplier [5]: %f", mSensitivityMultipliersArray[5]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_6, &mSensitivityMultipliersArray[6]);
    printf("Sensitivity multiplier [6]: %f", mSensitivityMultipliersArray[6]);
 
    pmem_read(ADDR_DEADZONE_X, &mDeadzoneX);
    printf("Deadzone X: %f", mDeadzoneX);
    pmem_read(ADDR_DEADZONE_Y, &mDeadzoneY);
    printf("Deadzone Y: %f", mDeadzoneY);
    pmem_read(ADDR_DEADZONE_D, &mDeadzoneD);
    printf("Deadzone D: %f", mDeadzoneD);
 
    pmem_read(ADDR_OUTER_DEADZONE, &mOuterDeadzone);
    printf("Outer Deadzone: %f", mOuterDeadzone);
    pmem_read(ADDR_INNER_DEADZONE, &mInnerDeadzone);
    printf("Inner Deadzone: %f", mInnerDeadzone);
 
    pmem_read(ADDR_CALIBRATION_DELAY, &mCalibrationDelay);
    printf("Calibration Delay: %d", mCalibrationDelay);
    pmem_read(ADDR_CALIBRATION_SAMPLES, &mCalibrationSamples);
    printf("Calibration Samples: %d", mCalibrationSamples);
 
    FetchCalibration();
}
 
main
{
    ResetLeds();
 
    ActivateIncreaseSensitivity(get_val(BUTTON_6) > 0.0 && get_prev(BUTTON_10) == 0.0 && get_actual(BUTTON_10) > 0.0);
    IncreaseSensitivity();
    ActivateDecreaseSensitivity(get_val(BUTTON_6) > 0.0 && get_prev(BUTTON_11) == 0.0 && get_actual(BUTTON_11) > 0.0);
    DecreaseSensitivity();
 
    ActivateCalibration(get_val(BUTTON_1) > 0.0 && get_val(BUTTON_6) > 0.0 && get_val(BUTTON_9) > 0.0);
    Calibrate();
 
    Debug();
 
    ToggleAlwaysOn(get_val(BUTTON_6) > 0.0 && get_prev(BUTTON_13) == 0.0 && get_actual(BUTTON_13) > 0.0);
    ToggleMotionAiming(get_val(BUTTON_6) > 0.0 && get_prev(BUTTON_12) == 0.0 && get_actual(BUTTON_12) > 0.0);
 
    MotionAiming(mIsMotionAimingOn && !mIsActivatedCalibrating && !mIsActivatedDebugging &&
                 (abs(get_val(STICK_1_X)) <= mDeadzoneX && (abs(get_val(STICK_1_Y)) <= mDeadzoneY)) &&
                    (mIsAlwaysOn ||
                    (mIsActivateL1 && (get_val(BUTTON_7) > 98.0)) ||
                    (mIsActivateL2 && (get_val(BUTTON_8) > 98.0)) ||
                    (mIsActivateR1 && (get_val(BUTTON_4) > 98.0)) ||
                    (mIsActivateR2 && (get_val(BUTTON_5) > 98.0))));
 
    AddInnerDeadzone();
    AddOuterDeadzone();
 
    MimicTouch(get_val(BUTTON_2) > 90.0 && GetPadType() != PAD_OTHER);
    if(!process_action) {if(event_active(PADDLE1)) {triggered_action = ACTION_SINGLE_TAP;if(time_release(PADDLE1) < 150) {triggered_action = ACTION_DOUBLE_TAP;process_action = TRUE;}}
        if(triggered_action == ACTION_SINGLE_TAP) {if(check_release(PADDLE1, 175)) {process_action = TRUE;}}
        if(check_active(PADDLE1, 200)) {triggered_action = ACTION_HOLD;process_action = TRUE;}} else if(check_release(PADDLE1, 250)) {process_action = FALSE;}
    if(process_action) {
        switch(triggered_action) {
            case ACTION_HOLD: {
                //
                //
                combo_run(LS);
            } break;
            case ACTION_SINGLE_TAP: {
                //
                //
                combo_run(L1);
            } break;
            case ACTION_DOUBLE_TAP: {
                //
                //
                combo_run(R1);
            } break;
        }
        triggered_action = ACTION_NONE;
    }
    if(!process_action2) {if(event_active(PADDLE4)) {triggered_action2 = ACTION_SINGLE_TAP2;if(time_release(PADDLE4) < 150) {triggered_action2 = ACTION_DOUBLE_TAP2;process_action2 = TRUE;}}
        if(triggered_action2 == ACTION_SINGLE_TAP2) {if(check_release(PADDLE4, 175)) {process_action2 = TRUE;}}
        if(check_active(PADDLE4, 200)) {triggered_action2 = ACTION_HOLD2;process_action2 = TRUE;}} else if(check_release(PADDLE4, 250)) {process_action2 = FALSE;}
    if(process_action2) {
        switch(triggered_action2) {
            case ACTION_HOLD2: {
                //
                //
                //
            } break;
            case ACTION_SINGLE_TAP2: {
                //
                //
                combo_run(RR);
            } break;
            case ACTION_DOUBLE_TAP2: {
                //
                //
                combo_run(L1R1);
            } break;
        }
        triggered_action2 = ACTION_NONE2;
    }
}
 
void ResetLeds()
{
    if(mIsActivatedLeds)
    {
        if(mTimeCounter > LED_DELAY)
        {
            led_reset();
            mTimeCounter = 0;
        }
        else
        {
            mTimeCounter += elapsed_time();
        }
    }
}
 
void ActivateIncreaseSensitivity(bool aIsActivated)
{
    if(aIsActivated)
    {
        if(mSensitivityMultiplierIndex < 6) //increase sensivity multiplier
            mIsActivatedIncreaseSensitivity = TRUE;
        else
        {
            SetLeds(7);
            mIsActivatedLeds = TRUE;
        }
    }
}
 
void IncreaseSensitivity()
{
    if(mIsActivatedIncreaseSensitivity)
    {
        mSensitivityMultiplierIndex = mSensitivityMultiplierIndex + 1;
        SetLeds(mSensitivityMultiplierIndex+1);
        SaveSensitivityIndex();
        mIsActivatedIncreaseSensitivity = FALSE;
        mIsActivatedLeds = TRUE;
    }       
}
 
void ActivateDecreaseSensitivity(bool aIsActivated)
{
    if(aIsActivated)
    {
        if(mSensitivityMultiplierIndex > 0) //decrease sensivity multiplier
            mIsActivatedDecreaseSensitivity = TRUE;
        else
        {
            SetLeds(0);
            mIsActivatedLeds = TRUE;
        }
    }
}
 
void DecreaseSensitivity()
{
    if(mIsActivatedDecreaseSensitivity)
    {
        mSensitivityMultiplierIndex = mSensitivityMultiplierIndex - 1;
        SetLeds(mSensitivityMultiplierIndex+1);
        SaveSensitivityIndex();
        mIsActivatedDecreaseSensitivity = FALSE;
        mIsActivatedLeds = TRUE;
    }
}
 
void ActivateCalibration(bool aIsActivated)
{
    if(aIsActivated && !mIsActivatedCalibrating)
    {
        mCalibOffsetX = 0.0;
        mCalibOffsetY = 0.0;
        mCalibOffsetZ = 0.0;
        mCalibrationCycleIndex = 0;
        mTimeCounter = 0;
        SetLeds(6);
        printf("Calibration started. Delay: %d, Samples: %d", mCalibrationDelay, mCalibrationSamples);
        mIsActivatedCalibrating = TRUE;
    }
}
 
void Calibrate()
{
    if(mIsActivatedCalibrating)
    {
        mTimeCounter += elapsed_time();
        if(mTimeCounter > mCalibrationDelay)
        {
            SetLeds(15);
            if(mCalibrationCycleIndex < mCalibrationSamples)
            {
                mCalibrationCycleIndex += 1;
 
                mCalibOffsetX += get_actual(GYRO_1_X);
                mCalibOffsetY += get_actual(GYRO_1_Y);
                mCalibOffsetZ += get_actual(GYRO_1_Z);
            }
            else
            {
                mCalibOffsetX /= (fix32)mCalibrationSamples;
                mCalibOffsetY /= (fix32)mCalibrationSamples;
                mCalibOffsetZ /= (fix32)mCalibrationSamples;
 
                StoreCalibration();
 
                mTimeCounter = 0;
                led_reset();
                mIsActivatedCalibrating = FALSE;
            }
        }
    }
}
 
void FetchCalibration()
{
    uint8 padType = GetPadType();
    pmem_load();
    switch(padType)
    {
        case PAD_OTHER:
            pmem_read(ADDR_CALIB_OTHER_X, &mCalibOffsetX);
            pmem_read(ADDR_CALIB_OTHER_Y, &mCalibOffsetY);
            pmem_read(ADDR_CALIB_OTHER_Z, &mCalibOffsetZ);
            printf("Other gamepad calibration. X: %f, Y: %f, Z: %f", mCalibOffsetX, mCalibOffsetY, mCalibOffsetZ);
        break;
    }
}
 
void StoreCalibration()
{
    uint8 padType = GetPadType();
    printf("Pad type set: %d", padType);
    switch(padType)
    {
        case PAD_OTHER:
            pmem_write(ADDR_CALIB_OTHER_X, mCalibOffsetX);
            pmem_write(ADDR_CALIB_OTHER_Y, mCalibOffsetY);
            pmem_write(ADDR_CALIB_OTHER_Z, mCalibOffsetZ);
            printf("Stored other gamepad calibration. X: %f, Y: %f, Z: %f", mCalibOffsetX, mCalibOffsetY, mCalibOffsetZ);
        break;
    }
    pmem_save();
}
 
uint8 GetPadType()
{
    uint8 status, protocol, device, i = 0;
    while(i < PAD_IDS_LENGHT)
    {
        status = port_status(PAD_IDS[i], &protocol, &device);
        if(status)
        {
            if(protocol == PROTOCOL_WII)
                return PAD_OTHER;
        }
        i++;
    }
    return(-1);
}
 
void Debug()
{
    if(mIsActivatedCalibrating || !mIsActivatedDebugging)
        return;
 
    set_val(GYRO_1_X, (get_val(GYRO_1_X) - mCalibOffsetX) * 1000.0);
    set_val(GYRO_1_Y, (get_val(GYRO_1_Y) - mCalibOffsetY) * 1000.0);
    set_val(GYRO_1_Z, (get_val(GYRO_1_Z) - mCalibOffsetZ) * 1000.0);
}
 
 
void ToggleAlwaysOn(bool aIsActivated)
{
    if(aIsActivated)
    {
        mIsAlwaysOn = !mIsAlwaysOn;
        pmem_write(ADDR_ACTIVATE_ALWAYS_ON, mIsAlwaysOn);
        pmem_save();
    }
}
 
void ToggleMotionAiming(bool aIsActivated)
{
    if(aIsActivated)
    {
        mIsMotionAimingOn = !mIsMotionAimingOn;
    }
}
 
void MotionAiming(bool aIsActivated)
{
    if(aIsActivated)
    {
        static fix32 accelX, accelY;
        static fix32 stickX, stickY;
        if(accelX != get_actual(GYRO_1_Z) || accelY != get_actual(GYRO_1_X))
        {
            accelX = get_actual(GYRO_1_Z);
            accelY = get_actual(GYRO_1_X);
 
            stickX = (accelX - mCalibOffsetZ) * mBaseSensitivityX * mSensitivityMultipliersArray[mSensitivityMultiplierIndex];
            stickY = (accelY - mCalibOffsetX) * mBaseSensitivityY * mSensitivityMultipliersArray[mSensitivityMultiplierIndex];
 
            fix32 signalX = (stickX < 0.0) ? (stickX = inv(stickX), -1.0) : (stickX > 0.0) ? 1.0 : 0.0;
            fix32 signalY = (stickY < 0.0) ? (stickY = inv(stickY), -1.0) : (stickY > 0.0) ? 1.0 : 0.0;
            fix32 angle = atan2(stickY, stickX);
 
            stickX = clamp(((mDeadzoneX * pow(cos(angle), mDeadzoneD)) + stickX) * signalX, -100.0, 100.0);
            stickY = clamp(((mDeadzoneY * pow(sin(angle), mDeadzoneD)) + stickY) * signalY, -100.0, 100.0);
        }
        set_val(STICK_1_X, stickX);
        set_val(STICK_1_Y, stickY);
        return;
    }
}
 
void AddInnerDeadzone()
{
    if(abs(get_val(STICK_1_Y)) > 5.00 && abs(get_val(STICK_1_Y)) < mInnerDeadzone)
        set_val(STICK_1_Y, 0.0);
 
    if(abs(get_val(STICK_1_X)) > 5.00 && abs(get_val(STICK_1_X)) < mInnerDeadzone)
        set_val(STICK_1_X, 0.0);
}
 
void AddOuterDeadzone()
{
    if(get_val(STICK_1_Y) <= mOuterDeadzone * -1.00)
        set_val(STICK_1_Y, -100);
 
    if(get_val(STICK_1_Y) >= mOuterDeadzone)
        set_val(STICK_1_Y, 100);
 
    if(get_val(STICK_1_X) <= mOuterDeadzone * -1.00)
        set_val(STICK_1_X, -100);
 
    if(get_val(STICK_1_X) >= mOuterDeadzone)
        set_val(STICK_1_X, 100);
}
 
 
void SaveSensitivityIndex()
{
    printf("Sensitivity Index: %d, Sensitivity Multiplier: %f", mSensitivityMultiplierIndex, mSensitivityMultipliersArray[mSensitivityMultiplierIndex]);
    pmem_write(ADDR_SENSITIVITY_MULTIPLIER_INDEX, mSensitivityMultiplierIndex);
    pmem_save();
}
 
void SetLeds(uint8 aLeds)
{
    if(aLeds == 1)
        aLeds = 0;
 
    fix32 bits[4];
    bits[0] = (aLeds & (1 << 0)) == 0 ? 0.0 : 100.0;
    bits[1] = (aLeds & (1 << 1)) == 0 ? 0.0 : 100.0;
    bits[2] = (aLeds & (1 << 2)) == 0 ? 0.0 : 100.0;
    bits[4] = (aLeds & (1 << 3)) == 0 ? 0.0 : 100.0;
 
    led_set(LED_1, bits[0], 800);
    led_set(LED_2, bits[1], 800);
    led_set(LED_3, bits[2], 800);
    led_set(LED_4, bits[3], 800);
}
 
void MimicTouch(bool aIsActivated)
{
    if(aIsActivated)
    {
        set_val(BUTTON_19, 100.0);
        set_val(POINT_1_X, get_actual(STICK_1_X));
        set_val(POINT_1_Y, get_actual(STICK_1_Y));
        set_val(STICK_1_X, 0.0);
        set_val(STICK_1_Y, 0.0);
    }
}
 
combo LS {
    set_val(BUTTON_9,100);
    wait(300);
}
 
combo L1 {
    set_val(BUTTON_7,100);
    wait(300);
}
 
combo R1 {
    set_val(BUTTON_4,100);
    wait(300);
}
combo RR {
    set_val(BUTTON_4,100);
    wait(300);
}
 
combo L1R1{
    set_val(BUTTON_4,100);
    set_val(BUTTON_7,100);
    wait(300);
}


Call Of Duty Cold War

Code: Select all
GIVICFG:0001000101000200000002000005000080000000C0000001000000014000000180000001C00000020000001E0000001E000000002148005C00000021800000000BB80000012C

Wiimote with Potinter Calibration Ver 1.12.gpc

Wiimote with Potinter Calibration Ver 1.12.gps

Wiimote with Potinter Calibration Ver 1.12.gpc

Wiimote with Potinter Calibration Ver 1.12.gpc
User avatar
teddy18
Lieutenant
Lieutenant
 
Posts: 336
Joined: Sun Jul 19, 2015 4:18 pm

Re: Wiimote with Potinter Calibration

Postby teddy18 » Sun Oct 24, 2021 1:49 am

Controlls

Wii Nunchuk Left Stick
Wii Nunchuk Tap One Button Z L1/LB/L
Wii Nunchuk Tap Twice Button Z R1/RB/R
Wii Nunchuk Hold Button Z L3/LS/SR
Wiimote + Tap One R1/RB/R
Wiimote + Tap Twice L1/LB/L+R1/RB/R For Cod Wiimote - - Square/X/Y
Wiimote Dpad Right R3/RS/SR
Wiimote Dpad Down Circle/B/A
Wiimote Home Triangle/Y/X
Wiimote Dpad Up Touch Click/View /Minus/Select/Back
For Ps4 and Ps5 Hold Wiimote Dpad Up move Wii Nunchuk Stick for Touch mimic
Wiimote Dpad Left L3/LS/SR
Wiimote A Cross/A/B
Wiimote 1 Options/Menu/Plus/Start
Wiimote 2 PS/Xbox/Home/Guide
Wiimote B R2/RT/ZR
Wii Nunchuk C L2/LT/ZL

Wiimote Hold Dpad Up + and Move Wii Nunchuk Stick in Direction like a dpad
1 DPad Up
2 DPad Right
3 DPad Down
4 DPad Left


Code: Select all
#pragma METAINFO("Wiimote with Potinter Calibration", 1,12, "teddy18")
#include <switch.gph>
#include "Wiimote.gph"
 
/*
<cfgdesc>
 
[Gyro Aiming Activation]
byteoffset = 0
bitsize    = 8
control    = checkbox
default    = 0
item       = On L1/LB
 
[Gyro Aiming Activation2]
group      = true
groupcol = true
byteoffset = 1
bitsize    = 8
control    = checkbox
default    = 1
item       = On L2/LT
 
[Gyro Aiming Activation3]
group      = true
groupcol = true
byteoffset = 2
bitsize    = 8
control    = checkbox
default    = 0
item       = On R1/RB
 
[Gyro Aiming Activation4]
group      = true
groupcol = true
byteoffset = 3
bitsize    = 8
control    = checkbox
default    = 1
item       = On R2/RT
 
[Gyro Aiming Activation5]
group      = true
groupcol = true
byteoffset = 4
bitsize    = 8
control    = checkbox
default    = 0
item       = Always On
 
[Sensitivity]
group      = false
shortdesc  = Base sensitivity X
byteoffset = 5
bitsize    = 32
control    = spinboxf
default    = 200
minimum    = 10
maximum    = 20000
step       = 1
decimals   = 2
 
[SensitivityY]
group      = true
groupcol = true
shortdesc  = Base sensitivity Y
byteoffset = 9
bitsize    = 32
control    = spinboxf
default    = 200
minimum    = 10
maximum    = 20000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers]
group      = false
groupcol = false
shortdesc  = Active Sensitivity Multiplier:
byteoffset = 13
bitsize    = 8
control    = slider
default    = 3
minimum    = 1
maximum    = 7
step       = 1
 
[Sensitivity Multipliers1]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 1:
byteoffset = 14
bitsize    = 32
control    = spinboxf
default    = 50
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers2]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 2:
byteoffset = 18
bitsize    = 32
control    = spinboxf
default    = 75
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers3]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 3:
byteoffset = 22
bitsize    = 32
control    = spinboxf
default    = 100
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers4]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 4:
byteoffset = 26
bitsize    = 32
control    = spinboxf
default    = 125
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers5]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 5:
byteoffset = 30
bitsize    = 32
control    = spinboxf
default    = 150
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers6]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 6:
byteoffset = 34
bitsize    = 32
control    = spinboxf
default    = 175
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Sensitivity Multipliers7]
group      = true
groupcol = false
shortdesc  = Sensitivity Multiplier 7:
byteoffset = 38
bitsize    = 32
control    = spinboxf
default    = 200
minimum    = 10
maximum    = 1000
step       = 1
decimals   = 2
 
[Deadzones]
group      = false
shortdesc  = Ignore Gyro if Right Stick X is greater than:
byteoffset = 42
bitsize    = 32
control    = spinboxf
default    = 300
minimum    = 0
maximum    = 1000
step       = 1
decimals   = 1
 
[DeadzonesY]
group      = true
groupcol = false
shortdesc  = Ignore Gyro if Right Stick Y is greater than:
byteoffset = 46
bitsize    = 32
control    = spinboxf
default    = 300
minimum    = 0
maximum    = 1000
step       = 1
decimals   = 1
 
[DeadzonesD]
group      = true
groupcol = false
shortdesc  = Right Stick Diagonal Deadzone:
byteoffset = 50
bitsize    = 32
control    = spinboxf
default    = 13
minimum    = 0
maximum    = 200
step       = 1
decimals   = 2
 
[DeadzonesO]
group      = true
groupcol = false
shortdesc  = Right Stick Outer Deadzone:
byteoffset = 54
bitsize    = 32
control    = spinboxf
default    = 9200
minimum    = 0
maximum    = 10000
step       = 1
decimals   = 2
 
[DeadzonesI]
group      = true
groupcol = false
shortdesc  = Right Stick Inner Deadzone:
byteoffset = 58
bitsize    = 32
control    = spinboxf
default    = 3350
minimum    = 0
maximum    = 10000
step       = 1
decimals   = 2
 
[Calibration]
group      = false
groupcol = false
shortdesc  = Delay (ms):
byteoffset = 62
bitsize    = 32
control    = slider
default    = 3000
minimum    = 500
maximum    = 10000
step       = 500
 
[CalibrationS]
group      = true
groupcol = false
shortdesc  = Samples:
byteoffset = 66
bitsize    = 32
control    = slider
default    = 300
minimum    = 100
maximum    = 10000
step       = 100
 
</cfgdesc>
*/

 
//Constants
#define PAD_OTHER  0
uint8 PAD_IDS[5] = { 6, 5, 4, 2, 1 };
uint8 PAD_IDS_LENGHT = 5;
 
//Persistent memory addereses
#define ADDR_ACTIVATE_L1                     0
#define ADDR_ACTIVATE_L2                     1
#define ADDR_ACTIVATE_R1                     2
#define ADDR_ACTIVATE_R2                     3
#define ADDR_ACTIVATE_ALWAYS_ON             4
 
#define ADDR_BASE_SENSITIVITY_X             5
#define ADDR_BASE_SENSITIVITY_Y             9
#define ADDR_SENSITIVITY_MULTIPLIER_INDEX     13
#define ADDR_SENSITIVITY_MULTIPLIER_0         14
#define ADDR_SENSITIVITY_MULTIPLIER_1         18
#define ADDR_SENSITIVITY_MULTIPLIER_2         22
#define ADDR_SENSITIVITY_MULTIPLIER_3         26
#define ADDR_SENSITIVITY_MULTIPLIER_4         30
#define ADDR_SENSITIVITY_MULTIPLIER_5         34
#define ADDR_SENSITIVITY_MULTIPLIER_6         38
 
#define ADDR_DEADZONE_X                        42
#define ADDR_DEADZONE_Y                        46
#define ADDR_DEADZONE_D                        50
 
#define ADDR_OUTER_DEADZONE                    54
#define ADDR_INNER_DEADZONE                    58
 
#define ADDR_CALIBRATION_DELAY                62
#define ADDR_CALIBRATION_SAMPLES            66
 
#define ADDR_CALIB_OTHER_X                     116
#define ADDR_CALIB_OTHER_Y                     120
#define ADDR_CALIB_OTHER_Z                     124
 
#define PADDLE1              PADDLE_1
#define ACTION_NONE         0
#define ACTION_HOLD         1
#define ACTION_SINGLE_TAP   2
#define ACTION_DOUBLE_TAP   3
uint8 triggered_action;
uint8 process_action;
#define PADDLE4              PADDLE_4
#define ACTION_NONE2         0
#define ACTION_HOLD2         1
#define ACTION_SINGLE_TAP2   2
#define ACTION_DOUBLE_TAP2   3
uint8 triggered_action2;
uint8 process_action2;
 
#define LED_DELAY                            2000
 
//Variables
fix32 mCalibOffsetX = 0.0;
fix32 mCalibOffsetY = 0.0;
fix32 mCalibOffsetZ = 0.0;
 
bool mIsActivatedCalibrating = FALSE;
bool mIsActivatedIncreaseSensitivity = FALSE;
bool mIsActivatedDecreaseSensitivity = FALSE;
bool mIsActivatedLeds = FALSE;
 
fix32 mBaseSensitivityX = 35.0;
fix32 mBaseSensitivityY = 35.0;
uint8 mSensitivityMultiplierIndex = 2;
fix32 mSensitivityMultipliersArray[7] = { 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0 };
 
uint32 mCalibrationDelay = 3000;
uint32 mCalibrationSamples = 300;
uint32 mCalibrationCycleIndex = 0;
 
fix32 mDeadzoneX = 30.0// Deadzone GYRO_1_YZ Input
fix32 mDeadzoneY = 30.0// Deadzone GYRO_1_YX Input
fix32 mDeadzoneD = 0.13// Deadzone Diagonal input
 
fix32 mOuterDeadzone = 92.00;
fix32 mInnerDeadzone = 33.5;
 
bool mIsActivateL1 = FALSE;
bool mIsActivateL2 = TRUE;
bool mIsActivateR1 = FALSE;
bool mIsActivateR2 = TRUE;
bool mIsAlwaysOn = FALSE;
bool mIsMotionAimingOn = TRUE;
 
uint32 mTimeCounter = 0;
 
bool mIsActivatedDebugging = FALSE;
 
init
{
    pmem_load();
 
    printf("Values loaded:");
 
    pmem_read(ADDR_ACTIVATE_L1, &mIsActivateL1);
    printf("Activate L1: %d", mIsActivateL1);
    pmem_read(ADDR_ACTIVATE_L2, &mIsActivateL2);
    printf("Activate L2: %d", mIsActivateL2);
    pmem_read(ADDR_ACTIVATE_R1, &mIsActivateR1);
    printf("Activate R1: %d", mIsActivateR1);
    pmem_read(ADDR_ACTIVATE_R2, &mIsActivateR2);
    printf("Activate R2: %d", mIsActivateR2);
    pmem_read(ADDR_ACTIVATE_ALWAYS_ON, &mIsAlwaysOn);
    printf("Activate AlwaysOn: %d", mIsAlwaysOn);
 
    pmem_read(ADDR_BASE_SENSITIVITY_X, &mBaseSensitivityX);
    printf("Base sensitivity X: %f", mBaseSensitivityX);
    pmem_read(ADDR_BASE_SENSITIVITY_Y, &mBaseSensitivityY);
    printf("Base sensitivity Y: %f", mBaseSensitivityY);
 
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_INDEX, &mSensitivityMultiplierIndex);
    mSensitivityMultiplierIndex--;
    printf("Sensitivity multiplier index: %d", mSensitivityMultiplierIndex);
 
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_0, &mSensitivityMultipliersArray[0]);
    printf("Sensitivity multiplier [0]: %f", mSensitivityMultipliersArray[0]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_1, &mSensitivityMultipliersArray[1]);
    printf("Sensitivity multiplier [1]: %f", mSensitivityMultipliersArray[1]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_2, &mSensitivityMultipliersArray[2]);
    printf("Sensitivity multiplier [2]: %f", mSensitivityMultipliersArray[2]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_3, &mSensitivityMultipliersArray[3]);
    printf("Sensitivity multiplier [3]: %f", mSensitivityMultipliersArray[3]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_4, &mSensitivityMultipliersArray[4]);
    printf("Sensitivity multiplier [4]: %f", mSensitivityMultipliersArray[4]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_5, &mSensitivityMultipliersArray[5]);
    printf("Sensitivity multiplier [5]: %f", mSensitivityMultipliersArray[5]);
    pmem_read(ADDR_SENSITIVITY_MULTIPLIER_6, &mSensitivityMultipliersArray[6]);
    printf("Sensitivity multiplier [6]: %f", mSensitivityMultipliersArray[6]);
 
    pmem_read(ADDR_DEADZONE_X, &mDeadzoneX);
    printf("Deadzone X: %f", mDeadzoneX);
    pmem_read(ADDR_DEADZONE_Y, &mDeadzoneY);
    printf("Deadzone Y: %f", mDeadzoneY);
    pmem_read(ADDR_DEADZONE_D, &mDeadzoneD);
    printf("Deadzone D: %f", mDeadzoneD);
 
    pmem_read(ADDR_OUTER_DEADZONE, &mOuterDeadzone);
    printf("Outer Deadzone: %f", mOuterDeadzone);
    pmem_read(ADDR_INNER_DEADZONE, &mInnerDeadzone);
    printf("Inner Deadzone: %f", mInnerDeadzone);
 
    pmem_read(ADDR_CALIBRATION_DELAY, &mCalibrationDelay);
    printf("Calibration Delay: %d", mCalibrationDelay);
    pmem_read(ADDR_CALIBRATION_SAMPLES, &mCalibrationSamples);
    printf("Calibration Samples: %d", mCalibrationSamples);
 
    FetchCalibration();
}
 
main
{
    ResetLeds();
 
    ActivateIncreaseSensitivity(get_val(BUTTON_6) > 0.0 && get_prev(BUTTON_10) == 0.0 && get_actual(BUTTON_10) > 0.0);
    IncreaseSensitivity();
    ActivateDecreaseSensitivity(get_val(BUTTON_6) > 0.0 && get_prev(BUTTON_11) == 0.0 && get_actual(BUTTON_11) > 0.0);
    DecreaseSensitivity();
 
    ActivateCalibration(get_val(BUTTON_1) > 0.0 && get_val(BUTTON_6) > 0.0 && get_val(BUTTON_9) > 0.0);
    Calibrate();
 
    Debug();
 
    ToggleAlwaysOn(get_val(BUTTON_6) > 0.0 && get_prev(BUTTON_13) == 0.0 && get_actual(BUTTON_13) > 0.0);
    ToggleMotionAiming(get_val(BUTTON_6) > 0.0 && get_prev(BUTTON_12) == 0.0 && get_actual(BUTTON_12) > 0.0);
 
    MotionAiming(mIsMotionAimingOn && !mIsActivatedCalibrating && !mIsActivatedDebugging &&
                 (abs(get_val(STICK_1_X)) <= mDeadzoneX && (abs(get_val(STICK_1_Y)) <= mDeadzoneY)) &&
                    (mIsAlwaysOn ||
                    (mIsActivateL1 && (get_val(BUTTON_7) > 98.0)) ||
                    (mIsActivateL2 && (get_val(BUTTON_8) > 98.0)) ||
                    (mIsActivateR1 && (get_val(BUTTON_4) > 98.0)) ||
                    (mIsActivateR2 && (get_val(BUTTON_5) > 98.0))));
 
    AddInnerDeadzone();
    AddOuterDeadzone();
 
    MimicTouch(get_val(BUTTON_2) > 90.0 && GetPadType() != PAD_OTHER);
    if(!process_action) {if(event_active(PADDLE1)) {triggered_action = ACTION_SINGLE_TAP;if(time_release(PADDLE1) < 150) {triggered_action = ACTION_DOUBLE_TAP;process_action = TRUE;}}
        if(triggered_action == ACTION_SINGLE_TAP) {if(check_release(PADDLE1, 175)) {process_action = TRUE;}}
        if(check_active(PADDLE1, 200)) {triggered_action = ACTION_HOLD;process_action = TRUE;}} else if(check_release(PADDLE1, 250)) {process_action = FALSE;}
    if(process_action) {
        switch(triggered_action) {
            case ACTION_HOLD: {
                //
                //
                combo_run(LS);
            } break;
            case ACTION_SINGLE_TAP: {
                //
                //
                combo_run(L1);
            } break;
            case ACTION_DOUBLE_TAP: {
                //
                //
                combo_run(R1);
            } break;
        }
        triggered_action = ACTION_NONE;
    }
    if(!process_action2) {if(event_active(PADDLE4)) {triggered_action2 = ACTION_SINGLE_TAP2;if(time_release(PADDLE4) < 150) {triggered_action2 = ACTION_DOUBLE_TAP2;process_action2 = TRUE;}}
        if(triggered_action2 == ACTION_SINGLE_TAP2) {if(check_release(PADDLE4, 175)) {process_action2 = TRUE;}}
        if(check_active(PADDLE4, 200)) {triggered_action2 = ACTION_HOLD2;process_action2 = TRUE;}} else if(check_release(PADDLE4, 250)) {process_action2 = FALSE;}
    if(process_action2) {
        switch(triggered_action2) {
            case ACTION_HOLD2: {
                //
                //
                //
            } break;
            case ACTION_SINGLE_TAP2: {
                //
                //
                combo_run(RR);
            } break;
            case ACTION_DOUBLE_TAP2: {
                //
                //
                combo_run(L1R1);
            } break;
        }
        triggered_action2 = ACTION_NONE2;
    }
}
 
void ResetLeds()
{
    if(mIsActivatedLeds)
    {
        if(mTimeCounter > LED_DELAY)
        {
            led_reset();
            mTimeCounter = 0;
        }
        else
        {
            mTimeCounter += elapsed_time();
        }
    }
}
 
void ActivateIncreaseSensitivity(bool aIsActivated)
{
    if(aIsActivated)
    {
        if(mSensitivityMultiplierIndex < 6) //increase sensivity multiplier
            mIsActivatedIncreaseSensitivity = TRUE;
        else
        {
            SetLeds(7);
            mIsActivatedLeds = TRUE;
        }
    }
}
 
void IncreaseSensitivity()
{
    if(mIsActivatedIncreaseSensitivity)
    {
        mSensitivityMultiplierIndex = mSensitivityMultiplierIndex + 1;
        SetLeds(mSensitivityMultiplierIndex+1);
        SaveSensitivityIndex();
        mIsActivatedIncreaseSensitivity = FALSE;
        mIsActivatedLeds = TRUE;
    }       
}
 
void ActivateDecreaseSensitivity(bool aIsActivated)
{
    if(aIsActivated)
    {
        if(mSensitivityMultiplierIndex > 0) //decrease sensivity multiplier
            mIsActivatedDecreaseSensitivity = TRUE;
        else
        {
            SetLeds(0);
            mIsActivatedLeds = TRUE;
        }
    }
}
 
void DecreaseSensitivity()
{
    if(mIsActivatedDecreaseSensitivity)
    {
        mSensitivityMultiplierIndex = mSensitivityMultiplierIndex - 1;
        SetLeds(mSensitivityMultiplierIndex+1);
        SaveSensitivityIndex();
        mIsActivatedDecreaseSensitivity = FALSE;
        mIsActivatedLeds = TRUE;
    }
}
 
void ActivateCalibration(bool aIsActivated)
{
    if(aIsActivated && !mIsActivatedCalibrating)
    {
        mCalibOffsetX = 0.0;
        mCalibOffsetY = 0.0;
        mCalibOffsetZ = 0.0;
        mCalibrationCycleIndex = 0;
        mTimeCounter = 0;
        SetLeds(6);
        printf("Calibration started. Delay: %d, Samples: %d", mCalibrationDelay, mCalibrationSamples);
        mIsActivatedCalibrating = TRUE;
    }
}
 
void Calibrate()
{
    if(mIsActivatedCalibrating)
    {
        mTimeCounter += elapsed_time();
        if(mTimeCounter > mCalibrationDelay)
        {
            SetLeds(15);
            if(mCalibrationCycleIndex < mCalibrationSamples)
            {
                mCalibrationCycleIndex += 1;
 
                mCalibOffsetX += get_actual(GYRO_1_X);
                mCalibOffsetY += get_actual(GYRO_1_Y);
                mCalibOffsetZ += get_actual(GYRO_1_Z);
            }
            else
            {
                mCalibOffsetX /= (fix32)mCalibrationSamples;
                mCalibOffsetY /= (fix32)mCalibrationSamples;
                mCalibOffsetZ /= (fix32)mCalibrationSamples;
 
                StoreCalibration();
 
                mTimeCounter = 0;
                led_reset();
                mIsActivatedCalibrating = FALSE;
            }
        }
    }
}
 
void FetchCalibration()
{
    uint8 padType = GetPadType();
    pmem_load();
    switch(padType)
    {
        case PAD_OTHER:
            pmem_read(ADDR_CALIB_OTHER_X, &mCalibOffsetX);
            pmem_read(ADDR_CALIB_OTHER_Y, &mCalibOffsetY);
            pmem_read(ADDR_CALIB_OTHER_Z, &mCalibOffsetZ);
            printf("Other gamepad calibration. X: %f, Y: %f, Z: %f", mCalibOffsetX, mCalibOffsetY, mCalibOffsetZ);
        break;
    }
}
 
void StoreCalibration()
{
    uint8 padType = GetPadType();
    printf("Pad type set: %d", padType);
    switch(padType)
    {
        case PAD_OTHER:
            pmem_write(ADDR_CALIB_OTHER_X, mCalibOffsetX);
            pmem_write(ADDR_CALIB_OTHER_Y, mCalibOffsetY);
            pmem_write(ADDR_CALIB_OTHER_Z, mCalibOffsetZ);
            printf("Stored other gamepad calibration. X: %f, Y: %f, Z: %f", mCalibOffsetX, mCalibOffsetY, mCalibOffsetZ);
        break;
    }
    pmem_save();
}
 
uint8 GetPadType()
{
    uint8 status, protocol, device, i = 0;
    while(i < PAD_IDS_LENGHT)
    {
        status = port_status(PAD_IDS[i], &protocol, &device);
        if(status)
        {
            if(protocol == PROTOCOL_WII)
                return PAD_OTHER;
        }
        i++;
    }
    return(-1);
}
 
void Debug()
{
    if(mIsActivatedCalibrating || !mIsActivatedDebugging)
        return;
 
    set_val(GYRO_1_X, (get_val(GYRO_1_X) - mCalibOffsetX) * 1000.0);
    set_val(GYRO_1_Y, (get_val(GYRO_1_Y) - mCalibOffsetY) * 1000.0);
    set_val(GYRO_1_Z, (get_val(GYRO_1_Z) - mCalibOffsetZ) * 1000.0);
}
 
 
void ToggleAlwaysOn(bool aIsActivated)
{
    if(aIsActivated)
    {
        mIsAlwaysOn = !mIsAlwaysOn;
        pmem_write(ADDR_ACTIVATE_ALWAYS_ON, mIsAlwaysOn);
        pmem_save();
    }
}
 
void ToggleMotionAiming(bool aIsActivated)
{
    if(aIsActivated)
    {
        mIsMotionAimingOn = !mIsMotionAimingOn;
    }
}
 
void MotionAiming(bool aIsActivated)
{
    if(aIsActivated)
    {
        static fix32 accelX, accelY;
        static fix32 stickX, stickY;
        if(accelX != get_actual(GYRO_1_Z) || accelY != get_actual(GYRO_1_X))
        {
            accelX = get_actual(GYRO_1_Z);
            accelY = get_actual(GYRO_1_X);
 
            stickX = (accelX - mCalibOffsetZ) * mBaseSensitivityX * mSensitivityMultipliersArray[mSensitivityMultiplierIndex];
            stickY = (accelY - mCalibOffsetX) * mBaseSensitivityY * mSensitivityMultipliersArray[mSensitivityMultiplierIndex];
 
            fix32 signalX = (stickX < 0.0) ? (stickX = inv(stickX), -1.0) : (stickX > 0.0) ? 1.0 : 0.0;
            fix32 signalY = (stickY < 0.0) ? (stickY = inv(stickY), -1.0) : (stickY > 0.0) ? 1.0 : 0.0;
            fix32 angle = atan2(stickY, stickX);
 
            stickX = clamp(((mDeadzoneX * pow(cos(angle), mDeadzoneD)) + stickX) * signalX, -100.0, 100.0);
            stickY = clamp(((mDeadzoneY * pow(sin(angle), mDeadzoneD)) + stickY) * signalY, -100.0, 100.0);
        }
        set_val(STICK_1_X, stickX);
        set_val(STICK_1_Y, stickY);
        return;
    }
}
 
void AddInnerDeadzone()
{
    if(abs(get_val(STICK_1_Y)) > 5.00 && abs(get_val(STICK_1_Y)) < mInnerDeadzone)
        set_val(STICK_1_Y, 0.0);
 
    if(abs(get_val(STICK_1_X)) > 5.00 && abs(get_val(STICK_1_X)) < mInnerDeadzone)
        set_val(STICK_1_X, 0.0);
}
 
void AddOuterDeadzone()
{
    if(get_val(STICK_1_Y) <= mOuterDeadzone * -1.00)
        set_val(STICK_1_Y, -100);
 
    if(get_val(STICK_1_Y) >= mOuterDeadzone)
        set_val(STICK_1_Y, 100);
 
    if(get_val(STICK_1_X) <= mOuterDeadzone * -1.00)
        set_val(STICK_1_X, -100);
 
    if(get_val(STICK_1_X) >= mOuterDeadzone)
        set_val(STICK_1_X, 100);
}
 
 
void SaveSensitivityIndex()
{
    printf("Sensitivity Index: %d, Sensitivity Multiplier: %f", mSensitivityMultiplierIndex, mSensitivityMultipliersArray[mSensitivityMultiplierIndex]);
    pmem_write(ADDR_SENSITIVITY_MULTIPLIER_INDEX, mSensitivityMultiplierIndex);
    pmem_save();
}
 
void SetLeds(uint8 aLeds)
{
    if(aLeds == 1)
        aLeds = 0;
 
    fix32 bits[4];
    bits[0] = (aLeds & (1 << 0)) == 0 ? 0.0 : 100.0;
    bits[1] = (aLeds & (1 << 1)) == 0 ? 0.0 : 100.0;
    bits[2] = (aLeds & (1 << 2)) == 0 ? 0.0 : 100.0;
    bits[4] = (aLeds & (1 << 3)) == 0 ? 0.0 : 100.0;
 
    led_set(LED_1, bits[0], 800);
    led_set(LED_2, bits[1], 800);
    led_set(LED_3, bits[2], 800);
    led_set(LED_4, bits[3], 800);
}
 
void MimicTouch(bool aIsActivated)
{
    if(aIsActivated)
    {
        set_val(BUTTON_19, 100.0);
        set_val(POINT_1_X, get_actual(STICK_1_X));
        set_val(POINT_1_Y, get_actual(STICK_1_Y));
        set_val(STICK_1_X, 0.0);
        set_val(STICK_1_Y, 0.0);
    }
}
 
combo LS {
    set_val(BUTTON_9,100);
    wait(300);
}
 
combo L1 {
    set_val(BUTTON_7,100);
    wait(300);
}
 
combo R1 {
    set_val(BUTTON_4,100);
    wait(300);
}
combo RR {
    set_val(BUTTON_4,100);
    wait(300);
}
 
combo L1R1{
    set_val(BUTTON_4,100);
    set_val(BUTTON_7,100);
    wait(300);
}


Call Of Duty Cold War

Code: Select all
GIVICFG:0001000101000200000002000005000080000000C0000001000000014000000180000001C00000020000001E0000001E000000002148005C00000021800000000BB80000012C

The attachment Wiimote with Potinter Calibration Ver 1.12.gpc is no longer available

Wiimote with Potinter Calibration Ver 1.12.gpc
(20.88 KiB) Downloaded 21 times

The attachment Wiimote with Potinter Calibration Ver 1.12.gps is no longer available

Wiimote with Potinter Calibration Ver 1.12.gpc
(20.88 KiB) Downloaded 18 times

Wiimote with Potinter Calibration Ver 1.12.gpc
(20.88 KiB) Downloaded 21 times

The attachment Wiimote with Potinter Calibration Ver 1.12.gpc is no longer available

The attachment Wiimote with Potinter Calibration Ver 1.12.gpc is no longer available

Wiimote with Potinter Calibration Ver 1.12.gpc
(20.88 KiB) Downloaded 21 times
Attachments
Wiimote with Potinter Calibration Ver 1.12.gps
(15.55 KiB) Downloaded 20 times
User avatar
teddy18
Lieutenant
Lieutenant
 
Posts: 336
Joined: Sun Jul 19, 2015 4:18 pm


Return to Wiimote, Nunchuk and Sensorbar

Who is online

Users browsing this forum: No registered users and 4 guests