Ramel Levin wrote:
>
> This is true for Palm OS 3.x, but for Palm OS 2 getting the percentage is
> not that simple... any ideas?
This code is from GadgetHack and should work on any version of the OS.
(Pardon the tabs.)
Regards,
Daniel.
#define MaxVoltage 300 // 2 batteries * 150 increments (1.5v)
void GetVoltage(UIntPtr voltage, BytePtr percent) {
UInt warning;
DWord romVersion;
// we have to correctly calculate the current voltage on a PalmPilot,
// PalmIII, PalmIIIx and PalmV...and in the future, PalmVII.
FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
if (sysGetROMVerMajor(romVersion) < 3) {
*voltage = SysBatteryInfoV20(false, /*set*/
&warning,
NULL, /*criticalThresholdP*/
NULL, /*maxTicksP*/
NULL, /*kindP*/
NULL /*pluggedIn*/);
// calculate the current percentage using pseudo-floats
// instead of doubles and their corresponding 3.5k FPL
*percent = (*voltage - warning) * 100 / (MaxVoltage - warning);
} else
*voltage = SysBatteryInfo(false, /*set*/
NULL, /*warnThresholdP*/
NULL, /*criticalThresholdP*/
NULL, /*maxTicksP*/
NULL, /*kindP*/
NULL, /*pluggedIn*/
percent);
}