Fx-9860 battery indicator (C)
22 posts
• Page 1 of 3 • 1, 2, 3
- helder7
- Senior Member
- Posts: 369
- Joined: Tue Jan 03, 2012 11:24 pm
- Calculators: Casio Afx 1.0, Casio fx-9860GII SD, Casio Classpad 330, Casio fx-CG20, Casio Classpad fx-CP400
Fx-9860 battery indicator (C)
I found this in interesting code in one add-in.
battery indicator
by SimonLothar
As for OSVersionAsInt see: http://www.casiopeia.net/forum/viewtopic.php?f=21&t=1368
There are some constants and other functions, which possibly need to be commented (f. i. IsEmulator()http://www.casiopeia.net/forum/viewtopic.php?f=20&t=1374).
I think the code needs some update, too. I'll see to it as fast as possible.
battery indicator
- Code: Select all
// battery = 1 = main (do not use other values)
// firstlevel: warning level
// secondlevel: shutdown level
int GetBatteryStatus( int battery, int*firstlevel, int*secondlevel ){
int (*iGBS)( int ) = 0; // declare an int function pointer
int*battconfig = (int*)0x80000334;
*firstlevel = 0x17F;
*secondlevel = 0x16D;
switch ( OSVersionAsInt() ){
case OS102 : iGBS = (int(*)(int))0x80032E14; break;
case OS103 : iGBS = (int(*)(int))0x80032E80; break;
case OS104 :
case OS105 :
iGBS = (int(*)(int))0x80032E5C;
if ( *battconfig==0x43444844 ){
*firstlevel = 0x1A5;
*secondlevel = 0x191;
};
break;
case OS1051 :
iGBS = (int(*)(int))0x80032E44;
if ( *battconfig==0x43444844 ){
*firstlevel = 0x1A5;
*secondlevel = 0x191;
};
break;
case OS110 :
iGBS = (int(*)(int))0x8003BD2C;
*firstlevel = 0x2AA;
*secondlevel = 0x288;
break;
case OS111 :
iGBS = (int(*)(int))0x8003BCF0;
*firstlevel = 0x2AA;
*secondlevel = 0x288;
break;
case OS200 :
iGBS = (int(*)(int))0x80039A0C;
if ( *battconfig==0x43444844 ){
*firstlevel = 0x1A5;
*secondlevel = 0x191;
};
break;
case OS200GII :
iGBS = (int(*)(int))0x8003C484;
break;
case OS200slim :
iGBS = (int(*)(int))0x80047FD4;
*firstlevel = 0x2AA;
*secondlevel = 0x288;
break;
};
if (IsSlim()){
*firstlevel = 0x2AA;
*secondlevel = 0x288;
}
if (iGBS!=0) return (*iGBS)( battery );
else return 0;
}
// the warning level lies around 2/3 full scale
int MainBatteryPercentage( void ){
int firstlevel, secondlevel;
int i;
if ( IsEmulator() ){
i = 100;
firstlevel = 70;
secondlevel = 65;
} else i = GetBatteryStatus( 1, &firstlevel, &secondlevel );
if (firstlevel > 0 ) return ( 200*i )/(firstlevel*3);
else return 0;
}
by SimonLothar
As for OSVersionAsInt see: http://www.casiopeia.net/forum/viewtopic.php?f=21&t=1368
There are some constants and other functions, which possibly need to be commented (f. i. IsEmulator()http://www.casiopeia.net/forum/viewtopic.php?f=20&t=1374).
I think the code needs some update, too. I'll see to it as fast as possible.
SiO2 + CaCO3 ----------> CaSiO3 + CO2
- SimonLothar
- Senior Member
-
- Posts: 605
- Joined: Sat Sep 15, 2012 6:59 am
- Location: Krautland ****
- Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400
The following code fetches the pointer to the function GetMainBatteryVoltage (iGBS in the code of the previous post) OS-independently (fx-9860-OSes; verified with versions 1.03, 1.04, 1.05, 1.10, 1.11, 2.00, 2.01 and 2.02):
BTW:
on the Prizm the BatteryVoltage can be read with
syscall 0x1186: int GetMainBatteryVoltage( int one );
The parameter one should be always 1.
source: Show
BTW:
on the Prizm the BatteryVoltage can be read with
syscall 0x1186: int GetMainBatteryVoltage( int one );
The parameter one should be always 1.
I'll be back!
- SimonLothar
- Senior Member
-
- Posts: 605
- Joined: Sat Sep 15, 2012 6:59 am
- Location: Krautland ****
- Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400
tom9358 wrote:cool, could you make an add-in from it or make a tutorial on how to do that?
Here's the snippet:
(if you are confused by the instant syscalls, put it in a separate file and include it. The advantages of the instant syscalls are its SDK-independence and a quick prototyping. In your final system, they may reside in a library, of course)
You can call F01_1_Handler() from out of your addin_main, f. i..
I do not know, how you want to display the battery status. Hence I implemented a simple printout for now.
source: Show
I'll be back!
- SimonLothar
- Senior Member
-
- Posts: 605
- Joined: Sat Sep 15, 2012 6:59 am
- Location: Krautland ****
- Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400
Oh. I did not try it myself, yet. But I will now and have a look to its internals.tom9358 wrote:I know about that add-in, it doesn't work, instead it instantly comes up with a system error
Edit:
I tried BATTERY.G1A on a fx-9860G (OS 1.03) and on a fx-9860GII SD (OS 2.01).
I encounter an immediate crash on both machines, too. I think it should be removed from the download area.
BTW: I hope you get along with the snippet I dropped.
I'll be back!
- helder7
- Senior Member
- Posts: 369
- Joined: Tue Jan 03, 2012 11:24 pm
- Calculators: Casio Afx 1.0, Casio fx-9860GII SD, Casio Classpad 330, Casio fx-CG20, Casio Classpad fx-CP400
Battery.g1a works in my fx9860gII sd with os 2.X (i dont know now the os version, i have my calc at home).
SiO2 + CaCO3 ----------> CaSiO3 + CO2
- SimonLothar
- Senior Member
-
- Posts: 605
- Joined: Sat Sep 15, 2012 6:59 am
- Location: Krautland ****
- Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400
Yep. I just downgraded my fx-9860GII SD to OS 2.00 and Battery.G1A works as expected.helder7 wrote:Battery.g1a works in my fx9860gII sd with os 2.X (i dont know now the os version, i have my calc at home).
Hence I had a closer look. In fact, BATTERY.G1A uses a single jump-address 0x8003C484 to get the battery-voltage. This address is valid on fx-9860GII OS 2.00, only! And leads to a crash on any different OS.
I'll be back!
- SimonLothar
- Senior Member
-
- Posts: 605
- Joined: Sat Sep 15, 2012 6:59 am
- Location: Krautland ****
- Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400
happy wrote:...but hung (had to reset my 9860 - OS 2.00) when I used F01_1_Handler in a timer.
What parts of "F01_1_Handler" do you exactly use in your timer-handler?
I'll be back!
22 posts
• Page 1 of 3 • 1, 2, 3
Return to Tutorials & Code Snippets
Who is online
Users browsing this forum: No registered users and 5 guests