Add misc.temp.unit and move misc.temp_limit to misc.temp.limit

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2023-01-12 19:27:24 +01:00
parent 1ef587f552
commit 4a033795c1
6 changed files with 42 additions and 12 deletions
+10 -3
View File
@@ -302,8 +302,13 @@ components:
type: boolean
privacylevel:
type: integer
temp_limit:
type: number
temp:
type: object
properties:
limit:
type: number
unit:
type: string
check:
type: object
properties:
@@ -472,7 +477,9 @@ components:
delay_startup: 10
addr2line: true
privacylevel: 0
temp_limit: 60.0
temp:
limit: 60.0
unit: "C"
check:
load: true
shmem: 90
+13 -2
View File
@@ -230,9 +230,20 @@ static int read_temp_sensor(struct ftl_conn *api,
// Compute actual temperature
double temp = raw_temp < 1000 ? raw_temp : 1e-3*raw_temp;
const char *unit = "C";
if(config.misc.temp.unit.v.s[0] == 'F')
{
temp = 1.8*temp + 32; // Convert °Celsius to °Fahrenheit
unit = "F";
}
else if(config.misc.temp.unit.v.s[0] == 'K')
{
temp += 273.15; // Convert °Celsius to Kelvin
unit = "K";
}
JSON_ADD_NUMBER_TO_OBJECT(item, "value", temp);
JSON_ADD_NUMBER_TO_OBJECT(item, "hot_limit", config.misc.temp_limit.v.d);
JSON_REF_STR_IN_OBJECT(item, "unit", "C");
JSON_ADD_NUMBER_TO_OBJECT(item, "hot_limit", config.misc.temp.limit.v.d);
JSON_REF_STR_IN_OBJECT(item, "unit", unit);
JSON_ADD_ITEM_TO_ARRAY(object, item);
}
}
+10 -4
View File
@@ -643,10 +643,16 @@ void initConfig(void)
config.misc.delay_startup.d.ui = 0;
// sub-struct misc.temp
config.misc.temp_limit.k = "misc.temp_limit";
config.misc.temp_limit.h = "Which upper temperature limit should be used by Pi-hole [°C]? Temperatures above this limit will be shown as \"hot\"";
config.misc.temp_limit.t = CONF_DOUBLE;
config.misc.temp_limit.d.d = 60.0; // °C
config.misc.temp.limit.k = "misc.temp.limit";
config.misc.temp.limit.h = "Which upper temperature limit should be used by Pi-hole? Temperatures above this limit will be shown as \"hot\". The number specified here is in the unit defined below";
config.misc.temp.limit.t = CONF_DOUBLE;
config.misc.temp.limit.d.d = 60.0; // °C
config.misc.temp.unit.k = "misc.temp.unit";
config.misc.temp.unit.h = "Which temperature unit should be used for temperatures processed by FTL?";
config.misc.temp.unit.a = "[ \"C\", \"F\", \"K\" ]";
config.misc.temp.unit.t = CONF_STRING;
config.misc.temp.unit.d.s = (char*)"C";
// sub-struct misc.check
config.misc.check.load.k = "misc.check.load";
+4 -1
View File
@@ -229,7 +229,10 @@ struct config {
struct conf_item delay_startup;
struct conf_item addr2line;
struct conf_item privacylevel;
struct conf_item temp_limit;
struct {
struct conf_item limit;
struct conf_item unit;
} temp;
struct {
struct conf_item load;
struct conf_item shmem;
+1 -1
View File
@@ -3306,7 +3306,7 @@ int check_struct_sizes(void)
int result = 0;
// sizeof(struct conf_item) is 72 on x86_64 and 52 on x86_32
// number of config elements: CONFIG_ELEMENTS
result += check_one_struct("struct config", sizeof(struct config), 7920, 5720);
result += check_one_struct("struct config", sizeof(struct config), 7992, 5772);
result += check_one_struct("queriesData", sizeof(queriesData), 72, 64);
result += check_one_struct("upstreamsData", sizeof(upstreamsData), 640, 628);
result += check_one_struct("clientsData", sizeof(clientsData), 672, 652);
+4 -1
View File
@@ -116,12 +116,15 @@ void importsetupVarsConf(void)
{
double lim;
if(sscanf(temp_limit, "%lf", &lim) == 1)
config.misc.temp_limit.v.d = lim;
config.misc.temp.limit.v.d = lim;
}
// Free memory, harmless to call if read_setupVarsconf() didn't return a result
clearSetupVarsArray();
// Try to obtain password hash from setupVars.conf
get_conf_string_from_setupVars("TEMPERATURE_UNIT", &config.misc.temp.unit);
// Try to obtain boxed-layout boolean