davor emard wrote:
> HI
>
> Thanks again for the on-off, and I'd like to know more - do you
> have some similar recipe either via proc or ioctl to read the battery status?
>
> (I'd like to perform a shutdown if battery is found low)
>
> On the opentom there's a small code snippet but it
> refers to #include some ioctl constants that I don't
> know the value as I don't have adequate include file.h
>
The code I use for reading the battery is this (cut & paste from a
larger project):
support of /proc/barcelona/battery disappeared in fwcore 6.
this is the code I use now to read an approximate battery level (from 0
to 100)
#define BATTERY_DEVNAME "battery"
#define BATTERY_MAJOR 241
typedef struct {
UINT16 u16BatteryVoltage; /* battery voltage */
UINT16 u16ChargeCurrent; /* charge current */
UINT8 u8ChargeStatus;
UINT8 u8VoltageSource;
} BATTERY_STATUS;
#define BATTERY_DRIVER_MAGIC 'B' /* Battery driver magic number */
#define IOR_BATTERY_STATUS _IOR(BATTERY_DRIVER_MAGIC, 3,
BATTERY_STATUS)
#define IO_ENABLE_CHARGING _IO(BATTERY_DRIVER_MAGIC, 4)
#define IO_DISABLE_CHARGING _IO(BATTERY_DRIVER_MAGIC, 5)
BATTERY_STATUS bs;
fd=open("/dev/battery",O_RDONLY|O_NOCTTY|O_NONBLOCK);
ioctl(fd,IOR_BATTERY_STATUS,&bs);
if(bs.u16ChargeCurrent>10)
return BATTERY_IS_CHARGING;
if(bs.u16BatteryVoltage>4000)
return 100;
else if(bs.u16BatteryVoltage<3600)
return 0;
else return (bs.u16BatteryVoltage-3600)/4;