1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

Make temperature_unit a lua setting

This commit is contained in:
Pavel Labath 2010-08-25 21:26:14 +02:00
parent 0085402d08
commit b6ed33b82a
3 changed files with 10 additions and 36 deletions

View File

@ -3022,14 +3022,6 @@ char load_config_file(const char *f)
} }
} }
#endif #endif
CONF("temperature_unit") {
if (!value) {
NORM_ERR("config option 'temperature_unit' needs an argument, either 'celsius' or 'fahrenheit'");
} else if (set_temp_output_unit(value)) {
NORM_ERR("temperature_unit: incorrect argument");
}
}
#ifdef BUILD_LUA #ifdef BUILD_LUA
CONF("lua_load") { CONF("lua_load") {
if (value) { if (value) {

View File

@ -30,8 +30,14 @@
#include "temphelper.h" #include "temphelper.h"
#include "conky.h" #include "conky.h"
/* default to output in celsius */ template<>
static enum TEMP_UNIT output_unit = TEMP_CELSIUS; conky::lua_traits<TEMP_UNIT>::Map conky::lua_traits<TEMP_UNIT>::map = {
{ "celsius", TEMP_CELSIUS },
{ "fahrenheit", TEMP_FAHRENHEIT }
};
static conky::simple_config_setting<TEMP_UNIT> output_unit("temperature_unit",
TEMP_CELSIUS, true);
static double fahrenheit_to_celsius(double n) static double fahrenheit_to_celsius(double n)
{ {
@ -43,35 +49,12 @@ static double celsius_to_fahrenheit(double n)
return ((n * 9 / 5) + 32); return ((n * 9 / 5) + 32);
} }
int set_temp_output_unit(const char *name)
{
long i;
int rc = 0;
char *buf;
if (!name)
return 1;
buf = strdup(name);
for (i = 0; i < (long)strlen(name); i++)
buf[i] = tolower(name[i]);
if (!strcmp(buf, "celsius"))
output_unit = TEMP_CELSIUS;
else if (!strcmp(buf, "fahrenheit"))
output_unit = TEMP_FAHRENHEIT;
else
rc = 1;
free(buf);
return rc;
}
static double convert_temp_output(double n, enum TEMP_UNIT input_unit) static double convert_temp_output(double n, enum TEMP_UNIT input_unit)
{ {
if (input_unit == output_unit) if (input_unit == output_unit.get(*state))
return n; return n;
switch(output_unit) { switch(output_unit.get(*state)) {
case TEMP_CELSIUS: case TEMP_CELSIUS:
return fahrenheit_to_celsius(n); return fahrenheit_to_celsius(n);
case TEMP_FAHRENHEIT: case TEMP_FAHRENHEIT:

View File

@ -30,7 +30,6 @@ enum TEMP_UNIT {
TEMP_FAHRENHEIT TEMP_FAHRENHEIT
}; };
int set_temp_output_unit(const char *);
int temp_print(char *, size_t, double, enum TEMP_UNIT); int temp_print(char *, size_t, double, enum TEMP_UNIT);
#endif /* TEMPHELPER_H */ #endif /* TEMPHELPER_H */