Advertising (This ad goes away for registered users. You can Login or Register)

Help Using Callbacks Power on Plugin

Plugins for PSPs running on 6.XX
Locked
Davis9278
Posts: 41
Joined: Tue Jul 15, 2014 11:34 pm
Location: Mexico :D
Contact:

Help Using Callbacks Power on Plugin

Post by Davis9278 »

Hi, I'm basically trying to use the sio port psp
This is a problem, it freezes on the suspension,
but repaired using callbacks power
but in a plugin, profit not get it to work,
Truly I need your help,
is that still remain wololo coder so please help.
Then The Codes: xD

Functional code, "EBOOT"

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspsdk.h>
#include <pspctrl.h>
#include <stdio.h>
#include <string.h>
#include <psppower.h>


#include <sys/types.h>
#include <sys/unistd.h> // for getcwd() 

PSP_MODULE_INFO("SIO_TESTER", 0, 1, 1); 
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);

int sioReadChar(void);
void sioInit(int baud);
int prout = 1;

int pollThread (SceSize args ,void * argp);

void createPollThread(){
	SceUID thid;
	thid = sceKernelCreateThread("sio polling thread", pollThread, 20, 16384, 0, NULL);
	sceKernelStartThread(thid, 0, NULL);
}



/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
    sceKernelExitGame();

	return 0;
}

/* Power Callback */
int power_callback(int unknown, int pwrflags, void *common)
{
    /* check for power switch and suspending as one is manual and the other automatic */
    if (pwrflags & PSP_POWER_CB_POWER_SWITCH || pwrflags & PSP_POWER_CB_SUSPENDING) {
	//Apagar el Sio
		pspDebugScreenPrintf("Apaga el SIO\n");
		sioFinalize();
    } else if (pwrflags & PSP_POWER_CB_RESUME_COMPLETE) {
	//Inicia el Sio
		pspDebugScreenPrintf("Enciende el SIO\n");
		sioInit(19200);
    }
	
	return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
    int cbid;
    cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
    sceKernelRegisterExitCallback(cbid);
    cbid = sceKernelCreateCallback("Power Callback", power_callback, NULL);
    scePowerRegisterCallback(0, 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;
}


int main(void)
{
		int baud=19200; 
		int midimode = 0;

        pspDebugScreenInit();

		SetupCallbacks(); // [home] handler

        pspDebugScreenPrintf("Suspend SIO test - Press HOME to exit\n");
        pspDebugScreenPrintf("Press UP/DOWN to change baud rate\n");
		pspDebugScreenPrintf("Press LEFT/RIGHT for MIDI/standard modes\n");
        pspDebugScreenPrintf("Press CROSS to switch between printout modes\n");
        
		sceDisplayWaitVblankStart();
        sceCtrlSetSamplingCycle(0);
        sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

		// retrieve current directory
		char fullName[256];
		getcwd(fullName,200);
		strcat(fullName,"/sioDriver3v0.prx");		

		// load siodriver
        SceUID mod = pspSdkLoadStartModule(&fullName, PSP_MEMORY_PARTITION_KERNEL);
		if (mod < 0)
		{
			pspDebugScreenPrintf(" ERROR 0x%08X loading/starting ", mod);
			pspDebugScreenPrintf(fullName);
			sceKernelDelayThread(3000000);
			sceKernelExitGame();
		}
        sceKernelDelayThread(1000000);
        pspDebugScreenPrintf("module sioDriver3v0.prx loaded.\n");
        
		sioInit(baud);
        sceKernelDelayThread(1000000);
        pspDebugScreenPrintf("sio port initialized.\n");
        
		// set main thread priority
		//int thid = sceKernelGetThreadId();
        //sceKernelChangeThreadPriority(thid, 31);
        
		SceCtrlData pad;
        
		createPollThread();
		
		
		pspDebugScreenPrintf("entering main loop...\n");
        while(1)
        {
			
			// ASSIGN YOUR OWN COMMANDS TO EACH KEY....

			    sceCtrlPeekBufferPositive(&pad, 1);
                if(pad.Buttons & PSP_CTRL_CROSS)
                {
					prout = !prout;
					sceKernelDelayThread(500000);	// when i'll do something serious with this, i have to subst these
													// delays with  justpressed = pressed & ~oldPressed  but for now
													// i won't bother
                }
		sceKernelDelayThread(500);
        }

        sceKernelExitGame();
        return 0;
} 

int pollThread (SceSize args ,void * argp)
{
	pspDebugScreenPrintf("entering sio polling thread...\n");

	int ch = -1;
	while(1){ 
		ch = sioReadChar();
		if(ch >= 0){
			if (prout){
				if (ch != '\r')
						pspDebugScreenPrintf("%c", ch);
				//else // IDLE:
				//        pspDebugScreenPrintf(".");
			} else {
				pspDebugScreenPrintf("received %d\n", ch);
				//sioPutchar(ch);
			}
		}
		sceKernelDelayThread(200);  

	}
	return 0;
}
UnFunctional code, "Plugin"

Code: Select all


// LIBRERÍAS
#include <pspsdk.h>
#include <pspintrman_kernel.h>
#include <pspintrman.h>
#include <pspsyscon.h>
#include <psppower.h>
//---------------------
#include <pspkernel.h>
#include <pspctrl.h>
//#include "libs/blit.h" // Librería que usaremos para imprimir en pantalla

PSP_MODULE_INFO("SioTest", 0x1000, 1, 0); //, 0x1006, 1, 1);//  checa con esto sino funciona
//PSP_MODULE_INFO("SioTest", 0x1006, 1, 1);
PSP_HEAP_SIZE_KB(2048);//100

void sioInit(int baud);
void sioPrint(const char *str);
void sioFinalize();


/* Power Callback */
int power_callback(int unknown, int pwrflags, void *common)
{
    /* check for power switch and suspending as one is manual and the other automatic */
    if (pwrflags & PSP_POWER_CB_POWER_SWITCH || pwrflags & PSP_POWER_CB_SUSPENDING) {
	//Apagar el Sio
		//pspDebugScreenPrintf("Apaga el SIO\n");
		sioFinalize();
    } else if (pwrflags & PSP_POWER_CB_RESUME_COMPLETE) {
	//Inicia el Sio
		//pspDebugScreenPrintf("Enciende el SIO\n");
		sioInit(19200);
    }
	
	return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
    int cbid;
    cbid = sceKernelCreateCallback("Power Callback", power_callback, NULL);
    scePowerRegisterCallback(0, 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;
}

void LoadSioDriver(){
        // load siodriver 
		SceUID mod = pspSdkLoadStartModule("/sioDriver3v0.prx", PSP_MEMORY_PARTITION_KERNEL);
		//Todo Correcto
		sioInit(19200);
}
//Programa Pricipal

int main_thread(SceSize argc, void* argp) // Thread/Hilo principal del plugin
{	
	LoadSioDriver();
	//SetupCallbacks();
	sioPrint("Entrando a ciclo while\n");
    while(1) // Iniciamos el loop principal del plugin.
        {
		sioPrint("Funciona!\n");
	    sceKernelDelayThreadCB(1600000);
        }
    return 0; // Devolvemos 0.
}


int module_start(SceSize args, void *argp) // En ésta parte colocaremos los threads/hilos que se ejecutarán, en éste caso solo uno.
{
	int thid = sceKernelCreateThread("KarlPower-In", main_thread, 1, 0x1000, 0, NULL);
	if(thid >= 0) sceKernelStartThread(thid, args, argp);
	
	return 0; // Devolvemos 0.
}
int module_stop()
{
        return 0;
} 
Greetings hope your help!
Advertising
Please refer to me as DevDavisNunez,
I am looking for some way to change my nick on wololo!
Locked

Return to “Plugins”