Fx-9860 battery indicator (C)
22 posts
• Page 2 of 3 • 1, 2, 3
- Code: Select all
int y = 0;
void F01_1_Handler()
{
char s[4];
memset(s, '\0', 4);
sprintf(s, "%d", MainBatteryPercentage());
PrintXY(78, y, (const unsigned char *) " ", 0);
PrintXY(78, y, (const unsigned char *) s, 0);
Bdisp_PutDisp_DD();
y++;
}
int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned int key;
Bdisp_AllClr_DDVRAM();
SetTimer(ID_USER_TIMER1, 100, (void *) F01_1_Handler);
while (1)
{
F01_1_Handler();
GetKey(&key);
}
return 1;
}
Changed F01_1_Handler a bit and added a global variable. Doesn't hang when SetTimer is commented out.
- 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
If F01_1_Handler() (called from out of the main-loop) is interrupted by the timer, F01_1_Handler() would be called while its already running. The outcome of such a situation is difficult to predict. The first thing I would implement is some prevention (busy).
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
Nope. I had a closer look again. The AD-conversion is interrupt driven, too. If it is called from inside of an interrupt handler, the interrupt system gets confused.happy wrote:Is it working for you?
Alternatively you could use PutKey in your interrupt-handler to send a special keycode every now and then, which tells your main program to display the battery level.
The timer-handler could look like this
- Code: Select all
//
void TestHandler2( void ){
PutKey( 0x1234, 0 );
}
// Now you have to react to keycode 0x1234 accordingly.
...
while (1){
GetKey(&key);
if ( key == KEY_CTRL_EXIT ) break;
if ( key == 0x1234 ) TestHandler();
}
This worked on my fx-9860GII.
I'll be back!
Sorry... I don't get it (:
(1) What is PutKey?
(2) So TestHandler2 is the timer handler (set in SetTimer) whose only job is to generate a key event (via PutKey?) which when caught, I call MainBatteryPercentage()..? How is this different from calling MainBatteryPercentage() from the timer handler directly?
(1) What is PutKey?
(2) So TestHandler2 is the timer handler (set in SetTimer) whose only job is to generate a key event (via PutKey?) which when caught, I call MainBatteryPercentage()..? How is this different from calling MainBatteryPercentage() from the timer handler directly?
- 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:(1) What is PutKey?
PutKey is syscall 0x910; it simulates a keypress (and ends the blocking state of GetKey).
happy wrote:(2) So TestHandler2 is the timer handler (set in SetTimer) whose only job is to generate a key event (via PutKey?) which when caught, I call MainBatteryPercentage()..? How is this different from calling MainBatteryPercentage() from the timer handler directly?
If a certain interrupt is handled (in this case the timer-interrupt), other interrupts may be masked off, t. i. they cannot interrupt the current interrupt-service-routine. Obviously the ad-conversion-interrupt cannot interrupt the timer-interrupt, so the battery-voltage-function waits for the ad-conversion-interrupt endlessly.
The difference is, that if you call the battery-voltage-function from the main-loop, the timer -interrupt-handler is not running any more and does not disturb the ad-conversion.
I'll be back!
Re:
SimonLothar wrote:BTW:
on the Prizm the BatteryVoltage can be read with
syscall 0x1186: int GetMainBatteryVoltage( int one );
The parameter one should be always 1.
In GII-2, MainBatteryPercentage() doesn't work, gives the wrong value. Tried changing return (*iGBS)(battery) to return GetMainBatteryVoltage(1) / 100 in GetBatteryStatus(), but that gives me a memory error. What am I doing wrong?
(Assumption here is that GII-2 architecture is very similar to Prizm and that most syscalls would work. Is that true?)
- 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
Re: Re:
No, alas not. The GII-2 calculators have the same MPU like the Prizm (SH-7305), but they have the fx-9860 syscall-numbers.happy wrote:(Assumption here is that GII-2 architecture is very similar to Prizm and that most syscalls would work. Is that true?)
I'll be back!
Re: Re:
SimonLothar wrote:No, alas not. The GII-2 calculators have the same MPU like the Prizm (SH-7305), but they have the fx-9860 syscall-numbers.
Thanks!
happy wrote:In GII-2, MainBatteryPercentage() doesn't work, gives the wrong value.
Any way to make this work..?
22 posts
• Page 2 of 3 • 1, 2, 3
Return to Tutorials & Code Snippets
Who is online
Users browsing this forum: No registered users and 5 guests