sceKernelSuspendThread and battery information

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

Moderators: cheriff, TyRaNiD

Post Reply
pspflashsystem
Posts: 31
Joined: Mon Mar 24, 2008 12:31 am

sceKernelSuspendThread and battery information

Post by pspflashsystem »

Hi everyone,
I don't understand why, when I use sceKernelSuspendThread (here in my function ~= xmbpause) I must wait a long time to see battery life time in the xmb.
But, when I don't use sceKernelSuspendThread, I can see rapidly battery life time in the xmb.
So I want to know how I can see rapidly battery life time when I use sceKernelSuspendThread :)

Here's a part of my code:

Code: Select all

void xmbpause(SceUID thid){

	if(pauseuid >= 0)
	return;
	pauseuid = thid;
	sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread, thread_buf_now, MAX_THREAD, &thread_count_now);
	int x, y, match;
	for&#40;x = 0; x < thread_count_now; x++&#41;&#123;
		match = 0;
		SceUID tmp_thid = thread_buf_now&#91;x&#93;;
		for&#40;y = 0; y < thread_count_start; y++&#41;&#123;
			if&#40;&#40;tmp_thid == thread_buf_start&#91;y&#93;&#41; || &#40;tmp_thid == thid&#41;&#41;&#123;
				match = 1;
				break;
			&#125;
		&#125;
		if&#40;match == 0&#41;
		sceKernelSuspendThread&#40;tmp_thid&#41;;
	&#125;

&#125;

//resume game
void xmbresume&#40;SceUID thid&#41;&#123;

	if&#40;pauseuid != thid&#41;
	return;
	pauseuid = -1;
	int x, y, match;
	for&#40;x = 0; x < thread_count_now; x++&#41;&#123;
		match = 0;
		SceUID tmp_thid = thread_buf_now&#91;x&#93;;
		for&#40;y = 0; y < thread_count_start; y++&#41;&#123;
			if&#40;&#40;tmp_thid == thread_buf_start&#91;y&#93;&#41; || &#40;tmp_thid == thid&#41;&#41;&#123;
				match = 1;
				break;
			&#125;
		&#125;
		if&#40;match == 0&#41;
		sceKernelResumeThread&#40;tmp_thid&#41;;
	&#125;

&#125;

int main_thread&#40;SceSize args, void *argp&#41;
&#123;
	 unsigned int oldpad = 0;
	 
	 int info = 0;
	 char strinfo2&#91;64&#93;;
	 
     SceCtrlData pad;
	 sceCtrlSetSamplingCycle&#40;0&#41;;
	 sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_ANALOG&#41;;
     
	 while&#40;1&#41; 
     &#123;
         sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		 
         if&#40;info&#41; &#123;   
	     if&#40;scePowerIsBatteryExist&#40;&#41; > 0&#41; &#123;
         sprintf&#40;strinfo2,"Hours Left &#40;in min&#40;~in h&#41;&#41; --> %d min approximately %d h", scePowerGetBatteryLifeTime&#40;&#41;, scePowerGetBatteryLifeTime&#40;&#41;/60&#41;;
         &#125;
         else &#123;
         sprintf&#40;strinfo2,"Hours Left &#40;in minutes&#40;~in h&#41;&#41; --> ??"&#41;;
         &#125;	
		 &#125;
         
		 if&#40;pad.Buttons != oldpad&#41; &#123;
		     if&#40;pad.Buttons & PSP_CTRL_SQUARE&#41; &#123;
		         if&#40;info == 0&#41; &#123;
	                 info = 1;
				 &#125;
 	             else if&#40;info == 1&#41; &#123;
	                 info = 0;
	             &#125;
             &#125;
         &#125; 
         oldpad = pad.Buttons;
		 
		 if&#40;info&#41; &#123;
         blit_string&#40;1,100,strinfo2,0x000000,0x111fff&#41;;	
		 xmbpause&#40;main_thread&#41;;		 
		 &#125;
		 else if&#40;!info&#41; &#123;
		 xmbresume&#40;main_thread&#41;;
		 &#125;
		 
	   sceKernelDelayThread&#40;100000&#41;;
     &#125;
 return 0;
&#125;
Thanks to everyone who help me

PS: I'm apologize for my bad English because I'm French :)
I'm apologize for my bad English because I am French :)

.::pspflashsystem::.
pspflashsystem
Posts: 31
Joined: Mon Mar 24, 2008 12:31 am

Post by pspflashsystem »

Any idea??
I'm apologize for my bad English because I am French :)

.::pspflashsystem::.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

EDIT..
Maybe you should wait for blit to finish. Its probably suspending the thread before that.
Post Reply