Multipul button input?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Vale
Posts: 4
Joined: Fri Jul 22, 2005 7:27 am

Multipul button input?

Post by Vale »

ok im using the PSPSDK header pspctrl.h:

Code: Select all

#ifndef __CTRL_H__
#define __CTRL_H__

#ifdef __cplusplus
extern "C" {
#endif

enum CtrlButtons
{

	CTRL_SQUARE     = 0x8000,
	CTRL_TRIANGLE   = 0x1000,
	CTRL_CIRCLE     = 0x2000,
	CTRL_CROSS      = 0x4000,
	CTRL_UP         = 0x0010,
	CTRL_DOWN      	= 0x0040,
	CTRL_LEFT      	= 0x0080,
	CTRL_RIGHT      = 0x0020,
	CTRL_START      = 0x0008,
	CTRL_SELECT     = 0x0001,
	CTRL_LTRIGGER   = 0x0100,
	CTRL_RTRIGGER   = 0x0200,
};

/** Returned controller data */
typedef struct _ctrl_data
{
	/** The current read frame */
	u32 frame;
	/** Bit mask containing zero or more of CtrlButtons */
	u32 buttons;
	/** Analogue stick, X direction */
	u8  analog_x;
	/** Analogue stick, Y direction */
	u8  analog_y; 
	/** Dummy padding value */
	u16 dummy;
	/** Seemingly unused */
	u32 unused;
} __attribute__((packed)) ctrl_data_t; 

/**
 * Set controller sample rate
 *
 * @par Example:
 * @see sceCtrlReadBufferPositive
 *
 * @param arg Should be set to 0
 */
void sceCtrlSetSamplingCycle(int arg);
/**
 * Set the sampling mode
 *
 * @par Example:
 * @see sceCtrlReadBufferPositive
 *
 * @param on - Pass 1 to enable analogue mode
 */
void sceCtrlSetSamplingMode(int on);
/**
 * Read buffer positive
 *
 * @par Example:
 * @code
 * ctrl_data_t pad;

 * sceCtrlSetSamplingCycle(0);
 * sceCtrlSetSamplingMode(1);
 * sceCtrlReadBufferPositive(&pad, 1); 
 * // Do something with the read controller data
 * @endcode
 *
 * @param pad_data - Structure to hold the returned pad data
 * @param option - Unknown function. Always set to 1
 */
void sceCtrlReadBufferPositive(ctrl_data_t *pad_data, int option);


/*@}*/

#ifdef __cplusplus
}
#endif

#endif
I was wondering if anyone knew a good way to get two button input using it. Im working on a simple program and when the player pushes a direction and square then he'll run, i've got the running and etc programed but I can't seem to get it to do multipul button inputs. Can anyone help me? Thanks in advanced - Vale
cheriff
Regular
Posts: 258
Joined: Wed Jun 23, 2004 5:35 pm
Location: Sydney.au

Post by cheriff »

Code: Select all

if (buttons & CTRL_SQUARE){
      my_square_func();
}
if (buttons & CTRL_UP){
    my_up_func();
}
if (buttons & (CTRL_LTRIGGER | CTRL_RTRIGGER)){
   my_R1_and_L1_func();
}
With something like that you should be able to detect multiple keypresses and do various stuff.
Damn, I need a decent signature!
Vale
Posts: 4
Joined: Fri Jul 22, 2005 7:27 am

Post by Vale »

Perfect! Thank You!
Post Reply