tibs624 Posté(e) le 7 février 2007 Posté(e) le 7 février 2007 Bonjour à tous je débute en programmation pour PSP, j'ai déja quelques connaissance an C mais j'avou que la je suis un peu déconcerté par ce problème. En fait je voudrai faire une boucle infini qui permettrai d'afficher "Hello world" lorsque l'ont appuy sur le bouton [X] ou alors quitte le programme si l'on appui sur le bouton [O] Mais mon problème est que le " Hello world" s'affiche 8 fois !!! et je ne trouve pas pourquoi. Merci d'avance pour vos réponses ! #include #include #include #include PSP_MODULE_INFO(" test", 0, 1, 1);#define printf pspDebugScreenPrintf/* Exit callback */int exit_callback(int arg1, int arg2, void *common) {sceKernelExitGame();return 0;}/* Callback thread */int CallbackThread(SceSize args, void *argp) {int cbid;cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);sceKernelRegisterExitCallback(cbid);sceKernelSleepThreadCB();return 0;}/* Sets up the callback thread and returns its thread id */int SetupCallbacks(void) {int thid = 0;thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);if(thid >= 0) {sceKernelStartThread(thid, 0, 0);}return thid;} // Le main qui se lance au démarrage du programme.// Le main qui se lance au démarrage du programme.int main(void){SetupCallbacks();pspDebugScreenInit();// On initialise l'écranpspDebugScreenSetTextColor(0xFF0000); // La couleur du texte: il faut un logiciel nommé Fast color codes pour obtenir ce code couleur c++pspDebugScreenClear(); // On efface l'écran// On écrit du texte :Pprintf("\n Appuyez sur[X] pour afficher Hello World ou sur [O] pour finnir le programme"); while(1>0) // Une boucle infinie { SceCtrlData pad; sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_CROSS) { printf("\n\n hello world"); } //Sinon c'est bon, on le signale. else if(pad.Buttons & PSP_CTRL_CIRCLE) { sceKernelExitGame(); } } }
Roomain Posté(e) le 7 février 2007 Posté(e) le 7 février 2007 Tu as oublié les include, et d'ou sort le "else if": sert à rien ici. Je reconnais mon code Voici le code corrigé: // Code corrigé par roomain#include <pspsdk.h>#include <pspkernel.h>#include <pspctrl.h>#include <string.h> PSP_MODULE_INFO(" test", 0, 1, 1);#define printf pspDebugScreenPrintf/* Exit callback */int exit_callback(int arg1, int arg2, void *common) {sceKernelExitGame();return 0;}/* Callback thread */int CallbackThread(SceSize args, void *argp) {int cbid;cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);sceKernelRegisterExitCallback(cbid);sceKernelSleepThreadCB();return 0;}/* Sets up the callback thread and returns its thread id */int SetupCallbacks(void) {int thid = 0;thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);if(thid >= 0) {sceKernelStartThread(thid, 0, 0);}return thid;}// Le main qui se lance au démarrage du programme.int main(void){SetupCallbacks();pspDebugScreenInit();// On initialise l'écranpspDebugScreenSetTextColor(0xFF0000); // La couleur du texte: il faut un logiciel nommé Fast color codes pour obtenir ce code couleur c++pspDebugScreenClear(); // On efface l'écran// On écrit du texte printf("\n Appuyez sur[X] pour afficher Hello World ou sur [O] pour finnir le programme");while(1) // Une boucle infinie{SceCtrlData pad;sceCtrlReadBufferPositive(&pad, 1);if (pad.Buttons & PSP_CTRL_CROSS){printf("\n\n hello world");}if(pad.Buttons & PSP_CTRL_CIRCLE){sceKernelExitGame();}}}
PSP_maniac Posté(e) le 7 février 2007 Posté(e) le 7 février 2007 (modifié) Je crois que même avec ta correction le hello world s'affichera plusieurs fois. // Code corrigé par roomain puis Maniac#include <pspsdk.h>#include <pspkernel.h>#include <pspctrl.h>#include <string.h> PSP_MODULE_INFO(" test", 0, 1, 1);#define printf pspDebugScreenPrintf/* Exit callback */int exit_callback(int arg1, int arg2, void *common) {sceKernelExitGame();return 0;}/* Callback thread */int CallbackThread(SceSize args, void *argp) {int cbid;cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);sceKernelRegisterExitCallback(cbid);sceKernelSleepThreadCB();return 0;}/* Sets up the callback thread and returns its thread id */int SetupCallbacks(void) {int thid = 0;thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);if(thid >= 0) {sceKernelStartThread(thid, 0, 0);}return thid;}statut = 0// Le main qui se lance au démarrage du programme.int main(void){SetupCallbacks();pspDebugScreenInit();// On initialise l'écranpspDebugScreenSetTextColor(0xFF0000); // La couleur du texte: il faut un logiciel nommé Fast color codes pour obtenir ce code couleur c++pspDebugScreenClear(); // On efface l'écran// On écrit du texte printf("\n Appuyez sur[X] pour afficher Hello World ou sur [O] pour finnir le programme");while(1) // Une boucle infinie{SceCtrlData pad;sceCtrlReadBufferPositive(&pad, 1);if (statut == 0){if (pad.Buttons & PSP_CTRL_CROSS){printf("\n\n hello world");statut = 1}}if(pad.Buttons & PSP_CTRL_CIRCLE){sceKernelExitGame();}}} Heu je crois que c'est bon là corrigez moi si je me trompe Modifié le 7 février 2007 par PSP_maniac
Roomain Posté(e) le 7 février 2007 Posté(e) le 7 février 2007 Ah oui, j'avais pas compris le problème. C'est parce qu'il faut mettre un timer sinon les touches se répètent trop vite. Pourquoi s'emmerder en rajoutant une valeur statut ? Voilà le code: // Code corrigé par roomain// Puis Maniac m'a donné une idée// Alors j'ai re-corrigé le code :d#include <pspsdk.h>#include <pspkernel.h>#include <pspctrl.h>#include <string.h>PSP_MODULE_INFO(" test", 0, 1, 1);#define printf pspDebugScreenPrintf/* Exit callback */int exit_callback(int arg1, int arg2, void *common) {sceKernelExitGame();return 0;}/* Callback thread */int CallbackThread(SceSize args, void *argp) {int cbid;cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);sceKernelRegisterExitCallback(cbid);sceKernelSleepThreadCB();return 0;}/* Sets up the callback thread and returns its thread id */int SetupCallbacks(void) {int thid = 0;thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);if(thid >= 0) {sceKernelStartThread(thid, 0, 0);}return thid;}// Le main qui se lance au démarrage du programme.int main(void){SetupCallbacks();pspDebugScreenInit();// On initialise l'écranpspDebugScreenSetTextColor(0xFF0000); // La couleur du texte: il faut un logiciel nommé Fast color codes pour obtenir ce code couleur c++pspDebugScreenClear(); // On efface l'écran// On écrit du texteprintf("\n Appuyez sur[X] pour afficher Hello World ou sur [O] pour finnir le programme");while(1) // Une boucle infinie{SceCtrlData pad;sceCtrlReadBufferPositive(&pad, 1);if (pad.Buttons & PSP_CTRL_CROSS){printf("\n\n hello world");sceKernelDelayThread(500000); // le timer pour éviter la répétition}if(pad.Buttons & PSP_CTRL_CIRCLE){sceKernelExitGame();}}} Théoriquement, ca devrait fonctionner mais il faut lacher le bouton X 0.5 sec max après avoir appuyé sinon le texte s'affichera plusieurs fois !
PSP_maniac Posté(e) le 7 février 2007 Posté(e) le 7 février 2007 Ben je trouvais la variable "statut" beaucoup plus simple et pratique mais quitte à bloquer la touche, vaut mieux la bloquer avec un "oldpad" plutôt qu'un timer nan ?
tibs624 Posté(e) le 8 février 2007 Auteur Posté(e) le 8 février 2007 Merci beaucoup! vos réponses me sont très précieuses ! J'aurai une autre petite question : Pour l'instant pour repérer les touches de la PSP je ne connais que PSP_CTRL_CROSS, PSP_CTRL_CIRCLE, PSP_CTRL_UP mais pour le boutton triangle caré et L et R je ne sais pas leur nom et je ne l'ai pas trouvé sur le net donc si vous savez ou si vous avez des adresses meme en anglais sa serai cool en vous remerciant beaucoup pour vos réponses rapide !
MichaelNet Posté(e) le 8 février 2007 Posté(e) le 8 février 2007 Merci beaucoup! vos réponses me sont très précieuses !J'aurai une autre petite question : Pour l'instant pour repérer les touches de la PSP je ne connais que PSP_CTRL_CROSS, PSP_CTRL_CIRCLE, PSP_CTRL_UP mais pour le boutton triangle caré et L et R je ne sais pas leur nom et je ne l'ai pas trouvé sur le net donc si vous savez ou si vous avez des adresses meme en anglais sa serai cool en vous remerciant beaucoup pour vos réponses rapide ! Left trigger (gâchette L), - PSP_CTRL_LTRIGGER Right trigger (gâchette R), - PSP_CTRL_RTRIGGER Triangle button, - PSP_CTRL_TRIANGLE Square button (bouton carré), - PSP_CTRL_SQUARE Select button, - PSP_CTRL_SELECT Start button, - PSP_CTRL_START Up D-Pad button, - PSP_CTRL_UP Right D-Pad button, - PSP_CTRL_RIGHT Down D-Pad button, - PSP_CTRL_DOWN Left D-Pad button, - PSP_CTRL_LEFT Left trigger, - PSP_CTRL_LTRIGGER Right trigger, - PSP_CTRL_RTRIGGER Triangle button, - PSP_CTRL_TRIANGLE Circle button, - PSP_CTRL_CIRCLE Cross button, - PSP_CTRL_CROSS Square button, - PSP_CTRL_SQUARE Home button, - PSP_CTRL_HOME Hold button, - PSP_CTRL_HOLD Music Note button, - PSP_CTRL_NOTE Screen Brightness button, - PSP_CTRL_SCREEN Volume up button, - PSP_CTRL_VOLUP Volume down button, - PSP_CTRL_VOLDOWN Wlan switch up, - PSP_CTRL_WLAN_UP Remote hold position, - PSP_CTRL_REMOTE
tibs624 Posté(e) le 8 février 2007 Auteur Posté(e) le 8 février 2007 Encor merci vous êtes vraiment sympa !
Messages recommandés
Créer un compte ou se connecter pour commenter
Vous devez être membre afin de pouvoir déposer un commentaire
Créer un compte
Créez un compte sur notre communauté. C’est facile !
Créer un nouveau compteSe connecter
Vous avez déjà un compte ? Connectez-vous ici.
Connectez-vous maintenant