Page 1 of 1
What does getBatteryLevel do?
Posted: Sun Sep 26, 2010 10:18 pm
by Xenon
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
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.
Re: What does getBatteryLevel do?
Posted: Sun Sep 26, 2010 11:44 pm
by StevenH
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
Re: What does getBatteryLevel do?
Posted: Mon Sep 27, 2010 7:47 am
by Xenon
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
should be changed to
Code: Select all
battery += (backlight & (1<<3))<<12
Re: What does getBatteryLevel do?
Posted: Tue Sep 28, 2010 12:31 pm
by WinterMute
meh, that's what I get for not testing "simple" code when I assume operator priority.
Fixed in libnds 1.4.7
Re: What does getBatteryLevel do?
Posted: Thu Sep 30, 2010 9:22 am
by Xenon
Thank you for fixing.
Re: What does getBatteryLevel do?
Posted: Sat Oct 16, 2010 10:58 am
by lazyprogramer
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