if (buf[0] == '1') {
return 1;
}
}
return 0;
}
int battery_capacity()
{
char buf[SIZE];
if (readFromFile(BATTERY_CAPACITY_PATH, buf, SIZE) > 0) {
return atoi(buf);
}
return 0;
}
int battery_voltage()
{
char buf[SIZE];
if (readFromFile(BATTERY_VOLTAGE_PATH, buf, SIZE) > 0) {
return atoi(buf);
}
return 0;
}
int battery_temperature()
{
char buf[SIZE];
if (readFromFile(BATTERY_TEMPERATURE_PATH, buf, SIZE) > 0) {
return atoi(buf);
}
return 0;
}
int capacity_full()
{
char buf[SIZE];
if (readFromFile(BATTERY_STATUS_PATH, buf, SIZE) > 0)
{
return getBatteryStatus(buf);
}
}
void do_nothing() //don't commnet it before fix zip error. shuaiwen
{
ZipArchive zip;
mzOpenZipArchive(NULL, &zip);
}
int main(int argc, char **argv)
{
int index=0;
#define CIRCLE 100 //1000x1000 microsecond
int circle=0;//interval to update battery status.
struct input_event ev;
//is AC power charging
if(!power_ac())
{
printf("battery supply,don't enter charge mode.\n\r");
return 0; //continue runing.
}
printf("entern charge mode\n\r");
//powerio_low(); //fixme,set power io low to shutdown system when unplug the power.
ui_init();
while(1)
{
circle=0;
ui_set_background(capacity_full()==STATUSCHARGING index++%BACKGROUND_ICON_END:BACKGROUND_ICON_END-1);//todo:more condition must be considered.
// ui_set_background(index++%BACKGROUND_ICON_END);
while(circle++ { usleep(1000); ev_get(&ev, 10); if((ev.type == EV_KEY)&&(ev.code==62)) { // powerio_high(); //fixme ev_exit(); gr_exit(); return 0;//the system will continue running } //debug if(ev.type==EV_KEY)printf("key:%d pressed\n",ev.code); // } } ev_exit(); gr_exit(); return 0; } 对应的andriod.mk文件如下: LOCAL_PATH :=$(call my-dir) include $(CLEAR_VARS) charge_local_path := $(LOCAL_PATH) LOCAL_SRC_FILES :=main.c LOCAL_MODULE := charge LOCAL_FORCE_STATIC_EXECUTABLE := true # This binary is in the recovery ramdisk, which is otherwise a copy of root. # It gets copied there in config/Makefile. LOCAL_MODULE_TAGS suppresses # a (redundant) copy of the binary in /system/bin for user builds. # TODO: Build the ramdisk image in a more principled way. LOCAL_MODULE_TAGS := eng LOCAL_STATIC_LIBRARIES := libminzip libunz libminui libpixelflinger_static libpng libcutils libstdc++ libc include $(BUILD_EXECUTABLE) include $(charge_local_path)/minzip/Android.mk PRODUCT_COPY_FILES += \ $(charge_local_path)/res/images/battery001.PNG:system/res/images/battery001.png \ $(charge_local_path)/res/images/battery002.PNG:system/res/images/battery002.png \ $(charge_local_path)/res/images/battery003.PNG:system/res/images/battery003.png \ $(charge_local_path)/res/images/battery004.PNG:system/res/images/battery004.png \ $(charge_local_path)/res/images/battery005.PNG:system/res/images/battery005.png \ $(charge_local_path)/res/images/battery006.PNG:system/res/images/battery006.png