Battery (Windows): add flag --battery-use-setup-api

This commit is contained in:
李通洲
2023-10-30 14:49:00 +08:00
parent b462006280
commit ae34208247
6 changed files with 34 additions and 2 deletions
+2 -1
View File
@@ -144,7 +144,8 @@ Module specific options:
--display-precise-refresh-rate: <?value>:Set if decimal refresh rates should not be rounded into integers when printing. Default is true
--brightness-ddcci-sleep: <num> Set the sleep times (in ms) when sending DDC/CI requests. See <https://www.ddcutil.com/performance_options/#option-sleep-multiplier> for detail. Default is 10
--sound-type: <value>: Set what type of sound devices should be printed. Should be either main, active or all. Default is main
--battery-dir <folder>: The directory where the battery folders are. Standard: /sys/class/power_supply/
--battery-dir <folder>: The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only
--battery-use-setup-api <?value>: Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only
--cpu-temp <?value>: Detect and display CPU temperature if supported. Default is false
--cpu-freq-ndigits <num>: Set the number of digits to keep after the decimal point when printing CPU frequency. Default is 2
--cpuusage-separate <?value>: Display CPU usage per CPU logical core, instead of an average result. Default is false
+1 -1
View File
@@ -32,7 +32,7 @@ static inline void wrapSetupDiDestroyDeviceInfoList(HDEVINFO* hdev)
const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
{
if(instance.config.general.allowSlowOperations)
if(options->useSetupApi)
{
//https://learn.microsoft.com/en-us/windows/win32/power/enumerating-battery-devices
HDEVINFO hdev __attribute__((__cleanup__(wrapSetupDiDestroyDeviceInfoList))) =
+23
View File
@@ -122,6 +122,14 @@ bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, co
}
#endif
#ifdef _WIN32
if (ffStrEqualsIgnCase(subKey, "use-setup-api"))
{
options->useSetupApi = ffOptionParseBoolean(value);
return true;
}
#endif
return false;
}
@@ -146,6 +154,14 @@ void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module)
}
#endif
#ifdef _WIN32
if (ffStrEqualsIgnCase(key, "useSetupApi"))
{
options->useSetupApi = yyjson_get_bool(val);
continue;
}
#endif
if (ffStrEqualsIgnCase(key, "temp"))
{
options->temp = yyjson_get_bool(val);
@@ -168,6 +184,11 @@ void ffGenerateBatteryJsonConfig(FFBatteryOptions* options, yyjson_mut_doc* doc,
yyjson_mut_obj_add_strbuf(doc, module, "dir", &options->dir);
#endif
#ifdef _WIN32
if (defaultOptions.useSetupApi != options->useSetupApi)
yyjson_mut_obj_add_bool(doc, module, "useSetupApi", options->useSetupApi);
#endif
if (options->temp != defaultOptions.temp)
yyjson_mut_obj_add_bool(doc, module, "temp", options->temp);
}
@@ -233,6 +254,8 @@ void ffInitBatteryOptions(FFBatteryOptions* options)
#ifdef __linux__
ffStrbufInit(&options->dir);
#elif defined(_WIN32)
options->useSetupApi = false;
#endif
}
+2
View File
@@ -13,5 +13,7 @@ typedef struct FFBatteryOptions
#ifdef __linux__
FFstrbuf dir;
#elif defined(_WIN32)
bool useSetupApi;
#endif
} FFBatteryOptions;