diff --git a/src/api/docs/content/specs/config.yaml b/src/api/docs/content/specs/config.yaml index 96c60b9a..63308bb2 100644 --- a/src/api/docs/content/specs/config.yaml +++ b/src/api/docs/content/specs/config.yaml @@ -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 diff --git a/src/api/ftl.c b/src/api/ftl.c index 91c3f364..dbc98ae3 100644 --- a/src/api/ftl.c +++ b/src/api/ftl.c @@ -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); } } diff --git a/src/config/config.c b/src/config/config.c index db9319bf..11933065 100644 --- a/src/config/config.c +++ b/src/config/config.c @@ -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"; diff --git a/src/config/config.h b/src/config/config.h index 51579cb6..1a281112 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -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; diff --git a/src/dnsmasq_interface.c b/src/dnsmasq_interface.c index 7cdfb194..e70554cf 100644 --- a/src/dnsmasq_interface.c +++ b/src/dnsmasq_interface.c @@ -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); diff --git a/src/setupVars.c b/src/setupVars.c index 166cc4b7..5fca18dd 100644 --- a/src/setupVars.c +++ b/src/setupVars.c @@ -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