From ba60d9059fb6ab9a69f926ac6627216d62a2fa0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 26 Feb 2024 16:39:41 +0800 Subject: [PATCH] Temps: support color range customization --- CMakeLists.txt | 1 + doc/json_schema.json | 48 ++++--- src/common/parsing.c | 38 ------ src/common/parsing.h | 1 - src/common/temps.c | 171 ++++++++++++++++++++++++ src/common/temps.h | 8 ++ src/data/help.json | 23 ++++ src/modules/battery/battery.c | 19 +-- src/modules/battery/option.h | 1 + src/modules/cpu/cpu.c | 19 +-- src/modules/cpu/option.h | 1 + src/modules/gpu/gpu.c | 19 +-- src/modules/gpu/option.h | 1 + src/modules/physicaldisk/option.h | 1 + src/modules/physicaldisk/physicaldisk.c | 19 +-- 15 files changed, 268 insertions(+), 102 deletions(-) create mode 100644 src/common/temps.c create mode 100644 src/common/temps.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0706620cb..a4b16f798 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -277,6 +277,7 @@ set(LIBFASTFETCH_SRC src/common/printing.c src/common/properties.c src/common/settings.c + src/common/temps.c src/detection/chassis/chassis.c src/detection/cpu/cpu.c src/detection/cpuusage/cpuusage.c diff --git a/doc/json_schema.json b/doc/json_schema.json index 5b7b89b7e..ff1750196 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/schema", + "$schema": "https://json-schema.org/draft-07/schema", "$defs": { "colors": { "type": "string", @@ -44,6 +44,32 @@ "description": "Value greater than green and less then yellow will be shown in yellow.\nValue greater than yellow will be shown in red" } } + }, + "temperature": { + "description": "Detect and display temperature if supported", + "oneOf": [ + { + "type": "boolean", + "default": false + }, + { + "type": "object", + "properties": { + "green": { + "type": "integer", + "minimum": 0, + "maximum": 100, + "description": "Value less then green will be shown in green" + }, + "yellow": { + "type": "integer", + "minimum": 0, + "maximum": 100, + "description": "Value greater than green and less then yellow will be shown in yellow.\nValue greater than yellow will be shown in red" + } + } + } + ] } }, "type": "object", @@ -272,7 +298,7 @@ "description": "Force display detection to use DRM. Linux only", "oneOf": [ { - "type": "bool", + "type": "boolean", "const": false, "description": "Try `wayland`, then `x11`, then `drm`" }, @@ -282,7 +308,7 @@ "const": "sysfs-only" }, { - "type": "bool", + "type": "boolean", "const": true, "description": "Try `libdrm` first, then `sysfs` if libdrm failed" } @@ -870,9 +896,7 @@ "default": false }, "temp": { - "description": "Detect and display Battery temperature if supported", - "type": "boolean", - "default": false + "$ref": "#/$defs/temperature" }, "percent": { "$ref": "#/$defs/percent" @@ -970,9 +994,7 @@ "const": "cpu" }, "temp": { - "description": "Detect and display CPU temperature if supported", - "type": "boolean", - "default": false + "$ref": "#/$defs/temperature" }, "freqNdigits": { "description": "Set the number of digits to keep after the decimal point when printing CPU frequency", @@ -1317,9 +1339,7 @@ "const": "gpu" }, "temp": { - "description": "Detect and display GPU temperature if supported", - "type": "boolean", - "default": false + "$ref": "#/$defs/temperature" }, "driverSpecific": { "description": "Use driver specific method to detect more detailed GPU information (memory usage, core count, etc)", @@ -1542,9 +1562,7 @@ "type": "string" }, "temp": { - "description": "Detect and display SSD temperature if supported", - "type": "boolean", - "default": false + "$ref": "#/$defs/temperature" }, "key": { "$ref": "#/$defs/key" diff --git a/src/common/parsing.c b/src/common/parsing.c index f4833fd35..b3f07a509 100644 --- a/src/common/parsing.c +++ b/src/common/parsing.c @@ -1,6 +1,5 @@ #include "fastfetch.h" #include "common/parsing.h" -#include "util/textModifier.h" #include #include @@ -97,43 +96,6 @@ void ffParseSize(uint64_t bytes, FFstrbuf* result) } } -void ffParseTemperature(double celsius, FFstrbuf* buffer) -{ - if (celsius != celsius) // ignores NaN - return; - - const FFOptionsDisplay* options = &instance.config.display; - const char* colorGreen = options->temperatureColorGreen.chars; - const char* colorYellow = options->temperatureColorYellow.chars; - const char* colorRed = options->temperatureColorRed.chars; - - if (!options->pipe) - { - if (celsius < 50) - ffStrbufAppendF(buffer, "\e[%sm", colorGreen); - else if (celsius < 80) - ffStrbufAppendF(buffer, "\e[%sm", colorYellow); - else - ffStrbufAppendF(buffer, "\e[%sm", colorRed); - } - - switch (options->temperatureUnit) - { - case FF_TEMPERATURE_UNIT_CELSIUS: - ffStrbufAppendF(buffer, "%.*f°C", options->temperatureNdigits, celsius); - break; - case FF_TEMPERATURE_UNIT_FAHRENHEIT: - ffStrbufAppendF(buffer, "%.*f°F", options->temperatureNdigits, celsius * 1.8 + 32); - break; - case FF_TEMPERATURE_UNIT_KELVIN: - ffStrbufAppendF(buffer, "%.*f K", options->temperatureNdigits, celsius + 273.15); - break; - } - - if (!options->pipe) - ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); -} - void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, const FFstrbuf* gtk4) { if(gtk2->length > 0 && gtk3->length > 0 && gtk4->length > 0) diff --git a/src/common/parsing.h b/src/common/parsing.h index 24fd13528..f295c74cc 100644 --- a/src/common/parsing.h +++ b/src/common/parsing.h @@ -26,4 +26,3 @@ void ffVersionToPretty(const FFVersion* version, FFstrbuf* pretty); int8_t ffVersionCompare(const FFVersion* version1, const FFVersion* version2); void ffParseSize(uint64_t bytes, FFstrbuf* result); -void ffParseTemperature(double celsius, FFstrbuf* buffer); diff --git a/src/common/temps.c b/src/common/temps.c new file mode 100644 index 000000000..b46abad79 --- /dev/null +++ b/src/common/temps.c @@ -0,0 +1,171 @@ +#include "fastfetch.h" +#include "common/temps.h" +#include "util/textModifier.h" +#include "util/stringUtils.h" + +void ffTempsAppendNum(double celsius, FFstrbuf* buffer, FFColorRangeConfig config) +{ + if (celsius != celsius) // ignores NaN + return; + + const FFOptionsDisplay* options = &instance.config.display; + const char* colorGreen = options->temperatureColorGreen.chars; + const char* colorYellow = options->temperatureColorYellow.chars; + const char* colorRed = options->temperatureColorRed.chars; + + uint8_t green = config.green, yellow = config.yellow; + + if (!options->pipe) + { + if(green <= yellow) + { + if (celsius > yellow) + ffStrbufAppendF(buffer, "\e[%sm", colorRed); + else if (celsius > green) + ffStrbufAppendF(buffer, "\e[%sm", colorYellow); + else + ffStrbufAppendF(buffer, "\e[%sm", colorGreen); + } + else + { + if (celsius < yellow) + ffStrbufAppendF(buffer, "\e[%sm", colorRed); + else if (celsius < green) + ffStrbufAppendF(buffer, "\e[%sm", colorYellow); + else + ffStrbufAppendF(buffer, "\e[%sm", colorGreen); + } + } + + switch (options->temperatureUnit) + { + case FF_TEMPERATURE_UNIT_CELSIUS: + ffStrbufAppendF(buffer, "%.*f°C", options->temperatureNdigits, celsius); + break; + case FF_TEMPERATURE_UNIT_FAHRENHEIT: + ffStrbufAppendF(buffer, "%.*f°F", options->temperatureNdigits, celsius * 1.8 + 32); + break; + case FF_TEMPERATURE_UNIT_KELVIN: + ffStrbufAppendF(buffer, "%.*f K", options->temperatureNdigits, celsius + 273.15); + break; + } + + if (!options->pipe) + ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); +} + +bool ffTempsParseCommandOptions(const char* key, const char* subkey, const char* value, bool* useTemp, FFColorRangeConfig* config) +{ + if (!ffStrStartsWithIgnCase(subkey, "temp")) + return false; + + if (subkey[strlen("temp")] == '\0') + { + *useTemp = ffOptionParseBoolean(value); + return true; + } + + if (subkey[strlen("temp")] != '-') + return false; + + subkey += strlen("temp-"); + + if (ffStrEqualsIgnCase(subkey, "green")) + { + uint32_t num = ffOptionParseUInt32(key, value); + if (num > 100) + { + fprintf(stderr, "Error: usage: %s must be between 0 and 100\n", key); + exit(480); + } + config->green = (uint8_t) num; + return true; + } + + if (ffStrEqualsIgnCase(subkey, "yellow")) + { + uint32_t num = ffOptionParseUInt32(key, value); + if (num > 100) + { + fprintf(stderr, "Error: usage: %s must be between 0 and 100\n", key); + exit(480); + } + config->yellow = (uint8_t) num; + return true; + } + + return false; +} + +bool ffTempsParseJsonObject(const char* key, yyjson_val* value, bool* useTemp, FFColorRangeConfig* config) +{ + if (!ffStrEqualsIgnCase(key, "temp")) + return false; + + if (yyjson_is_bool(value)) + { + *useTemp = yyjson_get_bool(value); + return true; + } + + if (yyjson_is_null(value)) + { + *useTemp = false; + return true; + } + + if (!yyjson_is_obj(value)) + { + fprintf(stderr, "Error: usage: %s must be an object or a boolean\n", key); + exit(480); + } + + *useTemp = true; + + yyjson_val* greenVal = yyjson_obj_get(value, "green"); + if (greenVal) + { + int num = yyjson_get_int(greenVal); + if (num < 0 || num > 100) + { + fputs("Error: usage: temp.green must be between 0 and 100\n", stderr); + exit(480); + } + config->green = (uint8_t) num; + } + + yyjson_val* yellowVal = yyjson_obj_get(value, "yellow"); + if (yellowVal) + { + int num = yyjson_get_int(yellowVal); + if (num < 0 || num > 100) + { + fputs("Error: usage: temp.yellow must be between 0 and 100\n", stderr); + exit(480); + } + config->yellow = (uint8_t) num; + } + + return true; +} + +void ffTempsGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FF_MAYBE_UNUSED bool defaultTemp, FFColorRangeConfig defaultConfig, bool temp, FFColorRangeConfig config) +{ + assert(defaultTemp == false); // assume defaultTemp is always false + + if (!temp) + return; + + if (config.green != defaultConfig.green || config.yellow != defaultConfig.yellow) + { + yyjson_mut_val* temp = yyjson_mut_obj_add_obj(doc, module, "temp"); + if (config.green != defaultConfig.green) + yyjson_mut_obj_add_uint(doc, temp, "green", config.green); + if (config.yellow != defaultConfig.yellow) + yyjson_mut_obj_add_uint(doc, temp, "yellow", config.yellow); + } + else + { + yyjson_mut_obj_add_bool(doc, module, "temp", true); + } +} diff --git a/src/common/temps.h b/src/common/temps.h new file mode 100644 index 000000000..bbbc74766 --- /dev/null +++ b/src/common/temps.h @@ -0,0 +1,8 @@ +#pragma once + +#include "common/parsing.h" + +void ffTempsAppendNum(double celsius, FFstrbuf* buffer, FFColorRangeConfig config); +bool ffTempsParseCommandOptions(const char* key, const char* subkey, const char* value, bool* useTemp, FFColorRangeConfig* config); +bool ffTempsParseJsonObject(const char* key, yyjson_val* value, bool* useTemp, FFColorRangeConfig* config); +void ffTempsGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FF_MAYBE_UNUSED bool defaultTemp, FFColorRangeConfig defaultConfig, bool temp, FFColorRangeConfig config); diff --git a/src/data/help.json b/src/data/help.json index 5199b1b42..9fa6dd08a 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -1532,6 +1532,29 @@ "type": "num" }, "pseudo": true + }, + { + "long": "-temp-green", + "desc": [ + "Threshold of temperature colors", + "Value less then temp-green will be shown in green" + ], + "arg": { + "type": "num" + }, + "pseudo": true + }, + { + "long": "-temp-yellow", + "desc": [ + "Threshold of temperature colors", + "Value greater than temp-green and less then yellow will be shown in yellow", + "Value greater than temp-yellow will be shown in red" + ], + "arg": { + "type": "num" + }, + "pseudo": true } ] } diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index ccfed5d09..39f43b1d2 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -2,6 +2,7 @@ #include "common/jsonconfig.h" #include "common/percent.h" #include "common/parsing.h" +#include "common/temps.h" #include "detection/battery/battery.h" #include "modules/battery/battery.h" #include "util/stringUtils.h" @@ -49,7 +50,7 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin if(str.length > 0) ffStrbufAppendS(&str, " - "); - ffParseTemperature(result->temperature, &str); + ffTempsAppendNum(result->temperature, &str, options->tempConfig); } ffStrbufPutTo(&str, stdout); @@ -59,7 +60,7 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin FF_STRBUF_AUTO_DESTROY capacityStr = ffStrbufCreate(); ffPercentAppendNum(&capacityStr, result->capacity, options->percent, false); FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); - ffParseTemperature(result->temperature, &tempStr); + ffTempsAppendNum(result->temperature, &tempStr, options->tempConfig); ffPrintFormat(FF_BATTERY_MODULE_NAME, index, &options->moduleArgs, FF_BATTERY_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName}, @@ -110,11 +111,8 @@ bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, co if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; - if (ffStrEqualsIgnCase(subKey, "temp")) - { - options->temp = ffOptionParseBoolean(value); + if (ffTempsParseCommandOptions(key, subKey, value, &options->temp, &options->tempConfig)) return true; - } #ifdef _WIN32 if (ffStrEqualsIgnCase(subKey, "use-setup-api")) @@ -151,11 +149,8 @@ void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module) } #endif - if (ffStrEqualsIgnCase(key, "temp")) - { - options->temp = yyjson_get_bool(val); + if (ffTempsParseJsonObject(key, val, &options->temp, &options->tempConfig)) continue; - } if (ffPercentParseJsonObject(key, val, &options->percent)) continue; @@ -176,8 +171,7 @@ void ffGenerateBatteryJsonConfig(FFBatteryOptions* options, yyjson_mut_doc* doc, 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); + ffTempsGenerateJsonConfig(doc, module, defaultOptions.temp, defaultOptions.tempConfig, options->temp, options->tempConfig); ffPercentGenerateJsonConfig(doc, module, defaultOptions.percent, options->percent); } @@ -250,6 +244,7 @@ void ffInitBatteryOptions(FFBatteryOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); options->temp = false; + options->tempConfig = (FFColorRangeConfig) { 60, 80 }; options->percent = (FFColorRangeConfig) { 50, 20 }; #ifdef _WIN32 diff --git a/src/modules/battery/option.h b/src/modules/battery/option.h index 4fa9e8f5c..ecaa45ccc 100644 --- a/src/modules/battery/option.h +++ b/src/modules/battery/option.h @@ -11,6 +11,7 @@ typedef struct FFBatteryOptions FFModuleArgs moduleArgs; bool temp; + FFColorRangeConfig tempConfig; FFColorRangeConfig percent; #ifdef _WIN32 diff --git a/src/modules/cpu/cpu.c b/src/modules/cpu/cpu.c index c2716b528..c7ee463e8 100644 --- a/src/modules/cpu/cpu.c +++ b/src/modules/cpu/cpu.c @@ -1,6 +1,7 @@ #include "common/printing.h" #include "common/jsonconfig.h" #include "common/parsing.h" +#include "common/temps.h" #include "detection/cpu/cpu.h" #include "modules/cpu/cpu.h" #include "util/stringUtils.h" @@ -53,7 +54,7 @@ void ffPrintCPU(FFCPUOptions* options) if(cpu.temperature == cpu.temperature) //FF_CPU_TEMP_UNSET { ffStrbufAppendS(&str, " - "); - ffParseTemperature(cpu.temperature, &str); + ffTempsAppendNum(cpu.temperature, &str, options->tempConfig); } ffStrbufPutTo(&str, stdout); @@ -61,7 +62,7 @@ void ffPrintCPU(FFCPUOptions* options) else { FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); - ffParseTemperature(cpu.temperature, &tempStr); + ffTempsAppendNum(cpu.temperature, &tempStr, options->tempConfig); ffPrintFormat(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &cpu.name}, {FF_FORMAT_ARG_TYPE_STRBUF, &cpu.vendor}, @@ -86,11 +87,8 @@ bool ffParseCPUCPUOptions(FFCPUOptions* options, const char* key, const char* va if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; - if (ffStrEqualsIgnCase(subKey, "temp")) - { - options->temp = ffOptionParseBoolean(value); + if (ffTempsParseCommandOptions(key, subKey, value, &options->temp, &options->tempConfig)) return true; - } if (ffStrEqualsIgnCase(subKey, "freq-ndigits")) { @@ -114,11 +112,8 @@ void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) continue; - if (ffStrEqualsIgnCase(key, "temp")) - { - options->temp = yyjson_get_bool(val); + if (ffTempsParseJsonObject(key, val, &options->temp, &options->tempConfig)) continue; - } if (ffStrEqualsIgnCase(key, "freqNdigits")) { @@ -137,8 +132,7 @@ void ffGenerateCPUJsonConfig(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_ ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); - if (defaultOptions.temp != options->temp) - yyjson_mut_obj_add_bool(doc, module, "temp", options->temp); + ffTempsGenerateJsonConfig(doc, module, defaultOptions.temp, defaultOptions.tempConfig, options->temp, options->tempConfig); if (defaultOptions.freqNdigits != options->freqNdigits) yyjson_mut_obj_add_uint(doc, module, "freqNdigits", options->freqNdigits); @@ -214,6 +208,7 @@ void ffInitCPUOptions(FFCPUOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); options->temp = false; + options->tempConfig = (FFColorRangeConfig) { 60, 80 }; options->freqNdigits = 2; } diff --git a/src/modules/cpu/option.h b/src/modules/cpu/option.h index ae5699939..1fee8a3d6 100644 --- a/src/modules/cpu/option.h +++ b/src/modules/cpu/option.h @@ -10,5 +10,6 @@ typedef struct FFCPUOptions FFModuleArgs moduleArgs; bool temp; + FFColorRangeConfig tempConfig; uint8_t freqNdigits; } FFCPUOptions; diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index c933d7832..7c3d5b55f 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -2,6 +2,7 @@ #include "common/parsing.h" #include "common/printing.h" #include "common/jsonconfig.h" +#include "common/temps.h" #include "detection/host/host.h" #include "detection/gpu/gpu.h" #include "modules/gpu/gpu.h" @@ -44,7 +45,7 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET { ffStrbufAppendS(&output, " - "); - ffParseTemperature(gpu->temperature, &output); + ffTempsAppendNum(gpu->temperature, &output, options->tempConfig); } if(gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET && gpu->dedicated.total != 0) @@ -73,7 +74,7 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu else { FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); - ffParseTemperature(gpu->temperature, &tempStr); + ffTempsAppendNum(gpu->temperature, &tempStr, options->tempConfig); ffPrintFormat(FF_GPU_MODULE_NAME, index, &options->moduleArgs, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->vendor}, {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->name}, @@ -148,11 +149,8 @@ bool ffParseGPUCommandOptions(FFGPUOptions* options, const char* key, const char return true; } - if (ffStrEqualsIgnCase(subKey, "temp")) - { - options->temp = ffOptionParseBoolean(value); + if (ffTempsParseCommandOptions(key, subKey, value, &options->temp, &options->tempConfig)) return true; - } if (ffStrEqualsIgnCase(subKey, "hide-type")) { @@ -183,11 +181,8 @@ void ffParseGPUJsonObject(FFGPUOptions* options, yyjson_val* module) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) continue; - if (ffStrEqualsIgnCase(key, "temp")) - { - options->temp = yyjson_get_bool(val); + if (ffTempsParseJsonObject(key, val, &options->temp, &options->tempConfig)) continue; - } if (ffStrEqualsIgnCase(key, "driverSpecific")) { @@ -237,8 +232,7 @@ void ffGenerateGPUJsonConfig(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_ if (options->forceVulkan != defaultOptions.forceVulkan) yyjson_mut_obj_add_bool(doc, module, "forceVulkan", options->forceVulkan); - if (options->temp != defaultOptions.temp) - yyjson_mut_obj_add_bool(doc, module, "temp", options->temp); + ffTempsGenerateJsonConfig(doc, module, defaultOptions.temp, defaultOptions.tempConfig, options->temp, options->tempConfig); if (options->hideType != defaultOptions.hideType) { @@ -373,6 +367,7 @@ void ffInitGPUOptions(FFGPUOptions* options) options->forceVulkan = false; options->temp = false; options->hideType = FF_GPU_TYPE_UNKNOWN; + options->tempConfig = (FFColorRangeConfig) { 60, 80 }; options->percent = (FFColorRangeConfig) { 50, 80 }; } diff --git a/src/modules/gpu/option.h b/src/modules/gpu/option.h index 438e4d309..a68b8ad3a 100644 --- a/src/modules/gpu/option.h +++ b/src/modules/gpu/option.h @@ -21,5 +21,6 @@ typedef struct FFGPUOptions bool temp; bool driverSpecific; bool forceVulkan; + FFColorRangeConfig tempConfig; FFColorRangeConfig percent; } FFGPUOptions; diff --git a/src/modules/physicaldisk/option.h b/src/modules/physicaldisk/option.h index f57770d67..fbd2dc685 100644 --- a/src/modules/physicaldisk/option.h +++ b/src/modules/physicaldisk/option.h @@ -11,4 +11,5 @@ typedef struct FFPhysicalDiskOptions FFstrbuf namePrefix; bool temp; + FFColorRangeConfig tempConfig; } FFPhysicalDiskOptions; diff --git a/src/modules/physicaldisk/physicaldisk.c b/src/modules/physicaldisk/physicaldisk.c index 01f5033c5..7bb9187cb 100644 --- a/src/modules/physicaldisk/physicaldisk.c +++ b/src/modules/physicaldisk/physicaldisk.c @@ -1,6 +1,7 @@ #include "common/printing.h" #include "common/jsonconfig.h" #include "common/parsing.h" +#include "common/temps.h" #include "detection/physicaldisk/physicaldisk.h" #include "modules/physicaldisk/physicaldisk.h" #include "util/stringUtils.h" @@ -96,14 +97,14 @@ void ffPrintPhysicalDisk(FFPhysicalDiskOptions* options) if(buffer.length > 0) ffStrbufAppendS(&buffer, " - "); - ffParseTemperature(dev->temperature, &buffer); + ffTempsAppendNum(dev->temperature, &buffer, options->tempConfig); } ffStrbufPutTo(&buffer, stdout); } else { FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); - ffParseTemperature(dev->temperature, &tempStr); + ffTempsAppendNum(dev->temperature, &tempStr, options->tempConfig); if (dev->type & FF_PHYSICALDISK_TYPE_READWRITE) readOnlyType = "Read-write"; ffParseSize(dev->size, &buffer); @@ -145,11 +146,8 @@ bool ffParsePhysicalDiskCommandOptions(FFPhysicalDiskOptions* options, const cha return true; } - if (ffStrEqualsIgnCase(subKey, "temp")) - { - options->temp = ffOptionParseBoolean(value); + if (ffTempsParseCommandOptions(key, subKey, value, &options->temp, &options->tempConfig)) return true; - } return false; } @@ -173,11 +171,8 @@ void ffParsePhysicalDiskJsonObject(FFPhysicalDiskOptions* options, yyjson_val* m continue; } - if (ffStrEqualsIgnCase(key, "temp")) - { - options->temp = yyjson_get_bool(val); + if (ffTempsParseJsonObject(key, val, &options->temp, &options->tempConfig)) continue; - } ffPrintError(FF_PHYSICALDISK_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key); } @@ -193,8 +188,7 @@ void ffGeneratePhysicalDiskJsonConfig(FFPhysicalDiskOptions* options, yyjson_mut if (!ffStrbufEqual(&options->namePrefix, &defaultOptions.namePrefix)) yyjson_mut_obj_add_strbuf(doc, module, "namePrefix", &options->namePrefix); - if (options->temp != defaultOptions.temp) - yyjson_mut_obj_add_bool(doc, module, "temp", options->temp); + ffTempsGenerateJsonConfig(doc, module, defaultOptions.temp, defaultOptions.tempConfig, options->temp, options->tempConfig); } void ffGeneratePhysicalDiskJsonResult(FFPhysicalDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) @@ -286,6 +280,7 @@ void ffInitPhysicalDiskOptions(FFPhysicalDiskOptions* options) ffStrbufInit(&options->namePrefix); options->temp = false; + options->tempConfig = (FFColorRangeConfig) { 40, 60 }; } void ffDestroyPhysicalDiskOptions(FFPhysicalDiskOptions* options)