forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

battery update problem

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
kennethdm



Joined: 24 Jan 2006
Posts: 8

PostPosted: Wed May 31, 2006 4:03 am    Post subject: battery update problem Reply with quote

Hi, I'm currently adding some battery indication in my program, what I want to be shown is the battery level (indicated with an image), and how long the battery will last. To do this I have written two procedures (or whatever they are called in C):

Code:

void drukBatterijTijd()
{
  char tekst[8];
  int batterijTijd = 0;
 
  if(scePowerIsBatteryCharging())
  {
    printTextScreen(400,6,"Charging",RGB(255,255,255));                               
  }
  else
  {       
    batterijTijd = scePowerGetBatteryLifeTime();
    sprintf(tekst,"%02dh%02dm", batterijTijd/60, batterijTijd-(batterijTijd/60*60));
    printTextScreen(400,6,tekst,RGB(255,255,255));
  }
}

void drukBatterij(Image* batterij, Image* batterijStreepje)
{

  pspTime   clock;
  sceRtcGetCurrentClockLocalTime( &clock );
  int tick = 0;
  int batterijProcent = scePowerGetBatteryLifePercent();
  int teller = 0;
  int aantal = 0;
 
  if(scePowerIsLowBattery()||scePowerIsBatteryCharging())
  //flikker indien opladen of laag batterijniveau
  {
    if( !tick && clock.microseconds >= 500000)
    {
      tick = 1;
    } else {
      tick = 0;
    }
  } else {
  //laadt niet op of is niet laag qua niveau => geen flikker
    tick = 1;
  }

  if(batterijProcent>70)
  {
    aantal = 3;
  }

  if(batterijProcent<=70)
  {
    aantal = 2;
  }

  if(batterijProcent<=40)
  {
    aantal = 1;
  }

  if(batterijProcent<=10)
  {
    aantal = 0;
  }

  if(tick)
  {     
    blitAlphaImageToScreen(0 ,0 ,33 , 22, batterij, 445, 2);
    for(teller = 0;teller<aantal;teller++)
    {
      blitAlphaImageToScreen(0 ,0 ,6 , 16, batterijStreepje, 452+(teller*8), 5);
    }
  }

}


the image is shown just fine, it flickers when it is charging or low, but there seems to be something wrong with the printing of how long the battery will last. When I try it in my app, and the power cable is not plugged in, everything works fine, the remaining time is displayed, and the battery level is indicated. But when I plug in my power cable, the program freezes... I seriously have no idea why this happens, it's probably something small, but can't find it.

any suggestions?
Back to top
View user's profile Send private message
kennethdm



Joined: 24 Jan 2006
Posts: 8

PostPosted: Wed May 31, 2006 9:40 pm    Post subject: Reply with quote

Anyone...?
Back to top
View user's profile Send private message
samlucas



Joined: 18 May 2005
Posts: 5
Location: UK

PostPosted: Tue Jun 13, 2006 9:29 am    Post subject: Reply with quote

It most probably has something todo with the way you gather and check the time in microseconds.

Code:

sceRtcGetCurrentClockLocalTime( &clock );
..........
if( !tick && clock.microseconds >= 500000)


If my understanding is right clock will hold the time from the start of the program/thread (it may hold the actual time) so it will always be > 500000 (half a second I presume). I assume you are calling this function in a loop so make a global variable to store the last loop time and check that 500000 microseconds have passed since the last call of this function. I would do the time checking outside of this function and have a loop schedule the function along with all your other functions that depend on time.

This could be BS since I am assuming the pspTime structure acts much like time does in C.

Learn how to debug. You probally didnt get a reply sooner beacuse people dont want to debug other peoples code, you were lucky I have uni work todo or I wouldnt be avoiding it by reading these forums.

(Sorry about flame I just needed to vent.)
_________________
"You can't do biology with beer cans."
-John R. Searle
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group