Temps: support color range customization

This commit is contained in:
李通洲
2024-02-26 16:39:41 +08:00
parent 8f205b8c30
commit ba60d9059f
15 changed files with 268 additions and 102 deletions
+7 -12
View File
@@ -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
+1
View File
@@ -11,6 +11,7 @@ typedef struct FFBatteryOptions
FFModuleArgs moduleArgs;
bool temp;
FFColorRangeConfig tempConfig;
FFColorRangeConfig percent;
#ifdef _WIN32
+7 -12
View File
@@ -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;
}
+1
View File
@@ -10,5 +10,6 @@ typedef struct FFCPUOptions
FFModuleArgs moduleArgs;
bool temp;
FFColorRangeConfig tempConfig;
uint8_t freqNdigits;
} FFCPUOptions;
+7 -12
View File
@@ -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 };
}
+1
View File
@@ -21,5 +21,6 @@ typedef struct FFGPUOptions
bool temp;
bool driverSpecific;
bool forceVulkan;
FFColorRangeConfig tempConfig;
FFColorRangeConfig percent;
} FFGPUOptions;
+1
View File
@@ -11,4 +11,5 @@ typedef struct FFPhysicalDiskOptions
FFstrbuf namePrefix;
bool temp;
FFColorRangeConfig tempConfig;
} FFPhysicalDiskOptions;
+7 -12
View File
@@ -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)