Listen for any I/O on T2 for Macro Record?

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

Listen for any I/O on T2 for Macro Record?

Postby USER101 » Mon Dec 10, 2018 10:52 pm

This is my first time using macro record and I want it to function like the one in the online resources where it has an indicator letting you know that once you make a move it starts recording. I thought leaving check_active() open would listen for any input. Trying to create my own Macro Recorder and want to go standby until any input is hit at which point macro_rec("<filename>.gmk"); starts. I want to know how to listen for any input. Any help would be appreciated. Thanks

Code: Select all
    if(check_active(XB1_RB,2000) && check_active(XB1_LB,2000)) { //Start Macro recorder standby
        if(standby || check_active()){standby = FALSE;}
        else{standby = TRUE;}
        }
 
User avatar
USER101
Sergeant Major
Sergeant Major
 
Posts: 100
Joined: Mon Dec 03, 2018 5:45 pm

Re: Listen for any I/O on T2 for Macro Record?

Postby Sillyasskid » Tue Dec 11, 2018 12:22 am

Code: Select all
#include <xb1.gph>
main {
  if(macro_time() == -1) {
    if(check_active(XB1_RB,2000) && check_active(XB1_LB,2000)) {
      if(check_for_active_buttons()) {
        macro_rec("<filename>.gmk");
      }
    }
  }
  else {
//  if( Conditon to end the macro recording ) {
//    macro_stop();
//  }
  }
}
 
 
bool check_for_active_buttons(){
  int i = 21;
  // Checks if any Button I/O, (1 thru 21) are active.
  while(i--){
  // Ignores RB and LB.
    if(i == XB1_RB | i == XB1_LB) --i;
  // Does not check any IO after BUTTON_21.
    if(get_actual(i)) return TRUE;
  }
  return FALSE
}

Is this what you were trying to do?
User avatar
Sillyasskid
Captain
Captain
 
Posts: 574
Joined: Sat May 14, 2016 3:07 am

Re: Listen for any I/O on T2 for Macro Record?

Postby USER101 » Tue Dec 11, 2018 12:47 am

Oh hell yeah!!! Thank you so much.
User avatar
USER101
Sergeant Major
Sergeant Major
 
Posts: 100
Joined: Mon Dec 03, 2018 5:45 pm

Re: Listen for any I/O on T2 for Macro Record?

Postby Sillyasskid » Tue Dec 11, 2018 12:58 am

:smile0203:
User avatar
Sillyasskid
Captain
Captain
 
Posts: 574
Joined: Sat May 14, 2016 3:07 am

Re: Listen for any I/O on T2 for Macro Record?

Postby USER101 » Tue Dec 11, 2018 6:13 pm

I am trying to implement your code but it does not seem to work. Any idea why on the T2? Could it be that "i" has to match the actual GPC Designators? Like BUTTON_5 instead of just 5. I even tried #include <titanone.gph> just to see if. If I replace (activity) with (event_active(XB1_B) for example the LED does change color when I press B.

Code: Select all
#pragma METAINFO("<author_name>", 1, 0, "")
#include "ColorLED.gph"
#include <xb1.gph>
 
bool activity(){ // Checks if any buttons I/O, (1 thru 24) are active.
        uint8 i = 24;
        while(i--){
            if(get_actual(i)) return TRUE;
            }
        return FALSE
        }
 
/*  ////////////////////////
    //Section 8: MAIN CODE//
    ////////////////////////
*/

main {
    if(activity){ // Check if any button is being pressed.
        ColorLED(CW);
        }
 
}
User avatar
USER101
Sergeant Major
Sergeant Major
 
Posts: 100
Joined: Mon Dec 03, 2018 5:45 pm

Re: Listen for any I/O on T2 for Macro Record?

Postby Sillyasskid » Tue Dec 11, 2018 6:43 pm

Fixed.
Code: Select all
#include "ColorLED.gph"
#include <xb1.gph>
 
bool activity(){ // Checks if any buttons I/O, (1 thru 24) are active.
  uint8 i = 25;
  while(i--){
    if(is_active(i)) return TRUE;
  }
  return FALSE
}
 
/*  ////////////////////////
    //Section 8: MAIN CODE//
    ////////////////////////
*/

main {
  if(activity()){ // Check if any button is being pressed.
    ColorLED(CW);
  }
}
The error was with your if statement,
if(activity)
It should have been
if(activity())

I also changed the
if(get_actual(i))
to
if(is_active(i))
Because I noticed you were also checking for stick movements.

When the sticks reach 20% in either direction, it will be considered active, with the is_active() function.
If you used the get_actual() function, it would return true, for any value thats not 0.
User avatar
Sillyasskid
Captain
Captain
 
Posts: 574
Joined: Sat May 14, 2016 3:07 am

Re: Listen for any I/O on T2 for Macro Record?

Postby USER101 » Tue Dec 11, 2018 8:21 pm

I only started a few days ago and I am learning based on examples. I almost have a solid product and thanks to you I am learning even more! You are awesome and thanks for the quick feedback!
User avatar
USER101
Sergeant Major
Sergeant Major
 
Posts: 100
Joined: Mon Dec 03, 2018 5:45 pm


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 100 guests