PSP-Nx v3 Button Problem

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
dudmaster
Posts: 171
Joined: 06 Oct 2010, 02:38
Location: Texas, Santa Fe
Contact:

PSP-Nx v3 Button Problem

Post by dudmaster »

Hello all, I am having trouble with the buttons on the PSP controller. I am using NXC, and i am using the button "PSP_BTNSET2_SQUARE"
and the command ReadSensorMSPlayStation(); command. I have it in Analog mode.

I have some code:

Code: Select all

until(b2 == BTN_SET2_SQUARE);
...And that doesn't work.

Does anybody know the problem?
2Labz.com, My Website
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: PSP-Nx v3 Button Problem

Post by mattallen37 »

I use something like this for reading buttons. Note, it uses very different specifics than what I currently use, but the concept is similar.

Code: Select all

int sel,str,up,dwn,lft,rght,L2,R2,L1,R1,tri,cir,crs,squ,sl,sr,b1,b2,B1,B2,lx,ly,rx,ry;
task main()
{
  SetSensorLowspeed(S3);
  while (true)
  {

    ReadSensorMSPlayStation(S3, 0x02, b1, b2, lx, ly, rx, ry);
    B2=b2*(-1)+255;
    if (B2>=128){squ=1;B2=B2-128;}else{squ=0;}
    if (B2>=64){crs=1;B2=B2-64;}else{crs=0;}
    if (B2>=32){cir=1;B2=B2-32;}else{cir=0;}
    if (B2>=16){tri=1;B2=B2-16;}else{tri=0;}
    if (B2>=8){R1=1;B2=B2-8;}else{R1 =0;}
    if (B2>=4){L1=1;B2=B2-4;}else{L1 =0;}
    if (B2>=2){R2=1;B2=B2-2;}else{R2 =0;}
    if (B2>=1){L2=1;B2=B2-1;}else{L2 =0;}

    B1=b1*(-1)+255;
    if (B1>=128){lft=1;B1=B1-128;}else{lft=0;}
    if (B1>=64){dwn=1;B1=B1-64;}else{dwn=0;}
    if (B1>=32){rght=1;B1=B1-32;}else{rght=0;}
    if (B1>=16){up=1;B1=B1-16;}else{up=0;}
    if (B1>=8){str=1;B1=B1-8;}else{str=0;}
    if (B1>=4){sr=1;B1=B1-4;}else{sr =0;}
    if (B1>=2){sl=1;B1=B1-2;}else{sl =0;}
    if (B1>=1){sel=1;B1=B1-1;}else{sel=0;}
  
    ClearScreen();                        //    ___________________
    NumOut(15,60,L2);                     //   | L2*           *R2 |
    NumOut(78,60,R2);                     //   | L1*           *R1 |
    NumOut(15,50,L1);                     //   |  up          tri  |
    NumOut(78,50,R1);                     //   |   *   selstr  *   |
    NumOut(78,35,tri);                    //   |lft     * *     cir|
    NumOut(93,20,cir);                    //   |*     *rght *squ  *|
    NumOut(78,0,crs);                     //   |  dwn sl   sr crs  |
    NumOut(63,20,squ);                    //   |   *   *   *   *   |

    NumOut(40,30,sel);
    NumOut(35,0,sl);
    NumOut(58,0,sr);
    NumOut(53,30,str);
    NumOut(15,35,up);
    NumOut(30,20,rght);
    NumOut(15,0,dwn);
    NumOut(0,20,lft);
    
    NumOut(21,LCD_LINE1,ly);
    NumOut(21,LCD_LINE2,lx);
    NumOut(50,LCD_LINE1,ry);
    NumOut(50,LCD_LINE2,rx);
    
  }
}
/*

b1 series

sel      =1
sl       =2
sr       =4
str      =8
up       =16
rght     =32
dwn      =64
lft      =128

b2 series

L2       =1
R2       =2
L1       =4
R1       =8
tri      =16
cir      =32
crs      =64
squ      =128
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
dudmaster
Posts: 171
Joined: 06 Oct 2010, 02:38
Location: Texas, Santa Fe
Contact:

Re: PSP-Nx v3 Button Problem

Post by dudmaster »

Well, thanks a lot. I got my program to work using this "sub" program. THX! Dud
2Labz.com, My Website
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: PSP-Nx v3 Button Problem

Post by mattallen37 »

You're welcome, but it is not as efficient as it could be. If you do something like this, it would be more efficient.

Code: Select all

    B2=~b2;
    squ = (B2 >> 7) & 0x01;
    crs = (B2 >> 6) & 0x01;
    cir = (B2 >> 5) & 0x01;
    tri = (B2 >> 4) & 0x01;
    R1  = (B2 >> 3) & 0x01;
    L1  = (B2 >> 2) & 0x01;
    R2  = (B2 >> 1) & 0x01;
    L2  = (B2 >> 0) & 0x01;

    B1=~b1;
    lft = (B1 >> 7) & 0x01;
    dwn = (B1 >> 6) & 0x01;
    rght= (B1 >> 5) & 0x01;
    up  = (B1 >> 4) & 0x01;
    str = (B1 >> 3) & 0x01;
    sr  = (B1 >> 2) & 0x01;
    sl  = (B1 >> 1) & 0x01;
    sel = (B1 >> 0) & 0x01;
Or you could do:

Code: Select all

    squ = (~b2 >> 7) & 0x01;
    crs = (~b2 >> 6) & 0x01;
    cir = (~b2 >> 5) & 0x01;
    tri = (~b2 >> 4) & 0x01;
    R1  = (~b2 >> 3) & 0x01;
    L1  = (~b2 >> 2) & 0x01;
    R2  = (~b2 >> 1) & 0x01;
    L2  = (~b2 >> 0) & 0x01;

    lft = (~b2 >> 7) & 0x01;
    dwn = (~b2 >> 6) & 0x01;
    rght= (~b2 >> 5) & 0x01;
    up  = (~b2 >> 4) & 0x01;
    str = (~b2 >> 3) & 0x01;
    sr  = (~b2 >> 2) & 0x01;
    sl  = (~b2 >> 1) & 0x01;
    sel = (~b2 >> 0) & 0x01;
There are many other ways to do it as well.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
chanyh
Posts: 17
Joined: 11 Oct 2010, 05:14

Re: PSP-Nx v3 Button Problem

Post by chanyh »

Hi, Matt,

What are the meanings of the statements "B2=b2*(-1)+255;" and "B1=b1*(-1)+255;" and their purposes?

What are the values of the buttons in the PSP controller?

Can you help explain?


YH Chan
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: PSP-Nx v3 Button Problem

Post by mattallen37 »

Before I learned about bitwise operators, I would use the statement B2=b2*(-1)+255; to invert a byte (bitwise NOT, in C represented by "~"). It is just a simple math function that would do just exactly what it looks like. It would assign the value of ~b2 to B2. "B2 equals b2 times negative one plus two hundred and fifty five".

The button values are as follows.

b1 series

sel =1
sl =2
sr =4
str =8
up =16
rght =32
dwn =64
lft =128

b2 series

L2 =1
R2 =2
L1 =4
R1 =8
tri =16
cir =32
crs =64
squ =128

Is that what you wanted?
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: PSP-Nx v3 Button Problem

Post by muntoo »

You may also want to take a look at the Documentation with so many registers you'll start hearing "ka-ching" all the time. And don't forget the example program with its own library.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: PSP-Nx v3 Button Problem

Post by nxtboyiii »

I agree with muntoo. The library is much easier to use.
BTW, when a button is pressed on the PSP-nx, the value equals zero, or false. So instead of doing, for example,
if(psp.square == true), it would be if(psp.square == false). :D
Thanks, and have a nice day,
nxtboy III

programnxt.com
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: PSP-Nx v3 Button Problem

Post by mattallen37 »

nxtboyiii wrote:...BTW, when a button is pressed on the PSP-nx, the value equals zero, or false. So instead of doing, for example,
if(psp.square == true), it would be if(psp.square == false). :D
That is why I use the bitwise NOT operator before I begin.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
chanyh
Posts: 17
Joined: 11 Oct 2010, 05:14

Re: PSP-Nx v3 Button Problem

Post by chanyh »

Matt, muntoo,

Thanks!

YH Chan.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests