PS4 TouchPad Help

GPC1 script programming for Titan One. Code examples, questions, requests.

PS4 TouchPad Help

Postby xenologer » Wed Jun 06, 2018 2:37 pm

Hey

I'd doing a simple test script to attempt to Detect touchpad swipes and direction - up, down, left, right.

But I'm getting an odd bug where if the touch swipe crosses the origin, I get an unexpected reversed +-signed result.

Note the Trace Values 4 and 5. keying on these to determine the touch swipe direction.

Can anyone see what I might have missed?
Thanks

Code: Select all
 
/* *
* GPC SCRIPT
*
*  GPC is a scripting language with C-like syntax.
*  To learn more access GPC Language Reference on Help menu.
* *********************************************************** */

int TOUCHING=0;
int tx1,tx2,txd;
int ty1,ty2,tyd;
 
main {
 
    if(ps4_touchpad(PS4T_P1)) {
        set_val(TRACE_1, 100);
        set_val(TRACE_2, ps4_touchpad(PS4T_P1X));
        set_val(TRACE_3, ps4_touchpad(PS4T_P1Y));
    } else set_val(TRACE_1, 0);
 
    //DETECT and save first touch point
    if(!TOUCHING){
         if(ps4_touchpad(PS4T_P1)) {
            TOUCHING=1;
            tx1=ps4_touchpad(PS4T_P1X);
            ty1=ps4_touchpad(PS4T_P1Y);
         }
    }
 
    if(TOUCHING){
        //Continued touch input held (in motion)
        if(ps4_touchpad(PS4T_P1)){
            tx2=ps4_touchpad(PS4T_P1X);
            ty2=ps4_touchpad(PS4T_P1Y);
        }
        //DETECT touch ending point
        if(!ps4_touchpad(PS4T_P1)){
            TOUCHING=0;
            txd=tx2-tx1;
            tyd=ty2-ty1;
 
            //FIND DIRECTION
            if(abs(txd)>abs(tyd)){
                //horizontal sweep
                if(txd>0){
 
                }else{
 
                }
 
            }else{
                //vertical sweep
                if(tyd>0){
 
                }else{
 
                }
 
            }
 
 
 
        }
    }
 
    set_val(TRACE_4,txd);
    set_val(TRACE_5,tyd);
 
}
 
//blue,red,green,purple
function LED(a, b, c, d){
    set_led(0, a);
    set_led(1, b);
    set_led(2, c);
    set_led(3, d);
}
 
 
Last edited by xenologer on Thu Jun 07, 2018 2:50 am, edited 1 time in total.
User avatar
xenologer
Command Sergeant Major
Command Sergeant Major
 
Posts: 147
Joined: Thu Dec 29, 2016 12:31 am

Re: PS4 TouchPad Help

Postby xenologer » Thu Jun 07, 2018 2:01 am

I'm just using straightforward vector math:
mark the coordinates of touch start
mark coordinates of touch stopping
then subtract the difference, and check +-signage to determine direction
fairly clear cut

so most likely, I'm misinterpreting how the touchpad states work or something; if there is something I'm missing, I haven't found it in the GPC docs....
User avatar
xenologer
Command Sergeant Major
Command Sergeant Major
 
Posts: 147
Joined: Thu Dec 29, 2016 12:31 am

Re: PS4 TouchPad Help

Postby J2Kbr » Thu Jun 07, 2018 7:46 am

Your script seems to be correct and should work.
xenologer wrote:But I'm getting an odd bug where if the touch swipe crosses the origin, I get an unexpected reversed +-signed result.

Maybe because the value on TRACE_* is overflowing, TRACE_ can only display signed 8bits integers (-128 to 127), and your math can potentially result on values out of this range (up to 200), which overflows. however the variables txd and tyd have the correct value and the script should work as expected.
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: PS4 TouchPad Help

Postby xenologer » Thu Jun 07, 2018 9:50 am

Yes that was exactly it!
scaling the values before display results in the correct signage
Thanks very much
User avatar
xenologer
Command Sergeant Major
Command Sergeant Major
 
Posts: 147
Joined: Thu Dec 29, 2016 12:31 am


Return to GPC1 Script Programming

Who is online

Users browsing this forum: No registered users and 106 guests