battery update problem

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

Moderators: cheriff, TyRaNiD

Post Reply
kennethdm
Posts: 8
Joined: Tue Jan 24, 2006 3:18 am

battery update problem

Post by kennethdm »

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: Select all

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&#40;batterijProcent<=70&#41;
  &#123;
    aantal = 2;
  &#125;

  if&#40;batterijProcent<=40&#41;
  &#123;
    aantal = 1;
  &#125;

  if&#40;batterijProcent<=10&#41;
  &#123;
    aantal = 0;
  &#125;

  if&#40;tick&#41;
  &#123;     
    blitAlphaImageToScreen&#40;0 ,0 ,33 , 22, batterij, 445, 2&#41;;
    for&#40;teller = 0;teller<aantal;teller++&#41;
    &#123;
      blitAlphaImageToScreen&#40;0 ,0 ,6 , 16, batterijStreepje, 452+&#40;teller*8&#41;, 5&#41;;
    &#125;
  &#125;

&#125;
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?
kennethdm
Posts: 8
Joined: Tue Jan 24, 2006 3:18 am

Post by kennethdm »

Anyone...?
samlucas
Posts: 5
Joined: Wed May 18, 2005 5:15 am
Location: UK

Post by samlucas »

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

Code: Select all

sceRtcGetCurrentClockLocalTime&#40; &clock &#41;;
..........
if&#40; !tick && clock.microseconds >= 500000&#41;
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
Post Reply