What does getBatteryLevel do?

Post Reply
Xenon
Posts: 7
Joined: Tue Jul 20, 2010 2:55 pm

What does getBatteryLevel do?

Post by Xenon » Sun Sep 26, 2010 10:18 pm

I have checked libnds-src to figure out that getBatteryLevel is a FIFO function.
Then I see ARM7 code:

Code: Select all

        battery = readPowerManagement(PM_BATTERY_REG) & 1;
        backlight = readPowerManagement(PM_BACKLIGHT_LEVEL);
        if (backlight & (1<<6)) battery += backlight & (1<<3)<<12;
        fifoSendValue32(FIFO_SYSTEM, battery);
I know almost all of this meaning(1<<6 was formally PM_NDSLITE_ISLITE), but I cannot understand

Code: Select all

battery += backlight & (1<<3)<<12
this is interprted as battery+=(backlight&((1<<3)<<12)), but I don't know what is the meaning of 15th bit of readPowerManagement(PM_BACKLIGHT_LEVEL). Could you tell me?

Or did you mean this?

Code: Select all

battery += (backlight & (1<<3))<<12
1<<3 was formally PM_NDSLITE_ExternalPowerPresent, thus it can be explained.

StevenH
Posts: 133
Joined: Sun Feb 22, 2009 7:59 pm

Re: What does getBatteryLevel do?

Post by StevenH » Sun Sep 26, 2010 11:44 pm

There is no 15th bit of the power management registers as they are all 8 bits...

I'm actually looking at that code now, and there's a couple of things that's a little stange to me as well...

I think what it's supposed to be doing is the following:

battery = OK / low power (0 = OK, 1 - Low power according to the GBATEK docs.)
backlight & ( 1 << 6 ) == DSLite check
backlight & ( 1 << 3 ) == Wall power ( 0 = no, 1 = Yes )

therefore from my understanding of the above:

battery = 0 - Green light
battery = 1 - low power
battery = 32768 - green light + wall power
battery = 32769 - low power, but recharging.

This is possibly due to the new features that the DSi has for power levels (5 different levels), and it's something that was needed to be added to the system, the only downside is that the DSi's power management stuff is still needing to be RE'd.

Please note the above is from my limited understanding of the code in the SVN.

Hope the above helps

Xenon
Posts: 7
Joined: Tue Jul 20, 2010 2:55 pm

Re: What does getBatteryLevel do?

Post by Xenon » Mon Sep 27, 2010 7:47 am

If
StevenH wrote: backlight & ( 1 << 3 ) == Wall power ( 0 = no, 1 = Yes )
battery = 32768 - green light + wall power
battery = 32769 - low power, but recharging.
is meant, I think

Code: Select all

battery += backlight & (1<<3)<<12
should be changed to

Code: Select all

battery += (backlight & (1<<3))<<12

WinterMute
Site Admin
Posts: 1986
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: What does getBatteryLevel do?

Post by WinterMute » Tue Sep 28, 2010 12:31 pm

meh, that's what I get for not testing "simple" code when I assume operator priority.

Fixed in libnds 1.4.7
Help keep devkitPro toolchains free, Donate today

Personal Blog

Xenon
Posts: 7
Joined: Tue Jul 20, 2010 2:55 pm

Re: What does getBatteryLevel do?

Post by Xenon » Thu Sep 30, 2010 9:22 am

Thank you for fixing.

lazyprogramer
Posts: 85
Joined: Mon Sep 27, 2010 5:26 pm

Re: What does getBatteryLevel do?

Post by lazyprogramer » Sat Oct 16, 2010 10:58 am

sorry, I dind't understand it!
How can I get the battery level?
Please can you give me the code and tell me, what I have to write, when I want to
play a sound, when I have a bad battery

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests