Battery functions explained?

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
Gary13579
Posts: 93
Joined: Mon Aug 15, 2005 7:43 am

Battery functions explained?

Post by Gary13579 »

Someone finnally talked me into start using Lua, and it seems to be pretty good. Great job :)

But when I look at the battery functions, they are weird.. Here's what I mean.

Code: Select all

Bool System.powerIsPowerOnline()
Bool System.powerIsBatteryExist()
Bool System.powerIsBatteryCharging()
Number System.powerGetBatteryChargingStatus()
Bool System.powerIsLowBattery()
Number System.powerGetBatteryLifePercent()
Number System.powerGetBatteryLifeTime()
Number System.powerGetBatteryTemp()
Number System.powerGetBatteryVolt()
A lot of these are doing the same thing.
System.powerGetBatteryChargingStatus(),
System.powerGetBatteryLifePercent(), and
System.powerGetBatteryLifeTime()
Are ALL giving me the percentage of the battery. Why is this?

And what is the difference between
System.powerIsPowerOnline() and System.powerIsBatteryCharging()

I love the player, but the lack of documentation for some things is very disappointing.
Maybe start up a Wiki just for PSP Lua?
2Xtremes2004
Posts: 53
Joined: Wed Aug 31, 2005 1:43 am

Post by 2Xtremes2004 »

This is a snipit of my code, the way i used the power function. It may not be the right way, but it worked for me.

Code: Select all

      battlvl = System.powerGetBatteryLifePercent()
      screen:print(425, 6, battlvl, white)
    
      if battlvl >= 11 and battlvl <= 33 then
      screen&#58;blit&#40;bx, by, battl&#41;
      elseif battlvl >= 34 and battlvl <= 66 then
      screen&#58;blit&#40;bx, by, batth&#41;
      elseif battlvl >= 67  then
      screen&#58;blit&#40;bx, by, battf&#41;
      end
I want my money back!?
2Xtremes2004
Posts: 53
Joined: Wed Aug 31, 2005 1:43 am

Post by 2Xtremes2004 »

Anyone got an example of this? I dont understand what it means.

- os.time() returns a userdata instead of a number because of problems
with the float-precision, so you have to use os.difftime instead of
doing calculations with the result
I want my money back!?
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: Battery functions explained?

Post by Shine »

Gary13579 wrote:But when I look at the battery functions, they are weird..
Lua Player just calls the original functions. We don't know, what they return, but this is the documentation from the PSPSDK:

Code: Select all

/**
 * Check if unit is plugged in
 */
int scePowerIsPowerOnline&#40;void&#41;;

/**
 * Check if a battery is present
 */
int scePowerIsBatteryExist&#40;void&#41;;

/**
 * Check if the battery is charging
 */
int scePowerIsBatteryCharging&#40;void&#41;;

/**
 * Get the status of the battery charging
 */
int scePowerGetBatteryChargingStatus&#40;void&#41;;

/**
 * Check if the battery is low
 */
int scePowerIsLowBattery&#40;void&#41;;

/**
 * Get battery life as integer percent
 * @return battery charge percentage
 */
int scePowerGetBatteryLifePercent&#40;void&#41;;

/**
 * Get battery life as time
 */
int scePowerGetBatteryLifeTime&#40;void&#41;;

/**
 * Get temperature of the battery
 */
int scePowerGetBatteryTemp&#40;void&#41;;

/**
 * Get battery volt level
 */
int scePowerGetBatteryVolt&#40;void&#41;;
You can see that the documenation doesn't add much information to the function name, but if you like, you can test the functions and if find out better documenations, perhaps with examples and possible return values, I'll add it to the functions.txt.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

2Xtremes2004 wrote:Anyone got an example of this? I dont understand what it means.

- os.time() returns a userdata instead of a number because of problems
with the float-precision, so you have to use os.difftime instead of
doing calculations with the result
It means, that you can't write "t1 = os.time(); t2 = os.time(); someNumber = t2-t1" anymore, but you have to write "t1 = os.time(); t2 = os.time(); someNumber = os.difftime(t2, t1)".

The reason for this is, that os.time() doesn't return a number anymore, because numbers are floats and not doubles anymore with Lua Player 0.10. This caused problems, because os.time() returns the number of seconds from some day back in the 20th century on PSP, but the least significant bits are lost, because 4 bytes are needed, but float has only a 3 byte mantissa (and 1 byte exponent). The result was, that the os.time() value changed only every x seconds (x > 200). So I changed the return type for os.time to userdata, which should be not a big problem, because the Lua language documentation says, that os.time() doesn't need to return the number of seconds on some systems, so you have to use os.difftime anyway, but some games already used t2-t1, so I added the comment to the releasenote.
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

Shine wrote:
2Xtremes2004 wrote:Anyone got an example of this? I dont understand what it means.

- os.time() returns a userdata instead of a number because of problems
with the float-precision, so you have to use os.difftime instead of
doing calculations with the result
It means, that you can't write "t1 = os.time(); t2 = os.time(); someNumber = t2-t1" anymore, but you have to write "t1 = os.time(); t2 = os.time(); someNumber = os.difftime(t2, t1)".

The reason for this is, that os.time() doesn't return a number anymore, because numbers are floats and not doubles anymore with Lua Player 0.10. This caused problems, because os.time() returns the number of seconds from some day back in the 20th century on PSP, but the least significant bits are lost, because 4 bytes are needed, but float has only a 3 byte mantissa (and 1 byte exponent). The result was, that the os.time() value changed only every x seconds (x > 200). So I changed the return type for os.time to userdata, which should be not a big problem, because the Lua language documentation says, that os.time() doesn't need to return the number of seconds on some systems, so you have to use os.difftime anyway, but some games already used t2-t1, so I added the comment to the releasenote.
We should overload the mathematical operators in luaplayer... Of course, that could be done with a Library :P
Post Reply