Need help optimizing a script

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

Re: Need help optimizing a script

Postby Fenria » Mon Feb 11, 2019 4:00 pm

Now it will show info of all the buttons in the Device Monitor BUTTON_ fields during cfg mode using the tens/hundreds like 71 for "feature 7 & state 1".
Entering cfgmode disables the output port to avoid sending the debug output to the console, you will get a disconnect controller message on your console. This is why I didn't do it for all buttons at first.
This is done to avoid sending the debug info to the console. On leaving the config mode it will reconnect the output connection.
I'll test another idea so we don't need to disable the output.
Thank you very much for making that change.
I actually hadn't even thought of the fact that it would send the information to the console when I suggested it, so if you can find a way to make it so that you don't need to disable the output, I'd really appreciate it, but if you can't, that's entirely fine.

As far as the script itself, it works quite well, and I want to say thank you for fixing the double-tap issue.

I did notice that when just turbo or alternate turbo is actively running, the LED flashes pink and blue/red, and I was wondering, if it's not to much trouble, could you please change it so that the LED only flashes blue/red, with the times when the LED would be pink changed to the LED being off?
User avatar
Fenria
Command Sergeant Major
Command Sergeant Major
 
Posts: 147
Joined: Thu May 21, 2015 5:56 pm

Re: Need help optimizing a script

Postby Scachi » Mon Feb 11, 2019 5:31 pm

Turning purple off during turbo can be done easily by commenting out the lines 260..266 like this:
Code: Select all
 
/*
    // feature are selected and active but only one turbo is used, set non-turbo time to pink
    if (LastState[idx_LEDFH]==0 && LastVal[idx_LEDFTN]==0 && LastVal[idx_LEDFTA]==0) {
      ColorLED(LEDF[FNONE]); // pink led
    }
  }
  */

 

I am glad it is working fine for you.
CPU usage wise it is running fine here..do you still notice very high cpu usage when you are using it ?
I couldn't find any other usable way to output all the button feature&toggle.
Using text to write to the output panel I can't color them or draw border for the table so it is difficult to read.
I don't now if it is possible to use monospace text in the output panel so I don't need to use a table to align them and if there is something short than using that to color the text per item:
Code: Select all
<b><font color='#00802b'>INFO</font></b>

If we can fit each line (included the format/color) in a char[400] then this would be easier to read.
It looks at the moment:
op_btns.jpg
op_btns.jpg (38.63 KiB) Viewed 1224 times


Maybe J2kbr has an idea where we don't have to switch the output off.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Need help optimizing a script

Postby Sillyasskid » Mon Feb 11, 2019 8:07 pm

Scachi wrote:Using text to write to the output panel I can't color them or draw border for the table so it is difficult to read. I don't now if it is possible to use monospace text in the output panel so I don't need to use a table to align them
. . .


mono space text in the output panel can be done using the <pre> tag
example,
Code: Select all
init{
  printf("<b><font color='green'>INFO</font></b><pre><b>\
   B:1    B:2    B:3    B:4    B:5    B:6    B:7    B:8    B:9 </b><br>\
  %-06.2f %-06.2f %-06.2f %-06.2f %-06.2f %-06.2f %-06.2f %-06.2f %-06.2f<pre>",
  10f, 20f, 30f, 40f, 50f, 60f, 70f, 80f, 90f);
}
259 bytes

Tables in the output panel can be done using the normal html table tags
example,
Code: Select all
init{
printf("\
<b><font color='green'>INFO</font></b>\
<table cellspacing='0' border='.25'>\
<tr>\
<td>B:1</td>\
<td>B:2</td>\
<td>B:3</td>\
<td>B:4</td>\
<td>B:5</td>\
<td>B:6</td>\
<td>B:7</td>\
<td>B:8</td>\
<td>B:9</td>\
</tr><tr>\
<td>%-06.2f</td>\
<td>%-06.2f</td>\
<td>%-06.2f</td>\
<td>%-06.2f</td>\
<td>%-06.2f</td>\
<td>%-06.2f</td>\
<td>%-06.2f</td>\
<td>%-06.2f</td>\
<td>%-06.2f</td>\
</tr>\
</table>",
  10f, 20f, 30f, 40f, 50f, 60f, 70f, 80f, 90f);
}
416 bytes
User avatar
Sillyasskid
Captain
Captain
 
Posts: 574
Joined: Sat May 14, 2016 3:07 am

Re: Need help optimizing a script

Postby Scachi » Mon Feb 11, 2019 8:15 pm

Thank you !
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Need help optimizing a script

Postby Fenria » Mon Feb 11, 2019 10:25 pm

Turning purple off during turbo can be done easily by commenting out the lines 260..266 like this:
Code: Select all
 
/*
    // feature are selected and active but only one turbo is used, set non-turbo time to pink
    if (LastState[idx_LEDFH]==0 && LastVal[idx_LEDFTN]==0 && LastVal[idx_LEDFTA]==0) {
      ColorLED(LEDF[FNONE]); // pink led
    }
  }
  */

 
Whelp, I'm blind.
Thanks for pointing that out.

CPU usage seems fine, though I think the last time I actually tested assigning and activating a function on every button to try and max out CPU usage was one of the first couple iterations of the script.

(Edit: Just tested The CPU usage with all buttons having assgned functions, and it's fine, as with all buttons having a multi-feature function set, which would theoretically be the most CPU intensive feature, I can have four of them using turbo/alternate turbo before the CPU usage causes a problem, which is one more than the most I would typically use at the same time, and while using only the non-multi function features, there seems to be no limitation in the number I can have active.)

A output panel based method would be highly preferable to having to have the T2 disconnect itself, and while I don't know how the mono-space or table variants would look, the example you posted works rather well, though it's a bit visually clunky.

Assuming that it updates/appears when the script enters config mode, as well as whenever a function is changed, and there's no way to display the values on the button outputs while keeping the Titan Two from sending the values to the console, without having to change the Titan Two's output protocol, then I think the output panel method would be the best option.

Edit 2:
I just noticed that the pink LED seems to go out on the controller when functions and config mode have not been used for a short period of time, though it stays active on the Titan Two.

I'm not sure why it does that, and I checked the script as best I could and didn't see anything that would cause it, but I don't understand the code that well, so could you please check as well just to be safe?

Edit 3:
I also just noticed that due to the addition of the disconnect feature that was required in order to use the button outputs to display the current features and toggles, the output protocol change feature no longer works, and the script will always use the automatic output protocol when exiting config mode.

It's mostly a non-issue though, as assumming that you decide to use the output panel based method that wouldn't require the Titan Two to be disconnected to preven it from sending the infromation to the console as button states, the disconnect function should be able to be removed.
User avatar
Fenria
Command Sergeant Major
Command Sergeant Major
 
Posts: 147
Joined: Thu May 21, 2015 5:56 pm

Re: Need help optimizing a script

Postby Scachi » Tue Feb 12, 2019 2:13 pm

Here is a version with debug feature state via the Output Panel, it shows '^' for buttons with selected features and '+' for the one last modified :
op_btns_pre.jpg
op_btns_pre.jpg (23.23 KiB) Viewed 1203 times

The feature state info is still shown during cfgmode only.

//2 : I can't replicate the issue with the purple led going of..it stays on for me correctly on T2 and controller, via usb cable and bluetooth.
maybe you can find a way to reproduce this.

//3 : removed the disconnect code and previous debug mode
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Need help optimizing a script

Postby Fenria » Tue Feb 12, 2019 3:30 pm

That seems like it would work quite well, and is easier to read than the example you provided before.

As far as the purple LED going out, I have determined that it occurs randomly, though typically within five minutes, as long as the controller is connected via USB and nothing that would cause the script to update the LEDs, like entering/exiting config mode or using a function, is done, and the only way to turn the purple LED back on is to do something that updates the LEDs.

It doesn't seem to occur when using the controller via bluetooth though.

Edit:
I have eliminated the possibility that it is a USB cable issue by setting the controller and Titan Two on a table to prevent the usb cable from moving, and I have not had any issues with the blue LED going out when using the Titan Two without a script loaded, leading me to believe that it is either my controller, Titan Two, or the script.

At this point though, I am starting to think that it has something to do with this script's method for setting the default purple LED, as when using the Titan Two with the ABTH script you created earlier that does not change the LEDs, the blue light does not go out.

Edit 2:
I just tested the following script that uses the LED control function from the first script I posted to make sure that it was not actually my controller or the Titan Two, and there were no issues with the purple LED going out.
Code: Select all
int16 LC = 0;
int16 LC1 = 0;
int16 LC2 = 0;
int16 LC3 = 0;
 
main {
    fLED_Control();
}
 
void fLED_Control() {
    if (LC1 || LC2 || LC3 == 1)    {
        LC = 1;
    }
    else    {
        LC = 0;
    }
    if (LC1 == 0 && led_get(LED_1, NULL) != 0.0)    {
        led_set(LED_1, 0.0, 0);
    }
    if (LC2 == 0 && led_get(LED_3, NULL) != 0.0)    {
        led_set(LED_3, 0.0, 0);
    }
    if (LC2 == 1 && led_get(LED_3, NULL) != 100.0)    {
        led_set(LED_3, 100.0, 0);
    }
    if (LC3 == 0 && led_get(LED_2, NULL) != 0.0)    {
        led_set(LED_2, 0.0, 0);
    }
    if (LC == 0 && led_get(LED_4, NULL) != 100.0)    {
        led_set(LED_4, 100.0, 0);
    }
    if (LC == 1 && led_get(LED_4, NULL) != 0.0)    {
        led_set(LED_4, 0.0, 0);
    }
}
Last edited by Fenria on Tue Feb 12, 2019 4:19 pm, edited 2 times in total.
User avatar
Fenria
Command Sergeant Major
Command Sergeant Major
 
Posts: 147
Joined: Thu May 21, 2015 5:56 pm

Re: Need help optimizing a script

Postby Scachi » Tue Feb 12, 2019 4:12 pm

Do you have any features assigned to buttons or does this still happen when you just loading the script and have it staying idle without doing anything ?

Got i happen here too now, so I can investigate and fix it a lot easier. No idea why it didn't happen before.

//edit:
It is led_vmset that doesn't work like it should, I'll add it to github and fix the script by using another command for now.
According to the documentation this should get permament light..but shuts off after 1sec:
Code: Select all
init{
  led_vmset(LED_1, 1000, 0, -1);
}
 
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Need help optimizing a script

Postby Fenria » Tue Feb 12, 2019 4:40 pm

I just tested with the script in config mode, out of config mode, in config mode while having features assigned but not active, and out of config mode while having features assigned but not active, and in all cases, within about 5 minutes since the last event that would cause the script to update the LEDs, the purple LED goes out.

Edit:
I just tested the script with hold active on a button to see if the green LED would turn off, and it turns out that, instead, the purple LED turns on, while the green LED is still on, and hold is still active on the button, resulting in a white LED on both the Titan Two and the controller.
Last edited by Fenria on Tue Feb 12, 2019 4:47 pm, edited 1 time in total.
User avatar
Fenria
Command Sergeant Major
Command Sergeant Major
 
Posts: 147
Joined: Thu May 21, 2015 5:56 pm

Re: Need help optimizing a script

Postby Scachi » Tue Feb 12, 2019 4:45 pm

Fenria wrote:I tested with the script in config mode, out of config mode, in config mode while having features assigned but not active, and out of config mode while having features assigned but not active, and in all cases, within about 5 minutes since the last event that would cause the script to update the LEDs, the purple LED goes out.

Add this line before the ColorLED include line:
Code: Select all
#define _ColorBrightness

so it should read now:
Code: Select all
#define _ColorBrightness
#include "ColorLED.gph"

It will work correctly then.

Bug report updated for j2kbr to investigate: https://github.com/J2Kbr/TitanTwo/issues/170
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

PreviousNext

Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 120 guests