cfgdesc + custom button presses
12 posts
• Page 1 of 2 • 1, 2
cfgdesc + custom button presses
I'm trying to build an Interactive Configurator that lets you choose which button you want to use to trigger a part of my script.
I'm stuck - I've got the shell of this, but I'm not sure how to finish it. Any ideas? This is what I have so far:
I'm stuck - I've got the shell of this, but I'm not sure how to finish it. Any ideas? This is what I have so far:
- Code: Select all
#include <ps4.gph>
#define SPRINT PS4_L3 // This example uses the sprint button (so double tap sprint).
#define VAULT PS4_CROSS
int doubletap_stage_swap = 0;
int doubletap_timing_swap;
/*
<cfgdesc>
[Double Tap Button Selector]
shortdesc = Select the button you would like to double tap.
byteoffset = 1
bitsize = 8
control = combobox
default = 5
item = SPRINT
item = VAULT
</cfgdesc>
*/
uint8 button_var;
init {
pmem_load();
button_var = pmem_read(1);
pmem_read(1, &button_var);
}
main {
// Replace all instances of "SPRINT" with the button press or action that you want to trigger this script.
if(get_val(button_var)) { // Replace
if(doubletap_stage_swap == 0) {
if(get_val(button_var)) { // Replace
doubletap_stage_swap = 1;
}
} else if(doubletap_stage_swap == 1) {
if(!get_val(button_var)) { // Replace
doubletap_timing_swap = 0;
doubletap_stage_swap = 2;
}
} else if(doubletap_stage_swap == 2) {
if(get_val(button_var)) { // Replace
doubletap_stage_swap = 1;
// Enter code you want to trigger here.
}
doubletap_timing_swap = doubletap_timing_swap + elapsed_time();
// Change this to increase / decrease timing between double taps. I have found 150-200 to be the sweet spot.
if(doubletap_timing_swap > 200) {
doubletap_stage_swap = 0;
}
}
}
}
Last edited by pablosscripts on Fri Oct 07, 2016 3:08 am, edited 2 times in total.
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
My R6 script: https://youtu.be/x-9NtxyySVM
-
pablosscripts - Brigadier General
- Posts: 1976
- Joined: Tue Nov 24, 2015 6:27 am
Re: cfgdesc + custom button presses
Buttons are of type uint8, so get_val(button_var) only works with variables of type uint8.
Your cfgdesc defines a value with bitsize of 8, but you are reading it into a variable of type fix32, not sure if that will work at all.
change
fix32 button_var;
to
uint8 button_var;
Your cfgdesc defines a value with bitsize of 8, but you are reading it into a variable of type fix32, not sure if that will work at all.
change
fix32 button_var;
to
uint8 button_var;
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: cfgdesc + custom button presses
Great thanks for that. I updated my code in the OP. Does this look like the correct approach? Does my logic make sense? I'm not at home to test this.
- Code: Select all
button_var = pmem_read(1);
pmem_read(1, &button_var);
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
My R6 script: https://youtu.be/x-9NtxyySVM
-
pablosscripts - Brigadier General
- Posts: 1976
- Joined: Tue Nov 24, 2015 6:27 am
Re: cfgdesc + custom button presses
I think this won't work. Reading the combobox just return the index of the selected item.
If you have defined 8 items to a combobox then the returned value is one of: 0,1,2,3...7
So you may have to do some magic to actually translate the item index to the button value you want it to be.
If you have defined 8 items to a combobox then the returned value is one of: 0,1,2,3...7
So you may have to do some magic to actually translate the item index to the button value you want it to be.
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: cfgdesc + custom button presses
Scachi wrote:I think this won't work. Reading the combobox just return the index of the selected item.
If you have defined 8 items to a combobox then the returned value is one of: 0,1,2,3...7
So you may have to do some magic to actually translate the item index to the button value you want it to be.
Dammit:(
J2Kbr, could you help us with some code samples?:)
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
My R6 script: https://youtu.be/x-9NtxyySVM
-
pablosscripts - Brigadier General
- Posts: 1976
- Joined: Tue Nov 24, 2015 6:27 am
Re: cfgdesc + custom button presses
Maybe it will work with this init:
- Code: Select all
init {
uint8 dbutton;
pmem_load();
pmem_read(1, &dbutton);
switch (dbutton) {
case 0: button_var = BUTTON_9; break;
case 1: button_var = BUTTON_16; break;
default:button_var = BUTTON_9; break;
}
}
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: cfgdesc + custom button presses
Scachi pointed a good solution for this!!
ConsoleTuner Support Team
-
J2Kbr - General of the Army
- Posts: 20323
- Joined: Tue Mar 18, 2014 1:39 pm
Re: cfgdesc + custom button presses
This didn't work:
- Code: Select all
#pragma METAINFO("Example - Double Tap Modifer", 1, 0, "pablogroup")
#include <ps4.gph>
#define SPRINT PS4_L3 // This example uses the sprint button (so double tap sprint).
#define VAULT PS4_CROSS
#define RELOAD PS4_SQUARE
int doubletap_stage_swap = 0;
int doubletap_timing_swap;
/*
<cfgdesc>
[Double Tap Button Selector]
shortdesc = Select the button you would like to double tap.
byteoffset = 1
bitsize = 8
control = combobox
default = 5
item = SPRINT
item = VAULT
</cfgdesc>
*/
uint8 button_var;
init {
uint8 dbutton;
pmem_load();
pmem_read(1, &dbutton);
switch (dbutton) {
case 0: button_var = SPRINT; break;
case 1: button_var = VAULT; break;
default:button_var = VAULT; break;
}
}
main {
// Replace all instances of "SPRINT" with the button press or action that you want to trigger this script.
if(get_val(button_var)) { // Replace
if(doubletap_stage_swap == 0) {
if(get_val(button_var)) { // Replace
doubletap_stage_swap = 1;
}
} else if(doubletap_stage_swap == 1) {
if(!get_val(button_var)) { // Replace
doubletap_timing_swap = 0;
doubletap_stage_swap = 2;
}
} else if(doubletap_stage_swap == 2) {
if(get_val(button_var)) { // Replace
doubletap_stage_swap = 1;
// Enter code you want to trigger here.
combo_run(ReloadForce);
}
doubletap_timing_swap = doubletap_timing_swap + elapsed_time();
// Change this to increase / decrease timing between double taps. I have found 150-200 to be the sweet spot.
if(doubletap_timing_swap > 200) {
doubletap_stage_swap = 0;
}
}
}
}
combo ReloadForce {
set_val(RELOAD, 100);
wait(40);
}
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
My R6 script: https://youtu.be/x-9NtxyySVM
-
pablosscripts - Brigadier General
- Posts: 1976
- Joined: Tue Nov 24, 2015 6:27 am
Re: cfgdesc + custom button presses
I am using something like this in my division script.
With this function you can check for more than one button for double tap.
// arg1:the button to be checked
// arg2: the max time for a double tap
// arg3: stores the state for the current button check result so this function can be used for multiple buttons
uint8 check_clicktype(uint8 btn, uint16 maxtime, uint8 *stat)
"BPress" in this example contains the result (no click=0, single click=1, doubleclick=2)
The single tap is only reported after the timeout for the double tap is reached.
Without that is will always report a single tap before a double tap may happen.
The drawback is that there is a small delay before a single click is reported.
With this function you can check for more than one button for double tap.
// arg1:the button to be checked
// arg2: the max time for a double tap
// arg3: stores the state for the current button check result so this function can be used for multiple buttons
uint8 check_clicktype(uint8 btn, uint16 maxtime, uint8 *stat)
"BPress" in this example contains the result (no click=0, single click=1, doubleclick=2)
The single tap is only reported after the timeout for the double tap is reached.
Without that is will always report a single tap before a double tap may happen.
The drawback is that there is a small delay before a single click is reported.
- Code: Select all
#include <ps4.gph>
/*
<cfgdesc>
[Double Tap Button Selector]
shortdesc = Select the button you would like to double tap.
byteoffset = 1
bitsize = 8
control = combobox
default = 5
item = SPRINT
item = VAULT
</cfgdesc>
*/
#define SPRINT PS4_L3 // This example uses the sprint button (so double tap sprint).
#define VAULT PS4_CROSS
#define RELOAD PS4_SQUARE
uint8 button_var = 0;
uint8 BPress = 0; // result of doubleclick check
uint8 BState = 0; // state tracker for doubleclick check
init {
uint8 dbutton;
pmem_load();
pmem_read(1, &dbutton);
switch (dbutton) {
case 0: button_var = SPRINT; break;
case 1: button_var = VAULT; break;
default:button_var = VAULT; break;
}
}
main {
BPress=check_clicktype(button_var, 260, &BState);
if ( BPress == 1 ) printf("Single Button press");
if ( BPress == 2 ) printf("Double Button press");
}
// check if button press was single or double, returns: 0(none),1(single),2(double)
uint8 check_clicktype(uint8 btn, uint16 maxtime, uint8 *stat) {
uint8 clicktype = 0;
if (*stat == 0 && event_active(btn)) { // first press
*stat=1;
// printf("First press");
} else if (*stat == 1 && event_release(btn)) *stat=2; // first release
if ( *stat > 0 && time_active(btn) > maxtime && time_release(btn) > maxtime ) { // time out = single press
*stat=0; clicktype = 1;
// printf("Timeout = Single press");
}
if (*stat == 2 && event_active(btn)) { // second press
*stat=0; clicktype = 2;
// printf("DOUBLE press");
}
return clicktype;
}
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: cfgdesc + custom button presses
Is it just me or does copy/paste from gpc code from posts into the gtuner software mess up the code indentation ?
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
12 posts
• Page 1 of 2 • 1, 2
Return to GPC2 Script Programming
Who is online
Users browsing this forum: No registered users and 118 guests