PSP development-[C ++] receiving key control

Source: Internet
Author: User
Tags clear screen

 

Padctrl. cpp

 # Include <pspkernel. h>
# Include <pspdebug. h>
# Include <pspdisplay. h>
# Include <pspctrl. h>

# Include <iostream>

Psp_module_info ("Hello World", 0, 1, 1 );

# Define printf pspdebugscreenprintf

Using namespace STD;

/* Exit callback */
Int exit_callback (INT arg1, int arg2, void * Common ){
Scekernelexitgame ();
Return 0;
}

/* Callback thread */
Int callbackthread (scesize ARGs, void * argp ){
Int CBID;
// Create callback
CBID = scekernelcreatecallback ("Exit callback", exit_callback, null );
Scekernelregisterexitcallback (CBID );

// Sleep thread but service any callbacks as necessary.
Scekernelsleepthreadcb ();

Return 0;
}

/* Sets up the callback thread and returns its thread ID */
Int setupcallbacks (){
Int thid = 0;

// Create a thread.
Thid = scekernelcreatethread ("update_thread", callbackthread, 0x11, 0xfa0, 0, 0 );
If (thid> = 0 ){
// Start a created thread.
Scekernelstartthread (thid, 0, 0 );
}

Return thid;
}

Int main (INT argc, char ** argv)
{
// Initialise the debug screen.
Pspdebugscreeninit ();
// Setup callback;
Setupcallbacks ();

// Press the struct button.
Scectrldata pad;

Printf ("Press [x] to start the timer ");

While (1)
{
// Read buffer positive.
Scectrlreadbufferpositive (& pad, 1 );

If (pad. Buttons & psp_ctrl_cross)
{
Printf ("You pressed X ");
Break;
}
// Clear screen
Pspdebugscreenclear ();
}

// Sleep thread
Scekernelsleepthread ();

Return 0;
}

Makefile

 Target = padctrl
Objs = padctrl. o

Build_prx = 1
Psp_fw_version = 371

# C compiler Parameters
Cflags =-O2-G0-wall
# C ++ compiler Parameters
Cxxflags = $ (cflags)-fno-exceptions-fno-rtti
# Compile compiler Parameters
Asflags = $ (cflags)

# Reference Library-l stdc ++
Libs =-lstdc ++

Extra_targets = eboot. pbp
Psp_eboot_title = pad Control

Pspsdk = $ (shell PSP-config -- pspsdk-path)
Include $ (pspsdk)/lib/build. Mak




Button Enumeration

Psp_ctrl_select  Select button.
Psp_ctrl_start  Start button.
Psp_ctrl_up  UP d-pad button.
Psp_ctrl_right  Right D-pad button.
Psp_ctrl_down  DOWN d-pad button.
Psp_ctrl_left  Left D-pad button.
Psp_ctrl_ltrigger  Left trigger.
Psp_ctrl_rtrigger  Right trigger.
Psp_ctrl_triangle  Triangle button.
Psp_ctrl_circle  Circle button.
Psp_ctrl_cross  Cross button.
Psp_ctrl_square  Square button.
Psp_ctrl_home  Home button.
Psp_ctrl_hold  Hold button.
Psp_ctrl_note  Music note button.

 

A while (1) button is required to receive system events.
Then, use scectrlreadbufferpositive (& pad, 1); To read the key content.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.