.TH "KDK_HW_GET_POWERINFO" 3 "Fri Aug 25 2023" "Linux Programmer's Manual" \" .SH NAME kdk_hw_get_powerinfo - 获取电源信息 .SH SYNOPSIS .nf .B #include .sp .BI "extern struct Power *kdk_hw_get_powerinfo();" .sp Link with \fI\-lkyhwinfo\fP. .SH "Detailed Description" The main function of the interface is to obtain power supply information. .SH "RETURN VALUE" On success, returns a pointer to a .I Power structure containing power supply information. .PP The .I Power structure is defined in .I as follows: struct Power { char daemon_version[32]; bool on_battery; bool lid_is_closed; bool lid_is_present; char critical_action[32]; struct power_device *devices; }; struct power_device { char name[256]; char native_path[32]; bool power_supply; char updated[64]; bool has_history; bool has_statistics; bool is_persent; bool is_rechargeable; char state[32]; char warning_level[32]; double energy; double energy_empty; double energy_full; double energy_full_design; double energy_rate; double voltage; long time_to_empty; long time_to_full; double percentage; double temperature; double capacity; char technology[32]; bool online; char icon_name[64]; struct power_device *next; }; .PP On error, return .BR NULL. .SH EXAMPLES .EX #include "libkyhw.h" #include #include static _print_hw(struct HWInfo *hw) { struct HWInfo *tmp = hw; while (tmp) { printf("\tmodel : %s\n", tmp->model); printf("\t\tvendor : %s\n", tmp->vendor); printf("\t\tdevice : %s\n", tmp->device); printf("\t\tdriver : %s\n", tmp->driver); printf("\t\trevision : %s\n", tmp->revision); printf("\t\tdevicenum : %s\n", tmp->devicenum); printf("\t\tclock : %s\n", tmp->clock); printf("\t\twidth : %s\n", tmp->width); tmp = tmp->next; } } static void Traverse_hardware() { struct HWInfo *keyboard = kdk_hw_get_hwinfo(3); printf("KeyBoard Info:\n"); _print_hw(keyboard); kdk_hw_free_hw(keyboard); struct HWInfo *mouse = kdk_hw_get_hwinfo(5); printf("Mouse Info:\n"); _print_hw(mouse); kdk_hw_free_hw(mouse); struct HWInfo *bound = kdk_hw_get_hwinfo(15); printf("Bound Info:\n"); _print_hw(bound); kdk_hw_free_hw(bound); struct HWInfo *cdrom = kdk_hw_get_hwinfo(23); printf("CDRom Info:\n"); _print_hw(cdrom); kdk_hw_free_hw(cdrom); struct HWInfo *camera = kdk_hw_get_hwinfo(27); printf("Camera Info:\n"); _print_hw(camera); kdk_hw_free_hw(camera); } static void Traverse_power() { struct Power * power = kdk_hw_get_powerinfo(); printf("on_battery : %s\n", power->on_battery ? "true" : "false"); printf("lid_is_closed : %s\n", power->lid_is_closed ? "true" : "false"); printf("lid_is_present : %s\n", power->lid_is_present ? "true" : "false"); printf("daemon version : %s\n", power->daemon_version); printf("critical action : %s\n", power->critical_action); struct power_device *tmp = power->devices; while (tmp) { printf("name : %s\n", tmp->name); printf("\tnative path : %s\n", tmp->native_path); printf("\tpower supply : %s\n", tmp->power_supply ? "true" : "false"); printf("\tupdated : %s\n", tmp->updated); printf("\thas history : %s\n", tmp->has_history ? "true" : "false"); printf("\thas statistics : %s\n", tmp->has_statistics ? "true" : "false"); printf("\tis persent: %s\n", tmp->is_persent ? "true" : "false"); printf("\tis rechargeable : %s\n", tmp->is_rechargeable ? "true" : "false"); printf("\tstate : %s\n", tmp->state); printf("\twaring level : %s\n", tmp->warning_level); printf("\tenergy : %0.2f\n", tmp->energy); printf("\tenergy empty : %0.2f\n", tmp->energy_empty); printf("\tenergy full: %0.2f\n", tmp->energy_full); printf("\tenergy full design : %0.2f\n", tmp->energy_full_design); printf("\tenergy rate : %0.2f\n", tmp->energy_rate); printf("\tvoltage : %0.2f\n", tmp->voltage); printf("\ttime to empty : %ld\n", tmp->time_to_empty); printf("\ttime to full : %ld\n", tmp->time_to_full); printf("\tpercentage : %0.2f\n", tmp->percentage); printf("\ttemperature : %0.2f\n", tmp->temperature); printf("\tcapacity : %0.2f\n", tmp->capacity); printf("\ttechnology : %s\n", tmp->technology); printf("\tonline : %s\n", tmp->online ? "true" : "false"); printf("\ticon name : %s\n", tmp->icon_name); tmp = tmp->next; } kdk_hw_free_power_info(power); } int main(int argc, char *argv[]) { if (argc < 2) { printf("please use like >> kyhwinfo-test --[target]\n"); printf("hardware"); printf("\tpower"); printf("\n"); return 0; } if (0 == strcmp(argv[1], "--hardware")) Traverse_hardware(); if (0 == strcmp(argv[1], "--power")) Traverse_power(); } .SH "CONFORMING TO" These functions are as per the withdrawn POSIX.1e draft specification. The following functions are Linux extensions: .BR kdk_hw_free_hw (), .BR kdk_hw_get_hwinfo () and .BR kdk_hw_free_power_info (). .SH "SEE ALSO" .BR kdk_hw_free_hw (3), .BR kdk_hw_get_hwinfo (3) and .BR kdk_hw_free_power_info (3).