Setting LED's keeps crashing my T2

GPC2 script programming for Titan Two. Code examples, questions, requests.

Setting LED's keeps crashing my T2

Postby pablosscripts » Tue Oct 04, 2016 11:49 pm

The following keeps freezing up my T2 after just a few seconds of play. Any ideas what I've done wrong?





Code: Select all


main {
    if(rappelling_flag || AutoReloadAction) {
        ColorLED('W');
    }
    if(!rappelling_flag && !AutoReloadAction) {
        ColorLED('B');
    }

}

void ColorLED(char Color) {
    fix32 Color1, Color2, Color3, Color4;
   
    if(Color == 'B'){Color1 = 100.0;    Color2 = 0.00;    Color3 = 0.00;    Color4 = 0.00;}
    if(Color == 'R'){Color1 = 0.00;    Color2 = 100.0;    Color3 = 0.00;    Color4 = 0.00;}
    if(Color == 'G'){Color1 = 0.00;    Color2 = 0.00;    Color3 = 100.0;    Color4 = 0.00;}
    if(Color == 'P'){Color1 = 0.00;    Color2 = 0.00;    Color3 = 0.00;    Color4 = 100.0;}
    if(Color == 'C'){Color1 = 100.0;    Color2 = 0.00;    Color3 = 100.0;    Color4 = 0.00;}
    if(Color == 'A'){Color1 = 0.00;    Color2 = 100.0;    Color3 = 100.0;    Color4 = 0.00;}
    if(Color == 'W'){Color1 = 100.0;    Color2 = 100.0;    Color3 = 100.0;    Color4 = 100.0;}
   
    led_set(LED_1, Color1, 0);
    led_set(LED_2, Color2, 0);
    led_set(LED_3, Color3, 0);
    led_set(LED_4, Color4, 0);
   
    return;
}
Setup: XIM Apex, T2, K780 keyboard, G Pro Wireless mouse, SteelSeries 4HD pad, DXRacer armrest, LucidSound LS30 headset, Netduma router, Ubiquiti UniFi AP LR

My R6 script: https://youtu.be/x-9NtxyySVM
User avatar
pablosscripts
Brigadier General
Brigadier General
 
Posts: 1976
Joined: Tue Nov 24, 2015 6:27 am

Re: Setting LED's keeps crashing my T2

Postby Scachi » Wed Oct 05, 2016 12:08 am

I think your are flooding the usb with your second statement, always sending ColorLED('B');
Maybe you should at something like a "toggle" variable that remembers the last color state and only call the ColorLED function if the value of the toggle variable has changes to only send the color once then ?
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Setting LED's keeps crashing my T2

Postby pablosscripts » Wed Oct 05, 2016 12:18 am

Scachi wrote:I think your are flooding the usb with your second statement, always sending ColorLED('B');
Maybe you should at something like a "toggle" variable that remembers the last color state and only call the ColorLED function if the value of the toggle variable has changes to only send the color once then ?


Ah yes you're right ok I'll rework the code, thank you!
Setup: XIM Apex, T2, K780 keyboard, G Pro Wireless mouse, SteelSeries 4HD pad, DXRacer armrest, LucidSound LS30 headset, Netduma router, Ubiquiti UniFi AP LR

My R6 script: https://youtu.be/x-9NtxyySVM
User avatar
pablosscripts
Brigadier General
Brigadier General
 
Posts: 1976
Joined: Tue Nov 24, 2015 6:27 am

Re: Setting LED's keeps crashing my T2

Postby pablosscripts » Wed Oct 05, 2016 12:50 am

On your suggestion I've rewritten it, hopefully this works. I'll have to test it tonight when I get home:

Code: Select all
    int led_change_flag = 0;
   
    if(rappelling_flag || AutoReloadAction) {
        ColorLED('W');
        led_change_flag = 0;
    }

    if((!rappelling_flag && !AutoReloadAction) && led_change_flag == 0) {
        ColorLED('B');
        led_change_flag = 1;
    }
Setup: XIM Apex, T2, K780 keyboard, G Pro Wireless mouse, SteelSeries 4HD pad, DXRacer armrest, LucidSound LS30 headset, Netduma router, Ubiquiti UniFi AP LR

My R6 script: https://youtu.be/x-9NtxyySVM
User avatar
pablosscripts
Brigadier General
Brigadier General
 
Posts: 1976
Joined: Tue Nov 24, 2015 6:27 am

Re: Setting LED's keeps crashing my T2

Postby pablosscripts » Wed Oct 05, 2016 8:20 am

Ok the code above doesn't work:( It keeps freezing. Can anyone see what I've done wrong?
Setup: XIM Apex, T2, K780 keyboard, G Pro Wireless mouse, SteelSeries 4HD pad, DXRacer armrest, LucidSound LS30 headset, Netduma router, Ubiquiti UniFi AP LR

My R6 script: https://youtu.be/x-9NtxyySVM
User avatar
pablosscripts
Brigadier General
Brigadier General
 
Posts: 1976
Joined: Tue Nov 24, 2015 6:27 am

Re: Setting LED's keeps crashing my T2

Postby J2Kbr » Wed Oct 05, 2016 10:23 am

the best solution for this is call ColorLED in the same block you change the variables rappelling_flag and AutoReloadAction;
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm

Re: Setting LED's keeps crashing my T2

Postby pablosscripts » Wed Oct 05, 2016 10:46 am

J2Kbr wrote:the best solution for this is call ColorLED in the same block you change the variables rappelling_flag and AutoReloadAction;



The problem isn't with setting the LED's, it's reverting it back to the original colour. Setting it is never a problem, it's the revert that freezes my T2.
Setup: XIM Apex, T2, K780 keyboard, G Pro Wireless mouse, SteelSeries 4HD pad, DXRacer armrest, LucidSound LS30 headset, Netduma router, Ubiquiti UniFi AP LR

My R6 script: https://youtu.be/x-9NtxyySVM
User avatar
pablosscripts
Brigadier General
Brigadier General
 
Posts: 1976
Joined: Tue Nov 24, 2015 6:27 am

Re: Setting LED's keeps crashing my T2

Postby J2Kbr » Wed Oct 05, 2016 10:53 am

please post your full code (or pm me), so I can try find a good way to set/reset the LED color using ColorLED . :)
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm

Re: Setting LED's keeps crashing my T2

Postby pablosscripts » Wed Oct 05, 2016 11:23 am

Thanks! I've uploaded it to online resources. See lines 896, 936, or 1240 (original attempt at this, commented out).

Image
Setup: XIM Apex, T2, K780 keyboard, G Pro Wireless mouse, SteelSeries 4HD pad, DXRacer armrest, LucidSound LS30 headset, Netduma router, Ubiquiti UniFi AP LR

My R6 script: https://youtu.be/x-9NtxyySVM
User avatar
pablosscripts
Brigadier General
Brigadier General
 
Posts: 1976
Joined: Tue Nov 24, 2015 6:27 am

Re: Setting LED's keeps crashing my T2

Postby J2Kbr » Wed Oct 05, 2016 12:39 pm

I changed the LED logic logic a little bit:

Code: Select all
if((rappelling_flag || AutoReloadAction) && !led_change_flag) {
        ColorLED('W');
        led_change_flag = 1;
    } else if((!rappelling_flag && !AutoReloadAction) && led_change_flag) {
        ColorLED('B');
        led_change_flag = 0;
    }
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm

Next

Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 177 guests