start a script for me Please

Gtuner IV general support. Operation, questions, updates, feature request.

Re: start a script for me Please

Postby Scopeloc » Sun May 19, 2019 6:32 pm

So I got the keyboard on B port to work to change the mode. Now I see it was not an issue with the inhibit Button_1 that was causing the issue. It is just because I am hitting the button to fast like double tapping. I have a terminal disease and have bad nerve damage which makes it hard for me to control how I am pushing or tell how many times I pushed it. I am going to try to inhibit the button to make it not activate till I hold it at least 500 ms. I think that will fix it.
User avatar
Scopeloc
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Wed Dec 19, 2018 6:22 am

Re: start a script for me Please

Postby Scopeloc » Sun May 19, 2019 8:26 pm

I was having issue with the inhibit button way. So I just made a button for every mode. this works really well as I have a usb numpad coming in the mail. When I get the numpad of coarse I will change the buttons to the right value. all is working great except one thing. maybe you can see the problem and help out if so.
When I return to mode_0. The home button on my controller starts a slow flash. It still works fine, but i dont like the flash it distracts me. Do you see anything that needs cleaning up or wrote different. Thanks for any help. I am not a programmer.
Code: Select all
#pragma METAINFO("QuickChangeFireModes", 1, 0, "bonefisher")
 
#include <keyboard.gph>
#include <xb1.gph>
 
#define SHOOT                 XB1_RT
#define ADS                   XB1_LT
 
#define MODE_0          0
#define MODE_1          1
#define MODE_2          2
#define MODE_3          3
#define MODE_4          4
 
uint8 mode = 0;
 
init {
    set_mode(MODE_0);
}
 
main {
 
        if(key_status(KEY_W))
    {
        set_mode(MODE_1);
    }
            if(key_status(KEY_A))
    {
        set_mode(MODE_2);
    }
            if(key_status(KEY_S))
    {
        set_mode(MODE_3);
    }
            if(key_status(KEY_D))
    {
        set_mode(MODE_4);
    }
            if(key_status(KEY_C))
    {
        set_mode(MODE_0);
    }
 
    switch(mode) {
        case MODE_0: {
        if(is_active(BUTTON_5)) {
        set_val(BUTTON_5, 100.0);
    }
        } break;
        case MODE_1: {
    if(is_active(BUTTON_5)) {
        combo_run(RadpiFire1);
    } else if(RadpiFire1) {
        combo_stop(RadpiFire1);
    }
} break;
        case MODE_2: {
    if(is_active(BUTTON_5)) {
        combo_run(RadpiFire2);
    } else if(RadpiFire2) {
        combo_stop(RadpiFire2);
    }
} break;
        case MODE_3: {
    if(is_active(BUTTON_5)) {
        combo_run(RadpiFire3);
    } else if(RadpiFire3) {
        combo_stop(RadpiFire3);
    }
} break;
        case MODE_4: {
    if(is_active(BUTTON_5)) {
        combo_run(RadpiFire4);
    } else if(RadpiFire4) {
        combo_stop(RadpiFire4);
    }
} break;
    }
}
 
combo RadpiFire1 {
    set_val(BUTTON_5, 100.0);
    wait(84);
    set_val(BUTTON_5, 0.0);
    wait(84);
}
 
combo RadpiFire2 {
    set_val(BUTTON_5, 100.0);
    wait(233);
    set_val(BUTTON_5, 0.0);
    wait(100);
}
 
combo RadpiFire3 {
    set_val(BUTTON_5, 100.0);
    wait(500);
    set_val(BUTTON_5, 0.0);
    wait(50);
}
 
combo RadpiFire4 {
    set_val(BUTTON_5, 100.0);
    wait(550);
    set_val(BUTTON_5, 0.0);
    wait(48);
}
 
void set_mode(uint8 new_mode) {
    mode = new_mode;
    // Set LED
    switch(mode) {
        case MODE_0: { // LED OFF
            led_set(LED_1, 0.0, 0);
            led_set(LED_2, 0.0, 0);
            led_set(LED_3, 0.0, 0);
            led_set(LED_4, 0.0, 0);
        } break;
        case MODE_1: { // Blue LED
            led_set(LED_1, 100.0, 0);
            led_set(LED_2, 0.0, 0);
            led_set(LED_3, 0.0, 0);
            led_set(LED_4, 0.0, 0);
        } break;
        case MODE_2: { // Red LED
            led_set(LED_1, 0.0, 0);
            led_set(LED_2, 100.0, 0);
            led_set(LED_3, 0.0, 0);
            led_set(LED_4, 0.0, 0);
        } break;
        case MODE_3: { // Green LED
            led_set(LED_1, 0.0, 0);
            led_set(LED_2, 0.0, 0);
            led_set(LED_3, 100.0, 0);
            led_set(LED_4, 0.0, 0);
        } break;
        case MODE_4: { // White LED
            led_set(LED_1, 100.0, 0);
            led_set(LED_2, 100.0, 0);
            led_set(LED_3, 100.0, 0);
            led_set(LED_4, 0.0, 0);
        } break;
    }
    return;
}
User avatar
Scopeloc
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Wed Dec 19, 2018 6:22 am

Re: start a script for me Please

Postby Scopeloc » Sun May 19, 2019 9:11 pm

I got it. When returning to mode_0 it made home key start flashing. I made a 5th mode which does the same thing and used a color for LED. now everything works the best it ever has and no flash at all. Thanks for helping and advice.
Code: Select all
#pragma METAINFO("QuickChangeFireModes", 1, 0, "bonefisher")
 
#include <keyboard.gph>
#include <xb1.gph>
 
#define SHOOT                 XB1_RT
#define ADS                   XB1_LT
 
#define MODE_0          0
#define MODE_1          1
#define MODE_2          2
#define MODE_3          3
#define MODE_4          4
#define MODE_5          5
 
uint8 mode = 0;
 
init {
    set_mode(MODE_0);
}
 
main {
 
        if(key_status(KEY_W))
    {
        set_mode(MODE_1);
    }
            if(key_status(KEY_A))
    {
        set_mode(MODE_2);
    }
            if(key_status(KEY_S))
    {
        set_mode(MODE_3);
    }
            if(key_status(KEY_D))
    {
        set_mode(MODE_4);
    }
            if(key_status(KEY_C))
    {
        set_mode(MODE_5);
    }
 
    switch(mode) {
        case MODE_0: {
        if(is_active(BUTTON_5)) {
        set_val(BUTTON_5, 100.0);
    }
        } break;
        case MODE_1: {
    if(is_active(BUTTON_5)) {
        combo_run(RadpiFire1);
    } else if(RadpiFire1) {
        combo_stop(RadpiFire1);
    }
} break;
        case MODE_2: {
    if(is_active(BUTTON_5)) {
        combo_run(RadpiFire2);
    } else if(RadpiFire2) {
        combo_stop(RadpiFire2);
    }
} break;
        case MODE_3: {
    if(is_active(BUTTON_5)) {
        combo_run(RadpiFire3);
    } else if(RadpiFire3) {
        combo_stop(RadpiFire3);
    }
} break;
        case MODE_4: {
    if(is_active(BUTTON_5)) {
        combo_run(RadpiFire4);
    } else if(RadpiFire4) {
        combo_stop(RadpiFire4);
    }
} break;
        case MODE_5: {
    if(is_active(BUTTON_5)) {
        set_val(BUTTON_5, 100.0);
    }
} break;
    }
}
 
combo RadpiFire1 {
    set_val(BUTTON_5, 100.0);
    wait(84);
    set_val(BUTTON_5, 0.0);
    wait(84);
}
 
combo RadpiFire2 {
    set_val(BUTTON_5, 100.0);
    wait(233);
    set_val(BUTTON_5, 0.0);
    wait(100);
}
 
combo RadpiFire3 {
    set_val(BUTTON_5, 100.0);
    wait(500);
    set_val(BUTTON_5, 0.0);
    wait(50);
}
 
combo RadpiFire4 {
    set_val(BUTTON_5, 100.0);
    wait(550);
    set_val(BUTTON_5, 0.0);
    wait(48);
}
 
void set_mode(uint8 new_mode) {
    mode = new_mode;
    // Set LED
    switch(mode) {
        case MODE_0: { // LED OFF
            led_set(LED_1, 0.0, 0);
            led_set(LED_2, 0.0, 0);
            led_set(LED_3, 0.0, 0);
            led_set(LED_4, 0.0, 0);
        } break;
        case MODE_1: { // Blue LED
            led_set(LED_1, 100.0, 0);
            led_set(LED_2, 0.0, 0);
            led_set(LED_3, 0.0, 0);
            led_set(LED_4, 0.0, 0);
        } break;
        case MODE_2: { // Red LED
            led_set(LED_1, 0.0, 0);
            led_set(LED_2, 100.0, 0);
            led_set(LED_3, 0.0, 0);
            led_set(LED_4, 0.0, 0);
        } break;
        case MODE_3: { // Green LED
            led_set(LED_1, 0.0, 0);
            led_set(LED_2, 0.0, 0);
            led_set(LED_3, 100.0, 0);
            led_set(LED_4, 0.0, 0);
        } break;
        case MODE_4: { // White LED
            led_set(LED_1, 100.0, 0);
            led_set(LED_2, 100.0, 0);
            led_set(LED_3, 100.0, 0);
            led_set(LED_4, 0.0, 0);
        } break;
        case MODE_5: { // Yellow LED
            led_set(LED_1, 0.0, 0);
            led_set(LED_2, 100.0, 0);
            led_set(LED_3, 100.0, 0);
            led_set(LED_4, 0.0, 0);
        } break;
    }
    return;
}
User avatar
Scopeloc
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Wed Dec 19, 2018 6:22 am

Re: start a script for me Please

Postby Scachi » Mon May 20, 2019 10:51 am

The function key_status return true as long as the key is pressed.. it works like get_val does for buttons.
For controller buttons you can use the function event_active to only do something in the moment the key is getting pressed (state changes from released ro pressed), a similar function for keys to not exists.

key_status like used in your code will repeat set the mode as long as you hold down the key, resetting the led over and over again, and this may cause disconnects like you have observed.

You can change your code to remember the last used mode and only change the mode if it is requesting a different one.
If you add this line directly below your line "void set_mode(uint8 new_mode) {" and it should solve that problem:
Code: Select all
if (new_mode == mode) return; // don't set this mode if it is alread active.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Previous

Return to Gtuner IV Support

Who is online

Users browsing this forum: No registered users and 53 guests