From 9a4062db7c5cfc79ceec7be21c157a4d79291fcf Mon Sep 17 00:00:00 2001 From: Alexandre Acebedo Date: Wed, 29 Dec 2021 15:47:36 +0100 Subject: [PATCH] fixup! modules: add temp module --- CHANGELOG.md | 2 +- ...5.scd => yambar-modules-temperature.5.scd} | 13 +++--- modules/meson.build | 2 +- modules/{temp.c => temperature.c} | 46 ++++++------------- plugin.c | 4 +- 5 files changed, 25 insertions(+), 42 deletions(-) rename doc/{yambar-modules-temp.5.scd => yambar-modules-temperature.5.scd} (65%) rename modules/{temp.c => temperature.c} (83%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 783ffef..4edd126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ (https://codeberg.org/dnkl/yambar/issues/139). * mem: a module handling system memory monitoring * cpu: a module offering cpu usage monitoring -* temp: a module displaying the temperature of the thermal zones in the machine. +* temperature: a module displaying the temperature of the thermal zones in the machine. ### Changed diff --git a/doc/yambar-modules-temp.5.scd b/doc/yambar-modules-temperature.5.scd similarity index 65% rename from doc/yambar-modules-temp.5.scd rename to doc/yambar-modules-temperature.5.scd index 3f01359..273517a 100644 --- a/doc/yambar-modules-temp.5.scd +++ b/doc/yambar-modules-temperature.5.scd @@ -1,7 +1,7 @@ -yambar-modules-temp(5) +yambar-modules-temperature(5) # NAME -temp - This module displays the temperature of the thermal zones available on +temperature - This module displays the temperature of the thermal zones available on the system # TAGS @@ -9,7 +9,7 @@ the system [[ *Name* :[ *Type* :[ *Description* -| temp +| temperature : string : Current temperature of a given thermal zone @@ -26,7 +26,8 @@ the system | unit : string : no -: Unit of the temperature. It can be Celsius (C) or Farenheit (F) (default=C) +: Unit of the temperature. It can be Celsius (C or Celsius) or Fahrenheit (F or +Fahrenheit) (default=C) | thermal_zone : int @@ -38,11 +39,11 @@ the system ``` bar: left: - - temp: + - temperature: interval: 1000 thermal_zone: 0 content: - string: {text: "{temp}C"} + string: {text: "{temperature}℃ (DEGREE CELSIUS)"} ``` # SEE ALSO diff --git a/modules/meson.build b/modules/meson.build index 6503e4b..f828533 100644 --- a/modules/meson.build +++ b/modules/meson.build @@ -19,7 +19,7 @@ mod_data = { 'clock': [[], []], 'cpu': [[], []], 'mem': [[], []], - 'temp': [[], []], + 'temperature': [[], []], 'i3': [['i3-common.c', 'i3-common.h'], [dynlist, json]], 'label': [[], []], 'network': [[], []], diff --git a/modules/temp.c b/modules/temperature.c similarity index 83% rename from modules/temp.c rename to modules/temperature.c index 3df46fa..92c3638 100644 --- a/modules/temp.c +++ b/modules/temperature.c @@ -9,7 +9,7 @@ #include #include -#define LOG_MODULE "temp" +#define LOG_MODULE "temperature" #define LOG_ENABLE_DBG 0 #define SMALLEST_INTERVAL 500 #include "../bar/bar.h" @@ -40,11 +40,11 @@ destroy(struct module *mod) static const char * description(struct module *mod) { - return "temp"; + return "temperature"; } static bool -get_temp(uint16_t thermal_zone, enum temp_unit unit, double *temp) +get_temperature(uint16_t thermal_zone, enum temp_unit unit, double *temp) { FILE *fp = NULL; char *line = NULL; @@ -72,17 +72,9 @@ get_temp(uint16_t thermal_zone, enum temp_unit unit, double *temp) goto exit; } - switch (unit) { - case TEMP_UNIT_CELSIUS: - *temp = read_temp / 1000; - break; - case TEMP_UNIT_FAHRENHEIT: - *temp = read_temp; - *temp = (*temp * (9 / 5)) + 32; - break; - default: - goto exit; - break; + *temp = read_temp / 1000; + if (TEMP_UNIT_FAHRENHEIT == unit) { + *temp = (*temp * (9.0 / 5.0)) + 32; } res = true; @@ -98,14 +90,14 @@ static struct exposable * content(struct module *mod) { const struct private *p = mod->private; - double temp = 0; + double temperature = 0; - if (!get_temp(p->thermal_zone, p->unit, &temp)) { + if (!get_temperature(p->thermal_zone, p->unit, &temperature)) { LOG_ERR("unable to retrieve the temperature"); } struct tag_set tags = { - .tags = (struct tag *[]){tag_new_int(mod, "temp", round(temp))}, + .tags = (struct tag *[]){tag_new_int(mod, "temperature", round(temperature))}, .count = 1, }; @@ -114,7 +106,6 @@ content(struct module *mod) return exposable; } -#include static int run(struct module *mod) { @@ -145,11 +136,11 @@ run(struct module *mod) static enum temp_unit str_to_unit(const char *unit_str) { - if (0 == strcasecmp(unit_str, "C")) { + if (0 == strcasecmp(unit_str, "C") || 0 == strcasecmp(unit_str, "Celsius")) { return TEMP_UNIT_CELSIUS; } - if (0 == strcasecmp(unit_str, "F")) { + if (0 == strcasecmp(unit_str, "F") || 0 == strcasecmp(unit_str, "Fahrenheit")) { return TEMP_UNIT_FAHRENHEIT; } @@ -203,16 +194,7 @@ conf_verify_interval(keychain_t *chain, const struct yml_node *node) static bool conf_verify_unit(keychain_t *chain, const struct yml_node *node) { - if (!conf_verify_string(chain, node)) - return false; - - enum temp_unit unit = str_to_unit(yml_value_as_string(node)); - if (unit == TEMP_UNIT_INVALID) { - LOG_ERR("%s: invalid unit, must be C or F", conf_err_prefix(chain, node)); - return false; - } - - return true; + return conf_verify_enum(chain, node, (const char *[]){"C", "F", "Celsius", "Fahrenheit"}, 4); } static bool @@ -228,11 +210,11 @@ verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } -const struct module_iface module_temp_iface = { +const struct module_iface module_temperature_iface = { .verify_conf = &verify_conf, .from_conf = &from_conf, }; #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) -extern const struct module_iface iface __attribute__((weak, alias("module_temp_iface"))); +extern const struct module_iface iface __attribute__((weak, alias("module_temperature_iface"))); #endif diff --git a/plugin.c b/plugin.c index 53f2d9b..a520b82 100644 --- a/plugin.c +++ b/plugin.c @@ -51,7 +51,7 @@ EXTERN_MODULE(xkb); EXTERN_MODULE(xwindow); EXTERN_MODULE(cpu); EXTERN_MODULE(mem); -EXTERN_MODULE(temp); +EXTERN_MODULE(temperature); EXTERN_PARTICLE(empty); EXTERN_PARTICLE(list); @@ -141,7 +141,7 @@ init(void) #endif REGISTER_CORE_MODULE(mem, mem); REGISTER_CORE_MODULE(cpu, cpu); - REGISTER_CORE_MODULE(temp, temp); + REGISTER_CORE_MODULE(temperature, temperature); REGISTER_CORE_PARTICLE(empty, empty); REGISTER_CORE_PARTICLE(list, list);