Button(s) hold time / average

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

Button(s) hold time / average

Postby Mad » Sat Dec 07, 2019 1:41 am

Single button hold time (button_5);
Code: Select all
main {
  if(event_release(BUTTON_5)) {
    printf("Held for %.2f secs",(fix32)time_active(BUTTON_5)/1000.0);
  }
}

Button 1-21 hold time;
Code: Select all
main {
 int8 i = 0;
   do {
    if(event_release(i)) {
      printf("BUTTON_%i held for %.3f Secs", i+1, (fix32)time_active(i)/1000f);
    }
  }
  while(++i!=STICK_1_X);
}

Button average hold time based on 10 presses (Dont@Me);
Code: Select all
uint16 io_time_actives[210];
uint8 io_release[20];
uint32 sum;
 
main {
  int8 i = 0;
  do {
    if(event_release(i)) {
      ++io_release[i] %= 10;
 
      io_time_actives[(i*10)+io_release[i]] = time_active(i);
 
      if(!io_release[i]){
 
        int8 n = 0;
        do{
          sum += io_time_actives[(i*10)+n];
        }while(++n<10);
 
        printf("BUTTON_%d average hold time: %.3f secs", i-1, (fix32)(sum/10)/1000f);
      }
    }
  }while(++i!=BUTTON_21);
}
ConsoleTuner Support Team || ConsoleTuner Discord || InputSense Discord
Mad
Major General
Major General
 
Posts: 4536
Joined: Wed May 22, 2019 5:39 am

Re: Button(s) hold time / average

Postby bonefisher » Sat Dec 07, 2019 3:11 am

:smile0517:
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am


Return to GPC2 Script Programming

Who is online

Users browsing this forum: Google [Bot] and 88 guests