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

RetroController use a Callbacks Power on Plugin

Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
Post Reply
User avatar
Davis9278
Posts: 41
Joined: Tue Jul 15, 2014 11:34 pm
Location: Mexico :D
Contact:

RetroController use a Callbacks Power on Plugin

Post by Davis9278 » Tue Nov 04, 2014 2:07 pm

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
Last edited by Davis9278 on Sun Nov 01, 2015 3:45 am, edited 1 time in total.
Please refer to me as DevDavisNunez,
I am looking for some way to change my nick on wololo!

User avatar
Davis9278
Posts: 41
Joined: Tue Jul 15, 2014 11:34 pm
Location: Mexico :D
Contact:

Re: Help Using Callbacks Power on Plugin

Post by Davis9278 » Sat Dec 27, 2014 2:55 am

In truth there is no coder who can help me please .
Advertising
Please refer to me as DevDavisNunez,
I am looking for some way to change my nick on wololo!

User avatar
Davis9278
Posts: 41
Joined: Tue Jul 15, 2014 11:34 pm
Location: Mexico :D
Contact:

Re: Help Using Callbacks Power on Plugin

Post by Davis9278 » Sat Oct 24, 2015 9:51 pm

Thank you all, today, the coders really gone, there are only a few, all other users are just simple people, looking for programs that do not care as they are made, a web in which the meaning is just hack , play umd's (isos) ..
Please refer to me as DevDavisNunez,
I am looking for some way to change my nick on wololo!

User avatar
qwikrazor87
Guru
Posts: 2868
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: Help Using Callbacks Power on Plugin

Post by qwikrazor87 » Sat Oct 24, 2015 10:00 pm

what happens when you run the kernel plugin? do you know the error returned?
kernel RAM has only a limited amount compared to user RAM, I see you have 2048 KB reserved for heap size, that may be what's causing it to fail, try either making the heap size smaller or use space from user RAM.
Other than that, I don't know anything about the sio port.
PSP 2001 - TA-085 - 6.61 PRO-C2
PS Vita 3G - PCH-1101 - 3.65 HENkaku Ensō
Maxwest Nitro 4 phone - Android 5.1
Laptop - Toshiba Satellite L305D-S5974 - Ubuntu 16.04 LTS

User avatar
Davis9278
Posts: 41
Joined: Tue Jul 15, 2014 11:34 pm
Location: Mexico :D
Contact:

Re: Help Using Callbacks Power on Plugin

Post by Davis9278 » Fri Oct 30, 2015 4:19 am

qwikrazor87 wrote:what happens when you run the kernel plugin? do you know the error returned?
kernel RAM has only a limited amount compared to user RAM, I see you have 2048 KB reserved for heap size, that may be what's causing it to fail, try either making the heap size smaller or use space from user RAM.
Other than that, I don't know anything about the sio port.
Qwikrazor87 Hello, thank you for answering !, really good in the end I found the solution, my problem was that I could not create callback power, but now is running! xD

If you have a problem before I had not managed to repair something on the suspension and a freeze on the reading event ..
The solution was just as visible, which previously did not attempt xD
"know when to be suspended and shut down the SIO port, returning from suspension reignite the port"


The SIO port, a serial port, for debugging purposes and control of peripherals for sony.

In the video a token of my plug in operation, together with an AVR microcontroller and an old control of snes...
Image

Finally, good is already running, I really appreciate your support, I would like to add it to gmail,
I'm currently in the "Onelua" team, is quite learn, wanting to make sintaxis it easier for other user's heheh XD

Excuse the delay in responding, in forums wololo never really found support, with exception of you! :)

Greetings Qwikrazor87!
Please refer to me as DevDavisNunez,
I am looking for some way to change my nick on wololo!

Post Reply

Return to “Programming and Security”