 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Gary13579
Joined: 15 Aug 2005 Posts: 93
|
Posted: Sun Sep 11, 2005 6:17 am Post subject: Battery functions explained? |
|
|
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: |
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? |
|
| Back to top |
|
 |
2Xtremes2004
Joined: 31 Aug 2005 Posts: 53
|
Posted: Sun Sep 11, 2005 9:41 am Post subject: |
|
|
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: |
battlvl = System.powerGetBatteryLifePercent()
screen:print(425, 6, battlvl, white)
if battlvl >= 11 and battlvl <= 33 then
screen:blit(bx, by, battl)
elseif battlvl >= 34 and battlvl <= 66 then
screen:blit(bx, by, batth)
elseif battlvl >= 67 then
screen:blit(bx, by, battf)
end |
_________________ I want my money back!? |
|
| Back to top |
|
 |
2Xtremes2004
Joined: 31 Aug 2005 Posts: 53
|
Posted: Sun Sep 11, 2005 11:38 am Post subject: |
|
|
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!? |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Mon Sep 12, 2005 5:17 pm Post subject: Re: Battery functions explained? |
|
|
| 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: |
/**
* Check if unit is plugged in
*/
int scePowerIsPowerOnline(void);
/**
* Check if a battery is present
*/
int scePowerIsBatteryExist(void);
/**
* Check if the battery is charging
*/
int scePowerIsBatteryCharging(void);
/**
* Get the status of the battery charging
*/
int scePowerGetBatteryChargingStatus(void);
/**
* Check if the battery is low
*/
int scePowerIsLowBattery(void);
/**
* Get battery life as integer percent
* @return battery charge percentage
*/
int scePowerGetBatteryLifePercent(void);
/**
* Get battery life as time
*/
int scePowerGetBatteryLifeTime(void);
/**
* Get temperature of the battery
*/
int scePowerGetBatteryTemp(void);
/**
* Get battery volt level
*/
int scePowerGetBatteryVolt(void);
|
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. |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Mon Sep 12, 2005 5:26 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
nevyn
Joined: 31 Jul 2005 Posts: 136 Location: Sweden
|
Posted: Mon Sep 12, 2005 8:36 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
|
|
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
|